SynchronizedSharedMemory.h

00001 // $Id: SynchronizedSharedMemory.h 21 2010-09-05 04:18:17Z cschwarz1 $
00002 
00003 #ifndef BASE_SYNCHRONIZEDSHAREDMEMORY_H
00004 #define BASE_SYNCHRONIZEDSHAREDMEMORY_H
00005 
00006 #ifndef _WIN32
00007     #include <pthread.h>
00008 #endif
00009 #include "SharedMemory.h"
00010 
00011 namespace base {
00013 
00017     class PPBASE_EXPORT SynchronizedSharedMemory: public SharedMemory {
00018     public:
00020         enum waitE {
00021             waitNone = 0,   
00022             waitEmpty = 1,  
00023             waitFull = 2    
00024         };
00025 
00027         SynchronizedSharedMemory();
00028 
00030         ~SynchronizedSharedMemory();
00031 
00033         void close();
00034 
00036 
00041         void destroy();
00042 
00044 
00052         void lock(waitE wait = waitNone);
00053 
00055 
00060         void open(const char *name, unsigned size, int flags = 0);
00061 
00063 
00071         void unlock(waitE wait = waitNone);
00072 
00073     private:
00074     #ifdef _WIN32
00075         HANDLE          _evente;  
00076         HANDLE          _eventf;  
00077         HANDLE          _mutex;   
00078     #else
00079         pthread_mutex_t _mutex;   
00080         int             _semid;   
00081     #endif
00082     };
00083 }
00084 
00085 #endif