/*! * Clears the queue, i.e. removes all elements */ void clear() { boost::lock_guard<boost::mutex> lock(_mutex); while ( _have_elements() ) { pop_one(); } }
/*! * Gets and removes an element from the front of the queue. If the * queue is empty this function blocks until a new element is pushed * into the queue. * * This is the recommended popping method when used wisely. * * \return The first element in the queue, aka the one being popped */ value_type pop() { boost::unique_lock<boost::mutex> lock(_mutex); _condition.wait(lock, _have_elements); return pop_one(); }
void enqueue(int item){ if(full_queue()){ printf("Full!\n"); return; } if(!full_one()) push_one(item); else{ while(!full_two() && !empty_one()) push_two(pop_one()); push_one(item); } }
int dequeue(void){ int retval; if(empty_two()){ while(!empty_one()){ retval=pop_one(); push_two(retval); } } if(empty_two()){ printf("Queue empty.\n"); return -1; }else retval=pop_two(); return retval; }
/*! * Gets and removes an element from the front of the queue. If the * queue is empty this function blocks until a new element is pushed * into the stack, or until \p timeout_ms milliseconds has passed. * * \param result Set with the element being popped. * * \return \c true if an element has been popped, \c false if the queue * is still empty after the given timeout */ bool pop(value_type &result, size_t timeout_ms) { boost::unique_lock<boost::mutex> lock(_mutex); boost::system_time deadline = boost::get_system_time() + boost::posix_time::milliseconds(timeout_ms); if ( !_condition.timed_wait(lock, deadline, _have_elements) ) { return false; } result = pop_one(); return true; }