[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 10/24: Remove thread-local weak mutex set
From: |
Andy Wingo |
Subject: |
[Guile-commits] 10/24: Remove thread-local weak mutex set |
Date: |
Sun, 6 Nov 2016 18:00:45 +0000 (UTC) |
wingo pushed a commit to branch master
in repository guile.
commit 857aa581a245f49946baa9b5ce25ab3fdb2f15af
Author: Andy Wingo <address@hidden>
Date: Sat Nov 5 00:20:39 2016 +0100
Remove thread-local weak mutex set
* libguile/threads.h (scm_i_thread):
* libguile/threads.c (guilify_self_1, do_thread_exit, fat_mutex_lock):
Remove thread-local weak mutex set.
---
libguile/threads.c | 76 +++-------------------------------------------------
libguile/threads.h | 1 -
2 files changed, 4 insertions(+), 73 deletions(-)
diff --git a/libguile/threads.c b/libguile/threads.c
index 79d0f81..76abe35 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -411,7 +411,6 @@ guilify_self_1 (struct GC_stack_base *base)
t.pthread = scm_i_pthread_self ();
t.handle = SCM_BOOL_F;
t.result = SCM_BOOL_F;
- t.mutexes = SCM_EOL;
t.held_mutex = NULL;
t.join_queue = SCM_EOL;
t.freelists = NULL;
@@ -543,28 +542,6 @@ do_thread_exit (void *v)
while (scm_is_true (unblock_from_queue (t->join_queue)))
;
- while (!scm_is_null (t->mutexes))
- {
- SCM mutex = scm_c_weak_vector_ref (scm_car (t->mutexes), 0);
-
- if (scm_is_true (mutex))
- {
- fat_mutex *m = SCM_MUTEX_DATA (mutex);
-
- scm_i_pthread_mutex_lock (&m->lock);
-
- /* Check whether T owns MUTEX. This is usually the case, unless
- T abandoned MUTEX; in that case, T is no longer its owner (see
- `fat_mutex_lock') but MUTEX is still in `t->mutexes'. */
- if (scm_is_eq (m->owner, t->handle))
- unblock_from_queue (m->waiting);
-
- scm_i_pthread_mutex_unlock (&m->lock);
- }
-
- t->mutexes = scm_cdr (t->mutexes);
- }
-
scm_i_pthread_mutex_unlock (&t->admin_mutex);
return NULL;
@@ -1183,26 +1160,6 @@ fat_mutex_lock (SCM mutex, scm_t_timespec *timeout, int
*ret)
{
m->owner = new_owner;
m->level++;
-
- if (SCM_I_IS_THREAD (new_owner))
- {
- scm_i_thread *t = SCM_I_THREAD_DATA (new_owner);
-
- /* FIXME: The order in which `t->admin_mutex' and
- `m->lock' are taken differs from that in
- `on_thread_exit', potentially leading to deadlocks. */
- scm_i_pthread_mutex_lock (&t->admin_mutex);
-
- /* Only keep a weak reference to MUTEX so that it's not
- retained when not referenced elsewhere (bug #27450).
- 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_cons (scm_make_weak_vector (SCM_INUM1, mutex),
- t->mutexes);
-
- scm_i_pthread_mutex_unlock (&t->admin_mutex);
- }
*ret = 1;
break;
}
@@ -1330,25 +1287,6 @@ 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)
@@ -1391,11 +1329,8 @@ fat_mutex_unlock (SCM mutex, SCM cond,
if (m->level > 0)
m->level--;
if (m->level == 0)
- {
- /* Change the owner of MUTEX. */
- remove_mutex_from_thread (mutex, t);
- m->owner = unblock_from_queue (m->waiting);
- }
+ /* Change the owner of MUTEX. */
+ m->owner = unblock_from_queue (m->waiting);
t->block_asyncs++;
@@ -1439,11 +1374,8 @@ fat_mutex_unlock (SCM mutex, SCM cond,
if (m->level > 0)
m->level--;
if (m->level == 0)
- {
- /* Change the owner of MUTEX. */
- remove_mutex_from_thread (mutex, t);
- m->owner = unblock_from_queue (m->waiting);
- }
+ /* Change the owner of MUTEX. */
+ m->owner = unblock_from_queue (m->waiting);
scm_i_pthread_mutex_unlock (&m->lock);
ret = 1;
diff --git a/libguile/threads.h b/libguile/threads.h
index f6165a5..e88a7e5 100644
--- a/libguile/threads.h
+++ b/libguile/threads.h
@@ -63,7 +63,6 @@ typedef struct scm_i_thread {
SCM join_queue;
scm_i_pthread_mutex_t admin_mutex;
- SCM mutexes;
scm_i_pthread_mutex_t *held_mutex;
SCM result;
- [Guile-commits] branch master updated (fcc6a7b -> f8de980), Andy Wingo, 2016/11/06
- [Guile-commits] 04/24: Remove export srfi-18 never had, Andy Wingo, 2016/11/06
- [Guile-commits] 01/24: Fix typo in threads documentation, Andy Wingo, 2016/11/06
- [Guile-commits] 02/24: try-mutex in terms of mutex-lock, Andy Wingo, 2016/11/06
- [Guile-commits] 12/24: Remove fat mutex abandoned mutex error, Andy Wingo, 2016/11/06
- [Guile-commits] 09/24: SRFI-18 manages own mutex "abandoned" state, Andy Wingo, 2016/11/06
- [Guile-commits] 05/24: srfi-18 condition variables disjoint, Andy Wingo, 2016/11/06
- [Guile-commits] 10/24: Remove thread-local weak mutex set,
Andy Wingo <=
- [Guile-commits] 18/24: Back to simple unlock-mutex, Andy Wingo, 2016/11/06
- [Guile-commits] 08/24: Remove lock-mutex owner facility, Andy Wingo, 2016/11/06
- [Guile-commits] 14/24: SRFI-18 mutexes are not recursive, Andy Wingo, 2016/11/06
- [Guile-commits] 07/24: SRFI-18 threads disjoint from guile threads, Andy Wingo, 2016/11/06
- [Guile-commits] 21/24: scm_timed_lock_mutex replaces scm_lock_mutex_timed, Andy Wingo, 2016/11/06
- [Guile-commits] 15/24: Recursively locking a SRFI-18 mutex blocks, Andy Wingo, 2016/11/06
- [Guile-commits] 19/24: Separate fat mutex unlock and wait operations, Andy Wingo, 2016/11/06
- [Guile-commits] 06/24: Update SRFI-18 documentation., Andy Wingo, 2016/11/06
- [Guile-commits] 11/24: Remove thread held pthread_mutex field, Andy Wingo, 2016/11/06
- [Guile-commits] 13/24: Move more functionality to SRFI-18 mutex-unlock!, Andy Wingo, 2016/11/06