[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 02/24: try-mutex in terms of mutex-lock
From: |
Andy Wingo |
Subject: |
[Guile-commits] 02/24: try-mutex in terms of mutex-lock |
Date: |
Sun, 6 Nov 2016 18:00:44 +0000 (UTC) |
wingo pushed a commit to branch master
in repository guile.
commit 0f5a59b215fdeff23d2632de1dfe7a22bfcb9d82
Author: Andy Wingo <address@hidden>
Date: Wed Nov 2 21:29:22 2016 +0100
try-mutex in terms of mutex-lock
* libguile/threads.c (scm_try_mutex): Just call scm_lock_mutex_timed
with a zero timeout.
* module/ice-9/threads.scm (try-mutex): Likewise.
---
libguile/threads.c | 22 +++-------------------
module/ice-9/threads.scm | 5 +++++
2 files changed, 8 insertions(+), 19 deletions(-)
diff --git a/libguile/threads.c b/libguile/threads.c
index 43bd313..0225348 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -1311,27 +1311,11 @@ scm_dynwind_lock_mutex (SCM mutex)
SCM_F_WIND_EXPLICITLY);
}
-SCM_DEFINE (scm_try_mutex, "try-mutex", 1, 0, 0,
- (SCM mutex),
-"Try to lock @var{mutex}. If the mutex is already locked by someone "
-"else, return @code{#f}. Else lock the mutex and return @code{#t}. ")
-#define FUNC_NAME s_scm_try_mutex
+SCM
+scm_try_mutex (SCM mutex)
{
- SCM exception;
- int ret = 0;
- scm_t_timespec cwaittime, *waittime = NULL;
-
- SCM_VALIDATE_MUTEX (1, mutex);
-
- to_timespec (scm_from_int(0), &cwaittime);
- waittime = &cwaittime;
-
- exception = fat_mutex_lock (mutex, waittime, SCM_UNDEFINED, &ret);
- if (!scm_is_false (exception))
- scm_ithrow (SCM_CAR (exception), scm_list_1 (SCM_CDR (exception)), 1);
- return ret ? SCM_BOOL_T : SCM_BOOL_F;
+ return scm_lock_mutex_timed (mutex, SCM_INUM0, SCM_UNDEFINED);
}
-#undef FUNC_NAME
/*** Fat condition variables */
diff --git a/module/ice-9/threads.scm b/module/ice-9/threads.scm
index 555143e..119334b 100644
--- a/module/ice-9/threads.scm
+++ b/module/ice-9/threads.scm
@@ -136,6 +136,11 @@ Once @var{thunk} or @var{handler} returns, the return
value is made the
(lp))))
thread))
+(define* (try-mutex mutex)
+ "Try to lock @var{mutex}. If the mutex is already locked, return
address@hidden Otherwise lock the mutex and return @code{#t}."
+ (lock-mutex mutex 0))
+
;;; Macros first, so that the procedures expand correctly.
- [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 <=
- [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, 2016/11/06
- [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