1 |
/* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. |
/* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
2 |
* |
* |
3 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
4 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
293 |
coop_new_mutex_init (coop_m *m, coop_mattr *attr) |
coop_new_mutex_init (coop_m *m, coop_mattr *attr) |
294 |
{ |
{ |
295 |
m->owner = NULL; |
m->owner = NULL; |
296 |
|
m->level = 0; |
297 |
coop_qinit(&(m->waiting)); |
coop_qinit(&(m->waiting)); |
298 |
return 0; |
return 0; |
299 |
} |
} |
306 |
m->owner = coop_global_curr; |
m->owner = coop_global_curr; |
307 |
return 0; |
return 0; |
308 |
} |
} |
309 |
|
else if (m->owner == coop_global_curr) |
310 |
|
{ |
311 |
|
m->level++; |
312 |
|
return 0; |
313 |
|
} |
314 |
else |
else |
315 |
return EBUSY; |
return EBUSY; |
316 |
} |
} |
322 |
{ |
{ |
323 |
m->owner = coop_global_curr; |
m->owner = coop_global_curr; |
324 |
} |
} |
325 |
|
else if (m->owner == coop_global_curr) |
326 |
|
{ |
327 |
|
m->level++; |
328 |
|
} |
329 |
else |
else |
330 |
{ |
{ |
331 |
coop_t *old, *newthread; |
coop_t *old, *newthread; |
353 |
{ |
{ |
354 |
coop_t *old, *newthread; |
coop_t *old, *newthread; |
355 |
|
|
356 |
newthread = coop_qget (&(m->waiting)); |
if (m->level == 0) |
|
if (newthread != NULL) |
|
357 |
{ |
{ |
358 |
/* Record the current top-of-stack before going to sleep */ |
newthread = coop_qget (&(m->waiting)); |
359 |
coop_global_curr->top = &old; |
if (newthread != NULL) |
360 |
|
{ |
361 |
old = coop_global_curr; |
/* Record the current top-of-stack before going to sleep */ |
362 |
coop_global_curr = newthread; |
coop_global_curr->top = &old; |
363 |
/* The new thread came into m->waiting through a lock operation. |
|
364 |
It now owns this mutex. */ |
old = coop_global_curr; |
365 |
m->owner = coop_global_curr; |
coop_global_curr = newthread; |
366 |
QT_BLOCK (coop_yieldhelp, old, &coop_global_runq, newthread->sp); |
/* The new thread came into m->waiting through a lock operation. |
367 |
|
It now owns this mutex. */ |
368 |
|
m->owner = coop_global_curr; |
369 |
|
QT_BLOCK (coop_yieldhelp, old, &coop_global_runq, newthread->sp); |
370 |
|
} |
371 |
|
else |
372 |
|
{ |
373 |
|
m->owner = NULL; |
374 |
|
} |
375 |
} |
} |
376 |
|
else if (m->level > 0) |
377 |
|
m->level--; |
378 |
else |
else |
379 |
{ |
abort (); /* XXX */ |
380 |
m->owner = NULL; |
|
|
} |
|
381 |
return 0; |
return 0; |
382 |
} |
} |
383 |
|
|
490 |
} |
} |
491 |
|
|
492 |
int |
int |
493 |
coop_condition_variable_signal (coop_c *c) |
coop_condition_variable_broadcast (coop_c *c) |
494 |
{ |
{ |
495 |
coop_t *newthread; |
coop_t *newthread; |
496 |
|
|
501 |
return 0; |
return 0; |
502 |
} |
} |
503 |
|
|
504 |
|
int |
505 |
|
coop_condition_variable_signal (coop_c *c) |
506 |
|
{ |
507 |
|
return coop_condition_variable_broadcast (c); |
508 |
|
} |
509 |
|
|
510 |
|
|
511 |
/* {Keys} |
/* {Keys} |
512 |
*/ |
*/ |
513 |
|
|