00001 #ifndef PCBuffer_HPP 00002 #define PCBuffer_HPP 00003 00004 class BoundedBuffer; 00005 class Producer; 00006 class Consumer; 00007 00008 #include "Standard.hpp" 00009 #include "Basic_PThread.hpp" 00010 #include "Mutex.hpp" 00011 #include "RWLock.hpp" 00012 #include "Semaphore.hpp" 00013 #include "BoundedBuffer.hpp" 00014 #include "Timer.hpp" 00015 00016 /*********************************************************************** 00017 *********************************************************************** 00018 *** *** 00019 *** message: Notify that a message is now complete *** 00020 *** *** 00021 *** slot: Is there any available slot left ? *** 00022 *** *** 00023 *** receiver: Make sure that only one reader is accessing *** 00024 *** the buffer at any given time. *** 00025 *** *** 00026 *** sender: Make sure that only one writer is modifying *** 00027 *** the buffer at any given time. *** 00028 *** *** 00029 *********************************************************************** 00030 ***********************************************************************/ 00031 00032 Semaphore message( 0, "message", 10 ); 00033 Semaphore sender( 1, "sender", 11 ); 00034 Semaphore receiver( 1, "slot", 12 ); 00035 Semaphore** slot; 00036 static int done = 0; 00037 BoundedBuffer boundedBuffer( BBSIZE ); // Create a buffer 00038 00039 class Producer : public Basic_PThread { 00040 private: 00041 int item; 00042 int name; 00043 _uint64 started; 00044 double elapsed; 00045 double total; 00046 00047 public: 00048 Producer( int n = 1, int i = 0 ); 00049 virtual void run(); 00050 }; 00051 00052 class Consumer : public Basic_PThread { 00053 private: 00054 static int item; 00055 00056 int name; 00057 00058 size_t slotno; 00059 _uint64 started; 00060 double elapsed; 00061 double total; 00062 00063 public: 00064 Consumer( int n = 1 ); 00065 virtual void run(); 00066 }; 00067 00068 int Consumer::item = 0; 00069 00070 #endif