34 res = pthread_mutex_init( &mMutex, 0 );
36 CLAM_ASSERT( res == 0,
"Not able to initialize mutex" );
43 res = pthread_mutex_destroy( &mMutex );
45 CLAM_ASSERT( res == 0,
"Not able to destroy mutex" );
52 res = pthread_mutex_lock( &mMutex );
57 CLAM_ASSERT( res == 0,
"Not able to lock the mutex" );
60 void Mutex::DoUnlock()
64 res = pthread_mutex_unlock( &mMutex );
69 CLAM_ASSERT( res == 0,
"Not able to Unlock the mutex" );
72 void Mutex::DoLock( ConditionVar& state )
77 void Mutex::DoUnlock( ConditionVar& state )
79 state.pmutex = &mMutex;
86 res = pthread_mutex_init( &mMutex, 0 );
88 CLAM_ASSERT( res == 0,
"Not able to initialize mutex" );
96 res = pthread_mutex_destroy( &mMutex );
98 CLAM_ASSERT( res == 0,
"Not able to destroy mutex" );
102 void TryMutex::DoLock()
105 res = pthread_mutex_lock( &mMutex );
106 if ( res == EDEADLK )
112 bool TryMutex::DoTryLock()
116 res = pthread_mutex_trylock(&mMutex );
118 if ( res == EDEADLK )
121 CLAM_ASSERT ( (res == 0) || (res == EBUSY),
"Not able to try-lock the mutex" );
126 void TryMutex::DoUnlock()
130 res = pthread_mutex_unlock( &mMutex );
135 CLAM_ASSERT( res == 0,
"Not able to Unlock the mutex" );
138 void TryMutex::DoLock( ConditionVar& state )
143 void TryMutex::DoUnlock( ConditionVar& state )
145 state.pmutex = &mMutex;
153 res = pthread_mutex_init( &mMutex, 0 );
155 CLAM_ASSERT( res==0,
"Not able to initilize the mutex" );
157 res = pthread_cond_init( &mCondition, 0 );
161 pthread_mutex_destroy( &mMutex );
168 CLAM_ASSERT( !mLocked,
"Mutex was locked while attempting to destroy it!" );
172 res = pthread_mutex_destroy(&mMutex );
174 CLAM_ASSERT( res == 0,
"Unable to destroy the mutex!" );
176 res = pthread_cond_destroy( &mCondition );
178 CLAM_ASSERT( res == 0,
"Unable to destroy the Condition variable" );
181 void TimedMutex::DoLock( )
185 res = pthread_mutex_lock( &mMutex );
186 CLAM_ASSERT( res == 0,
"Unable to lock mutex (already locked) " );
190 res = pthread_cond_wait( &mCondition, &mMutex );
194 CLAM_ASSERT( !mLocked,
"Spurious value for loop condition" );
197 res = pthread_mutex_unlock( &mMutex );
198 CLAM_ASSERT( res ==0,
"Unable to unlock the mutex" );
201 bool TimedMutex::DoTryLock()
205 res = pthread_mutex_lock( &mMutex );
207 CLAM_ASSERT( res == 0,
"Unable to lock the mutex" );
217 res = pthread_mutex_unlock( &mMutex );
218 CLAM_ASSERT( res==0,
"Unable to unlock the mutex" );
223 bool TimedMutex::DoTimedLock(
const xtime& xt )
226 res = pthread_mutex_lock( &mMutex );
227 CLAM_ASSERT( res == 0,
"Unable to lock the mutex" );
234 res = pthread_cond_timedwait(&mCondition, &mMutex, &ts);
235 CLAM_ASSERT(res == 0 || res == ETIMEDOUT,
"Low level error");
237 if (res == ETIMEDOUT)
248 res = pthread_mutex_unlock(&mMutex);
249 CLAM_ASSERT(res == 0,
"Something low level failed!");
253 void TimedMutex::DoUnlock()
256 res = pthread_mutex_lock(&mMutex);
259 CLAM_ASSERT(mLocked,
"No condition spurious value change");
262 res = pthread_cond_signal(&mCondition);
263 CLAM_ASSERT(res == 0,
"Not able to change the condition var value");
265 res = pthread_mutex_unlock(&mMutex);
266 CLAM_ASSERT(res == 0,
"Unable to unlock the mutex");
269 void TimedMutex::DoLock(ConditionVar& v)
274 res = pthread_cond_wait(&mCondition, &mMutex);
275 CLAM_ASSERT(res == 0,
"pthread_cond_wait call failed!");
281 res = pthread_mutex_unlock(&mMutex);
282 CLAM_ASSERT(res == 0,
"pthread_mutex_unlock call failed!");
285 void TimedMutex::DoUnlock(ConditionVar& state)
288 res = pthread_mutex_lock(&mMutex);
289 CLAM_ASSERT(res == 0,
"pthread_mutex_lock call failed");
294 res = pthread_cond_signal(&mCondition);
295 CLAM_ASSERT(res == 0,
"pthread_cond_signal call failed!");
297 state.pmutex = &mMutex;