00001 // only compile if USE_SHMEMDEV is defined 00002 #ifdef USE_SHMEMDEV 00003 00004 // this code only works on linux 00005 #ifdef linux 00006 00007 #ifndef __CLUSTERBARRIER_H__ 00008 #define __CLUSTERBARRIER_H__ 00009 00040 #include <time.h> 00041 00042 class SimpleSHMEM; 00043 class IPC_SimpleSemaphore; 00044 00045 #include "ipc.simple.sem.H" 00046 #include "ipc.simple.shmem.H" 00047 00048 namespace IS3D { 00049 00050 class ClusterBarrier 00051 { 00052 public: 00053 00055 virtual bool init() = 0; 00056 00061 virtual void stop() = 0; 00062 }; 00063 00064 class SpinLockBarrier : public ClusterBarrier 00065 { 00066 public: 00067 enum { READY_FLAG = 0, 00068 ALL_READY_FLAG, 00069 HAS_RENDERING_ATTACHED, 00070 SHMEM_NUM_FLAGS 00071 }; 00072 00073 protected: 00074 // Syncing operations 00075 void setReady(); 00076 void setAllReady(); 00077 void setNotReady(); 00078 void setNotAllReady(); 00079 void waitForReady(); 00080 void waitForAllReady(); 00081 00082 // Keeping track of rendering process 00083 bool hasRenderingAttached(); 00084 bool isRenderingAttached(); 00085 bool hasRenderingQuit(); 00086 00087 // Generic operations 00088 void setFlag ( int flag, bool val ); 00089 bool getFlag ( int flag ); 00090 void waitForFlag( int flag ); 00091 00092 SpinLockBarrier(); 00093 00094 SimpleSHMEM *_shmem; 00095 struct timespec _delay_time, _delay_time_result; 00096 }; 00097 00098 class SemaphoreBarrier : public ClusterBarrier 00099 { 00100 protected: 00101 SemaphoreBarrier(); 00102 IPC_SimpleSemaphore *_enterGate, *_exitGate; 00103 }; 00104 00105 } 00106 00107 #endif 00108 00109 #endif 00110 00111 #endif