comparison packages/kernel/current/src/sync/mutex.cxx @ 62:7a6ac9edc838 ecos-sw-2000-01-24

Merge from eCos master repository on 2000-01-24-19:43:49-GMT
author jlarmour
date Mon, 24 Jan 2000 21:43:17 +0000
parents 18ee5a9c102e
children c38311975d4f
comparison
equal deleted inserted replaced
61:e44112c47676 62:7a6ac9edc838
20 // 20 //
21 // The Original Code is eCos - Embedded Cygnus Operating System, released 21 // The Original Code is eCos - Embedded Cygnus Operating System, released
22 // September 30, 1998. 22 // September 30, 1998.
23 // 23 //
24 // The Initial Developer of the Original Code is Cygnus. Portions created 24 // The Initial Developer of the Original Code is Cygnus. Portions created
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. 25 // by Cygnus are Copyright (C) 1998,1999,2000 Cygnus Solutions.
26 // All Rights Reserved.
26 // ------------------------------------------- 27 // -------------------------------------------
27 // 28 //
28 //####COPYRIGHTEND#### 29 //####COPYRIGHTEND####
29 //========================================================================== 30 //==========================================================================
30 //#####DESCRIPTIONBEGIN#### 31 //#####DESCRIPTIONBEGIN####
131 // Loop while the mutex is locked, sleeping each time around 132 // Loop while the mutex is locked, sleeping each time around
132 // the loop. This copes with the possibility of a higher priority 133 // the loop. This copes with the possibility of a higher priority
133 // thread grabbing the mutex between the wakeup in unlock() and 134 // thread grabbing the mutex between the wakeup in unlock() and
134 // this thread actually starting. 135 // this thread actually starting.
135 136
137 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE
138
139 self->count_mutex();
140
141 #endif
142
136 while( locked && result ) 143 while( locked && result )
137 { 144 {
138 CYG_ASSERT( self != owner, "Locking mutex I already own"); 145 CYG_ASSERT( self != owner, "Locking mutex I already own");
139 146
140 self->set_sleep_reason( Cyg_Thread::WAIT ); 147 self->set_sleep_reason( Cyg_Thread::WAIT );
180 if( result ) 187 if( result )
181 { 188 {
182 locked = true; 189 locked = true;
183 owner = self; 190 owner = self;
184 191
192 CYG_INSTRUMENT_MUTEX(LOCKED, this, 0);
193 }
185 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE 194 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE
186 195 else
187 self->count_mutex(); 196 {
188 197 self->uncount_mutex();
189 #endif 198 self->disinherit_priority();
190 199 }
191 CYG_INSTRUMENT_MUTEX(LOCKED, this, 0); 200 #endif
192 }
193 201
194 // Unlock the scheduler and maybe switch threads 202 // Unlock the scheduler and maybe switch threads
195 Cyg_Scheduler::unlock(); 203 Cyg_Scheduler::unlock();
196 204
197 CYG_ASSERTCLASS( this, "Bad this pointer"); 205 CYG_ASSERTCLASS( this, "Bad this pointer");
257 265
258 CYG_ASSERTCLASS( this, "Bad this pointer"); 266 CYG_ASSERTCLASS( this, "Bad this pointer");
259 CYG_ASSERT( locked, "Unlock mutex that is not locked"); 267 CYG_ASSERT( locked, "Unlock mutex that is not locked");
260 CYG_ASSERT( owner == Cyg_Thread::self(), "Unlock mutex I do not own"); 268 CYG_ASSERT( owner == Cyg_Thread::self(), "Unlock mutex I do not own");
261 269
270 if( !queue.empty() ) {
271
272 // The queue is non-empty, so grab the next
273 // thread from it and wake it up.
274
275 Cyg_Thread *thread = queue.dequeue();
276
277 CYG_ASSERTCLASS( thread, "Bad thread pointer");
278
279 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE
280
281 // Give the owner-to-be a chance to inherit from the remaining
282 // queue or the relinquishing thread:
283
284 thread->relay_priority(owner, &queue);
285
286 #endif
287
288 thread->set_wake_reason( Cyg_Thread::DONE );
289
290 thread->wake();
291
292 CYG_INSTRUMENT_MUTEX(WAKE, this, thread);
293
294 }
295
262 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE 296 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE
263 297
264 owner->uncount_mutex(); 298 owner->uncount_mutex();
265 owner->disinherit_priority(); 299 owner->disinherit_priority();
266 300
267 #endif 301 #endif
268 302
269 locked = false; 303 locked = false;
270 owner = NULL; 304 owner = NULL;
271 305
272 if( !queue.empty() ) {
273
274 // The queue is non-empty, so grab the next
275 // thread from it and wake it up.
276
277 Cyg_Thread *thread = queue.dequeue();
278
279 CYG_ASSERTCLASS( thread, "Bad thread pointer");
280
281 thread->set_wake_reason( Cyg_Thread::DONE );
282
283 thread->wake();
284
285 CYG_INSTRUMENT_MUTEX(WAKE, this, thread);
286
287 }
288
289 CYG_ASSERTCLASS( this, "Bad this pointer"); 306 CYG_ASSERTCLASS( this, "Bad this pointer");
290 307
291 // Unlock the scheduler and maybe switch threads 308 // Unlock the scheduler and maybe switch threads
292 Cyg_Scheduler::unlock(); 309 Cyg_Scheduler::unlock();
293 310