I'd like change thread safe circular buffer that i saw here, adding a predicate at the condition variable like in this article.
I need to go out of my wait condition after a lot of time with the buffer empty.... so this is my circular-buffer-template snapshot :
//Template of CIRCULAR BUFFER thread-safe
template <typename T>
class circ_buffer : private boost::noncopyable{
public:
typedef boost::mutex::scoped_lock lock;
circ_buffer(){}
circ_buffer(int n){cb.set_capacity(n);}
........
struct cb_not_empty{
boost::circular_buffer<T>& circ_buf;
cb_not_empty(boost::circular_buffer<T>& circular_buffer_):
circ_buf(circular_buffer_){}
bool operator ()() const{
return !circ_buf.empty();
}
};
template<typename Duration>
bool timed_wait_and_pop(T& popped_valued,Duration const& wait_duration){
lock lk(monitor);
if(!buffer_not_empty.timed_wait(lk,wait_duration,cb_not_empty(the_cb)))
return false;
popped_valued = the_cb.front();
the_cb.pop();
return true;
}
.......
private:
boost::condition buffer_not_empty;
boost::mutex monitor;
boost::circular_buffer<T> cb;
std::atomic<bool> circ_buf_flag; //flag to turn ON/OFF circular buffer: make circ_buf OFF to go out
};
my gnu compiler give me
error: 'the_cb' was not declared in this scope if(!buffer_not_empty.timed_wait(lk,wait_duration,cb_not_empty(the_cb))) ^