mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-11 14:21:10 +02:00
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.
This commit is contained in:
parent
10471f40fe
commit
0f5a59b215
2 changed files with 8 additions and 19 deletions
|
@ -1311,27 +1311,11 @@ scm_dynwind_lock_mutex (SCM mutex)
|
||||||
SCM_F_WIND_EXPLICITLY);
|
SCM_F_WIND_EXPLICITLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM_DEFINE (scm_try_mutex, "try-mutex", 1, 0, 0,
|
SCM
|
||||||
(SCM mutex),
|
scm_try_mutex (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 exception;
|
return scm_lock_mutex_timed (mutex, SCM_INUM0, SCM_UNDEFINED);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
|
||||||
|
|
||||||
/*** Fat condition variables */
|
/*** Fat condition variables */
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,11 @@ Once @var{thunk} or @var{handler} returns, the return value is made the
|
||||||
(lp))))
|
(lp))))
|
||||||
thread))
|
thread))
|
||||||
|
|
||||||
|
(define* (try-mutex mutex)
|
||||||
|
"Try to lock @var{mutex}. If the mutex is already locked, return
|
||||||
|
@code{#f}. Otherwise lock the mutex and return @code{#t}."
|
||||||
|
(lock-mutex mutex 0))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;; Macros first, so that the procedures expand correctly.
|
;;; Macros first, so that the procedures expand correctly.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue