00001 #line 1105 "./lpsrc/flx_pthread.pak" 00002 #ifndef __MONITOR__ 00003 #define __MONITOR__ 00004 #include <flx_pthread_config.hpp> 00005 #include "pthread_mutex.hpp" 00006 #include "pthread_condv.hpp" 00007 #include "pthread_semaphore.hpp" 00008 00009 // interface for a consumer/producer queue. threads requesting a resource 00010 // that isn't there block until one is available. push/pop re-entrant 00011 00012 namespace flx { namespace pthread { 00013 00014 // ******************************************************** 00015 /// A monitor is an concurrent version of a channel. 00016 /// It matches up readers and writers in pairs, 00017 /// synchronising transfer of one datum. 00018 /// 00019 /// Unlike the bounded queue below, a monitor is a fully 00020 /// synchronised unbuffered transfer, mediated by a full 00021 /// handshake. 00022 /// 00023 /// In particular, unlike the queue of size 1, the writer 00024 /// cannot proceed until the reader sends an acknowlege 00025 /// signal. 00026 /// 00027 /// This logic matches that provides by schannels, but 00028 /// across an asynchronous boundary. 00029 // ******************************************************** 00030 00031 class PTHREAD_EXTERN monitor_t { 00032 flx_mutex_t m; 00033 flx_mutex_t rm; 00034 flx_mutex_t wm; 00035 int dataput; 00036 int datagot; 00037 flx_condv_t ack; 00038 void *data; 00039 public: 00040 monitor_t(); 00041 ~monitor_t(); 00042 void enqueue(void*); 00043 void* dequeue(); 00044 }; 00045 00046 }} // namespace pthread, flx 00047 #endif 00048