<commit_before>#ifndef CIRCULARBUFFER_THREADSAFE_H
#define CIRCULARBUFFER_THREADSAFE_H

#include "CircularBuffer.h"

#include <mutex>
#include <condition_variable>

template < typename T >
class CircularBufferThreadSafe : public CircularBuffer< T > {
public:
  bool                  Add( T & input );
  bool                  Wait_And_Consume( T & get );
private:
  mutable std::mutex mut;
  std::condition_variable data_cond;
};

template < typename T >
bool CircularBufferThreadSafe< T >::Add( T & input ){
  std::lock_guard<std::mutex> lguard(mut);
  bool ret = CircularBuffer< T >::Add( input );
  data_cond.notify_one();
  return ret;
}

template < typename T >
bool CircularBufferThreadSafe< T >::Wait_And_Consume( T & get ){
  std::unique_lock<std::mutex> lguard(mut);
  data_cond.wait( lguard, [this]{return ( this->GetStatus() == CIRBUFFER_PARTIAL );} ); // wait until queue is not empty 
  bool ret = CircularBuffer< T >::Consume( get );
  return ret;
}


#endif
<commit_msg>changed method name from Wait_And_Consume to WaitAndConsume<commit_after>#ifndef CIRCULARBUFFER_THREADSAFE_H
#define CIRCULARBUFFER_THREADSAFE_H

#include "CircularBuffer.h"

#include <mutex>
#include <condition_variable>

template < typename T >
class CircularBufferThreadSafe : public CircularBuffer< T > {
public:
  bool                  Add( T & input );
  bool                  WaitAndConsume( T & get );
private:
  mutable std::mutex mut;
  std::condition_variable data_cond;
};

template < typename T >
bool CircularBufferThreadSafe< T >::Add( T & input ){
  std::lock_guard<std::mutex> lguard(mut);
  bool ret = CircularBuffer< T >::Add( input );
  data_cond.notify_one();
  return ret;
}

template < typename T >
bool CircularBufferThreadSafe< T >::WaitAndConsume( T & get ){
  std::unique_lock<std::mutex> lguard(mut);
  data_cond.wait( lguard, [this]{return ( this->GetStatus() == CIRBUFFER_PARTIAL );} ); // wait until queue is not empty 
  bool ret = CircularBuffer< T >::Consume( get );
  return ret;
}


#endif

{'fraction_non_alphanumeric': 0.12139303482587065, 'fraction_numerical': 0.0, 'mean_word_length': 4.334217506631299, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4608170', 'n_tokens_mistral': 675, 'n_tokens_neox': 644, 'n_words': 174}