diff options
author | Andy Wingo <wingo@pobox.com> | 2011-10-24 10:52:55 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2011-10-24 12:54:14 +0200 |
commit | a141db8604ecca8a4f4c210cd680b41e337c689a (patch) | |
tree | 6d7fec7621586e8c569ec2451e2a4c93f674e5a5 /libguile/threads.c | |
parent | c4e83f74c2f518d8c25959c6e7bb2b36e7058d01 (diff) | |
download | guile-a141db8604ecca8a4f4c210cd680b41e337c689a.tar.gz |
remove weak pairs, rewrite weak vectors
* libguile/weak-vector.c:
* libguile/weak-vector.h: Renamed from weaks.[ch]. Remove weak pairs.
They were not safe to access with `car' and `cdr'. Remove weak alist
vectors, as we have weak tables and sets. Reimplement weak vectors,
moving the implementation here.
* libguile/vectors.c:
* libguile/vectors.h: Remove the extra header word. Use
scm_c_weak_vector_ref / scm_c_weak_vector_set_x to access weak
vectors.
* libguile/snarf.h: Remove the extra header word in vectors.
* libguile/threads.c (do_thread_exit, fat_mutex_lock, fat_mutex_unlock):
Instead of weak pairs, store thread-owned mutexes in a list of
one-element weak vectors.
* libguile/guardians.c (finalize_guarded): Similarly, store object
guardians in a list of one-element weak vectors.
* libguile/modules.c (scm_module_reverse_lookup): We no longer need to
handle the case of weak references.
* libguile/print.c (iprin1): Use the standard vector accessor to print
vectors.
* libguile.h:
* libguile/Makefile.am:
* libguile/gc-malloc.c:
* libguile/gc.c:
* libguile/goops.c:
* libguile/init.c:
* libguile/objprop.c:
* libguile/struct.c: Update includes.
* module/ice-9/weak-vector.scm: Load weak vector definitions using an
extension instead of %init-weaks-builtins.
* test-suite/tests/weaks.test: Use the make-...-hash-table names instead
of the old alist vector names.
Diffstat (limited to 'libguile/threads.c')
-rw-r--r-- | libguile/threads.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/libguile/threads.c b/libguile/threads.c index fcd1c1d2b..2560b69a2 100644 --- a/libguile/threads.c +++ b/libguile/threads.c @@ -56,7 +56,6 @@ #include "libguile/init.h" #include "libguile/scmsigs.h" #include "libguile/strings.h" -#include "libguile/weaks.h" #include <full-read.h> @@ -651,9 +650,9 @@ do_thread_exit (void *v) while (!scm_is_null (t->mutexes)) { - SCM mutex = SCM_WEAK_PAIR_CAR (t->mutexes); + SCM mutex = scm_c_weak_vector_ref (scm_car (t->mutexes), 0); - if (!SCM_UNBNDP (mutex)) + if (scm_is_true (mutex)) { fat_mutex *m = SCM_MUTEX_DATA (mutex); @@ -667,7 +666,7 @@ do_thread_exit (void *v) scm_i_pthread_mutex_unlock (&m->lock); } - t->mutexes = SCM_WEAK_PAIR_CDR (t->mutexes); + t->mutexes = scm_cdr (t->mutexes); } scm_i_pthread_mutex_unlock (&t->admin_mutex); @@ -1376,7 +1375,8 @@ fat_mutex_lock (SCM mutex, scm_t_timespec *timeout, SCM owner, int *ret) The weak pair itself is eventually removed when MUTEX is unlocked. Note that `t->mutexes' lists mutexes currently held by T, so it should be small. */ - t->mutexes = scm_weak_car_pair (mutex, t->mutexes); + t->mutexes = scm_cons (scm_make_weak_vector (SCM_INUM1, mutex), + t->mutexes); scm_i_pthread_mutex_unlock (&t->admin_mutex); } @@ -1520,6 +1520,25 @@ typedef struct { #define SCM_CONDVARP(x) SCM_SMOB_PREDICATE (scm_tc16_condvar, x) #define SCM_CONDVAR_DATA(x) ((fat_cond *) SCM_SMOB_DATA (x)) +static void +remove_mutex_from_thread (SCM mutex, scm_i_thread *t) +{ + SCM walk, prev; + + for (prev = SCM_BOOL_F, walk = t->mutexes; scm_is_pair (walk); + walk = SCM_CDR (walk)) + { + if (scm_is_eq (mutex, scm_c_weak_vector_ref (SCM_CAR (walk), 0))) + { + if (scm_is_pair (prev)) + SCM_SETCDR (prev, SCM_CDR (walk)); + else + t->mutexes = SCM_CDR (walk); + break; + } + } +} + static int fat_mutex_unlock (SCM mutex, SCM cond, const scm_t_timespec *waittime, int relock) @@ -1564,7 +1583,7 @@ fat_mutex_unlock (SCM mutex, SCM cond, if (m->level == 0) { /* Change the owner of MUTEX. */ - t->mutexes = scm_delq_x (mutex, t->mutexes); + remove_mutex_from_thread (mutex, t); m->owner = unblock_from_queue (m->waiting); } @@ -1612,7 +1631,7 @@ fat_mutex_unlock (SCM mutex, SCM cond, if (m->level == 0) { /* Change the owner of MUTEX. */ - t->mutexes = scm_delq_x (mutex, t->mutexes); + remove_mutex_from_thread (mutex, t); m->owner = unblock_from_queue (m->waiting); } |