00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 OSG_BEGIN_NAMESPACE
00040
00041 inline
00042 void BarrierCommonBase::setNumWaitFor(UInt32 uiNumWaitFor)
00043 {
00044 _uiNumWaitFor = uiNumWaitFor;
00045 }
00046
00047
00048 #if defined (OSG_USE_PTHREADS)
00049
00050
00051
00052 inline
00053 void PThreadBarrierBase::enter(void)
00054 {
00055 if(_uiNumWaitFor <= 1)
00056 return;
00057
00058 pthread_mutex_lock(&(_pLockOne));
00059
00060 _uiCount++;
00061
00062 if(_uiCount < _uiNumWaitFor)
00063 {
00064
00065
00066 pthread_cond_wait(&(_pWakeupCondition[_uiCurrentCond]), &(_pLockOne));
00067 }
00068 else
00069 {
00070
00071
00072
00073
00074 pthread_cond_broadcast(&(_pWakeupCondition[_uiCurrentCond]));
00075
00076 _uiCount = 0;
00077 _uiCurrentCond = 1 - _uiCurrentCond;
00078 }
00079
00080 pthread_mutex_unlock(&(_pLockOne));
00081 }
00082
00083 inline
00084 void PThreadBarrierBase::enter(UInt32 uiNumWaitFor)
00085 {
00086 _uiNumWaitFor = uiNumWaitFor;
00087
00088 enter();
00089 }
00090
00091 #endif
00092
00093
00094
00095 #if defined (OSG_USE_SPROC)
00096
00097
00098
00099 inline
00100 void SprocBarrierBase::enter(void)
00101 {
00102 if(_pBarrier != NULL)
00103 barrier(_pBarrier, _uiNumWaitFor);
00104 }
00105
00106 inline
00107 void SprocBarrierBase::enter(UInt32 uiNumWaitFor)
00108 {
00109 _uiNumWaitFor = uiNumWaitFor;
00110
00111 enter();
00112 }
00113
00114 #endif
00115
00116
00117
00118 #if defined (OSG_USE_WINTHREADS)
00119
00120
00121
00122 inline
00123 void WinThreadBarrierBase::enter(void)
00124 {
00125 WaitForSingleObject(_pMutex1, INFINITE);
00126
00127 ++_uiNumWaiters;
00128
00129 if(_uiNumWaiters == _uiNumWaitFor)
00130 {
00131 --_uiNumWaiters;
00132
00133 ReleaseMutex(_pMutex1);
00134
00135 ReleaseSemaphore(_pBarrierSema, _uiNumWaitFor - 1, NULL);
00136
00137 return;
00138 }
00139 else
00140 {
00141 ReleaseMutex(_pMutex1);
00142
00143 WaitForSingleObject(_pBarrierSema, INFINITE);
00144
00145 WaitForSingleObject(_pMutex1, INFINITE);
00146
00147 --_uiNumWaiters;
00148
00149 ReleaseMutex(_pMutex1);
00150 }
00151 }
00152
00153 inline
00154 void WinThreadBarrierBase::enter(UInt32 uiNumWaitFor)
00155 {
00156 _uiNumWaitFor = uiNumWaitFor;
00157
00158 enter();
00159 }
00160
00161 #endif
00162
00163 inline
00164 Barrier *Barrier::create(void)
00165 {
00166 return Barrier::get(NULL);
00167 }
00168
00169 inline
00170 const MPBarrierType &Barrier::getClassType(void)
00171 {
00172 return _type;
00173 }
00174
00175
00176
00177
00178 inline
00179 void Barrier::enter(void)
00180 {
00181 Inherited::enter();
00182 }
00183
00184 inline
00185 void Barrier::enter(UInt32 uiNumWaitFor)
00186 {
00187 Inherited::enter(uiNumWaitFor);
00188 }
00189
00190
00191 OSG_END_NAMESPACE
00192
00193 #define OSGBARRIER_INLINE_CVSID "@(#)$Id: $"
00194