diff options
author | Marius Vollmer <mvo@zagadka.de> | 2002-10-27 20:12:07 +0000 |
---|---|---|
committer | Marius Vollmer <mvo@zagadka.de> | 2002-10-27 20:12:07 +0000 |
commit | 79cd5b8edac67485e9b88b3b0abf8068f54cf900 (patch) | |
tree | d6e86ec59a7754e49ca604a9b4fc8ccca68e3bdc /libguile/coop.c | |
parent | 026f9e6654d32cb4ce2b0c02b5f0b82d561e1551 (diff) | |
download | guile-79cd5b8edac67485e9b88b3b0abf8068f54cf900.tar.gz |
* coop-defs.h (coop_m): Added 'level' field.
(scm_t_mutex, scm_mutex_init, scm_mutex_lock, scm_mutex_trylock,
scm_mutex_unlock, scm_mutex_destroy, scm_t_cond, scm_cond_init,
scm_cond_wait, scm_cond_timedwait, scm_cond_signal,
scm_cond_broadcast, scm_cond_destroy, struct timespec): Do not
define.
(coop_condition_variable_broadcast): New.
* coop-threads.c (scm_threads_init): Create smobs here, using the
appropriate sizes.
(scm_c_thread_exited_p, scm_try_mutex,
scm_timed_wait_condition_variable,
scm_broadcast_condition_variable): New.
(scm_wait_condition_variable): Removed.
* coop.c (coop_new_mutex_init): Initialize level.
(coop_mutex_trylock, coop_mutex_lock, coop_mutex_unlock): maintain
level.
(coop_condition_variable_signal): Renamed to
coop_condition_variable_broadcast and reimplemented in terms of
that. Thus...
(coop_condition_variable_broadcast): New.
Diffstat (limited to 'libguile/coop.c')
-rw-r--r-- | libguile/coop.c | 59 |
1 files changed, 42 insertions, 17 deletions
diff --git a/libguile/coop.c b/libguile/coop.c index 889276e23..3b46e65ea 100644 --- a/libguile/coop.c +++ b/libguile/coop.c @@ -1,4 +1,4 @@ -/* 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. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,7 +40,7 @@ * If you do not wish that, delete this exception notice. */ -/* $Id: coop.c,v 1.31 2002-08-17 20:39:35 ghouston Exp $ */ +/* $Id: coop.c,v 1.32 2002-10-27 20:12:07 mvo Exp $ */ /* Cooperative thread library, based on QuickThreads */ @@ -293,6 +293,7 @@ int coop_new_mutex_init (coop_m *m, coop_mattr *attr) { m->owner = NULL; + m->level = 0; coop_qinit(&(m->waiting)); return 0; } @@ -305,6 +306,11 @@ coop_mutex_trylock (coop_m *m) m->owner = coop_global_curr; return 0; } + else if (m->owner == coop_global_curr) + { + m->level++; + return 0; + } else return EBUSY; } @@ -316,6 +322,10 @@ coop_mutex_lock (coop_m *m) { m->owner = coop_global_curr; } + else if (m->owner == coop_global_curr) + { + m->level++; + } else { coop_t *old, *newthread; @@ -343,23 +353,31 @@ coop_mutex_unlock (coop_m *m) { coop_t *old, *newthread; - newthread = coop_qget (&(m->waiting)); - if (newthread != NULL) + if (m->level == 0) { - /* Record the current top-of-stack before going to sleep */ - coop_global_curr->top = &old; - - old = coop_global_curr; - coop_global_curr = newthread; - /* The new thread came into m->waiting through a lock operation. - It now owns this mutex. */ - m->owner = coop_global_curr; - QT_BLOCK (coop_yieldhelp, old, &coop_global_runq, newthread->sp); + newthread = coop_qget (&(m->waiting)); + if (newthread != NULL) + { + /* Record the current top-of-stack before going to sleep */ + coop_global_curr->top = &old; + + old = coop_global_curr; + coop_global_curr = newthread; + /* The new thread came into m->waiting through a lock operation. + It now owns this mutex. */ + m->owner = coop_global_curr; + QT_BLOCK (coop_yieldhelp, old, &coop_global_runq, newthread->sp); + } + else + { + m->owner = NULL; + } } + else if (m->level > 0) + m->level--; else - { - m->owner = NULL; - } + abort (); /* XXX */ + return 0; } @@ -472,7 +490,7 @@ coop_condition_variable_timed_wait_mutex (coop_c *c, } int -coop_condition_variable_signal (coop_c *c) +coop_condition_variable_broadcast (coop_c *c) { coop_t *newthread; @@ -483,6 +501,13 @@ coop_condition_variable_signal (coop_c *c) return 0; } +int +coop_condition_variable_signal (coop_c *c) +{ + return coop_condition_variable_broadcast (c); +} + + /* {Keys} */ |