pthread_sleep_queue.hpp

00001 #line 1241 "./lpsrc/flx_pthread.pak"
00002 #ifndef __FLX_PTHREAD_SLEEP_QUEUE_H__
00003 #define __FLX_PTHREAD_SLEEP_QUEUE_H__
00004 #include <flx_pthread_config.hpp>
00005 #include "pthread_mutex.hpp"
00006 #include "pthread_condv.hpp"
00007 
00008 // interface for a consumer/producer queue. threads requesting a resource
00009 // that isn't there block until one is available. push/pop re-entrant
00010 
00011 namespace flx { namespace pthread {
00012 
00013 // ********************************************************
00014 /// Thread safe bounded queue.
00015 ///
00016 /// The queue can be locked by setting bound=0.
00017 /// In this state it can only be unlocked by setting a non-zero bound.
00018 ///
00019 /// If the bound is set to 1 (the default),
00020 /// then the queue is always either empty or full.
00021 /// An empty queue blocks readers until a writer sends some data.
00022 /// A full queue blocks writers, until a reader reads the data.
00023 /// Note that when the queue is empty a writer can write data
00024 /// and continues without waiting for the data to be read.
00025 // ********************************************************
00026 
00027 class PTHREAD_EXTERN sleep_queue_t {
00028   flx_condv_t size_changed;
00029   void *lame_opaque;
00030   size_t bound;
00031 public:
00032   flx_mutex_t member_lock;
00033   sleep_queue_t(size_t);
00034   ~sleep_queue_t();
00035   void enqueue(void*);
00036   void* dequeue();
00037   void resize(size_t);
00038   void wait_until_empty();
00039 };
00040 
00041 }} // namespace pthread, flx
00042 #endif
00043 

Generated on Sat May 31 04:06:23 2008 for Felix by  doxygen 1.5.5