mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
Back to simple unlock-mutex
* libguile/threads.c (scm_unlock_mutex): Bind to unlock-mutex. * libguile/threads.h: Remove scm_unlock_mutex_timed. * libguile/deprecated.h: Add scm_unlock_mutex_timed. * libguile/deprecated.c (scm_unlock_mutex_timed): Deprecate. * test-suite/tests/threads.test: Update unlock-mutex tests to use wait-condition-variable if they would wait on a cond.
This commit is contained in:
parent
7682461241
commit
56dd476af7
5 changed files with 30 additions and 38 deletions
|
@ -699,6 +699,21 @@ scm_make_mutex_with_flags (SCM flags)
|
|||
return scm_make_mutex_with_kind (kind);
|
||||
}
|
||||
|
||||
SCM
|
||||
scm_unlock_mutex_timed (SCM mx, SCM cond, SCM timeout)
|
||||
{
|
||||
scm_c_issue_deprecation_warning
|
||||
("'scm_unlock_mutex_timed' is deprecated. "
|
||||
"Use just plain old 'scm_unlock_mutex' instead, or otherwise "
|
||||
"'scm_wait_condition_variable' if you need to.");
|
||||
|
||||
if (!SCM_UNBNDP (cond) &&
|
||||
scm_is_false (scm_timed_wait_condition_variable (cond, mx, timeout)))
|
||||
return SCM_BOOL_F;
|
||||
|
||||
return scm_unlock_mutex (mx);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -239,6 +239,7 @@ SCM_DEPRECATED void scm_dynwind_critical_section (SCM mutex);
|
|||
|
||||
|
||||
SCM_DEPRECATED SCM scm_make_mutex_with_flags (SCM flags);
|
||||
SCM_DEPRECATED SCM scm_unlock_mutex_timed (SCM mx, SCM cond, SCM timeout);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1370,37 +1370,16 @@ fat_mutex_unlock (SCM mutex, SCM cond,
|
|||
return ret;
|
||||
}
|
||||
|
||||
SCM scm_unlock_mutex (SCM mx)
|
||||
SCM_DEFINE (scm_unlock_mutex, "unlock-mutex", 1, 0, 0, (SCM mx),
|
||||
"Unlocks @var{mutex}. The calling thread must already hold\n"
|
||||
"the lock on @var{mutex}, unless the mutex was created with\n"
|
||||
"the @code{allow-external-unlock} option; otherwise an error\n"
|
||||
"will be signalled.")
|
||||
#define FUNC_NAME s_scm_unlock_mutex
|
||||
{
|
||||
return scm_unlock_mutex_timed (mx, SCM_UNDEFINED, SCM_UNDEFINED);
|
||||
}
|
||||
|
||||
SCM_DEFINE (scm_unlock_mutex_timed, "unlock-mutex", 1, 2, 0,
|
||||
(SCM mx, SCM cond, SCM timeout),
|
||||
"Unlocks @var{mutex} if the calling thread owns the lock on "
|
||||
"@var{mutex}. Calling unlock-mutex on a mutex not owned by the current "
|
||||
"thread results in undefined behaviour. Once a mutex has been unlocked, "
|
||||
"one thread blocked on @var{mutex} is awakened and grabs the mutex "
|
||||
"lock. Every call to @code{lock-mutex} by this thread must be matched "
|
||||
"with a call to @code{unlock-mutex}. Only the last call to "
|
||||
"@code{unlock-mutex} will actually unlock the mutex. ")
|
||||
#define FUNC_NAME s_scm_unlock_mutex_timed
|
||||
{
|
||||
scm_t_timespec cwaittime, *waittime = NULL;
|
||||
|
||||
SCM_VALIDATE_MUTEX (1, mx);
|
||||
if (! (SCM_UNBNDP (cond)))
|
||||
{
|
||||
SCM_VALIDATE_CONDVAR (2, cond);
|
||||
|
||||
if (! SCM_UNBNDP (timeout) && ! scm_is_false (timeout))
|
||||
{
|
||||
to_timespec (timeout, &cwaittime);
|
||||
waittime = &cwaittime;
|
||||
}
|
||||
}
|
||||
|
||||
return fat_mutex_unlock (mx, cond, waittime, 0) ? SCM_BOOL_T : SCM_BOOL_F;
|
||||
return scm_from_bool (fat_mutex_unlock (mx, SCM_UNDEFINED, NULL, 0));
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
|
|
@ -156,7 +156,6 @@ SCM_API SCM scm_lock_mutex_timed (SCM m, SCM timeout, SCM owner);
|
|||
SCM_API void scm_dynwind_lock_mutex (SCM mutex);
|
||||
SCM_API SCM scm_try_mutex (SCM m);
|
||||
SCM_API SCM scm_unlock_mutex (SCM m);
|
||||
SCM_API SCM scm_unlock_mutex_timed (SCM m, SCM cond, SCM timeout);
|
||||
SCM_API SCM scm_mutex_p (SCM o);
|
||||
SCM_API SCM scm_mutex_locked_p (SCM m);
|
||||
SCM_API SCM scm_mutex_owner (SCM m);
|
||||
|
|
|
@ -250,7 +250,7 @@
|
|||
(let ((m (make-mutex))
|
||||
(c (make-condition-variable)))
|
||||
(lock-mutex m)
|
||||
(not (unlock-mutex m c (current-time)))))
|
||||
(not (wait-condition-variable c m (current-time)))))
|
||||
|
||||
(pass-if "asyncs are still working 4"
|
||||
(asyncs-still-working?))
|
||||
|
@ -261,14 +261,12 @@
|
|||
(c1 (make-condition-variable))
|
||||
(c2 (make-condition-variable)))
|
||||
(lock-mutex m1)
|
||||
(let ((t (begin-thread (begin (lock-mutex m1)
|
||||
(let ((t (begin-thread
|
||||
(lock-mutex m1)
|
||||
(signal-condition-variable c1)
|
||||
(lock-mutex m2)
|
||||
(unlock-mutex m1)
|
||||
(unlock-mutex m2
|
||||
c2
|
||||
(+ (current-time)
|
||||
5))))))
|
||||
(wait-condition-variable c2 m2 (+ (current-time) 5)))))
|
||||
(wait-condition-variable c1 m1)
|
||||
(unlock-mutex m1)
|
||||
(lock-mutex m2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue