diff options
author | Andy Wingo <wingo@pobox.com> | 2016-11-05 11:33:20 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2016-11-05 11:50:31 +0100 |
commit | 56dd476af7653b0c147c3416fd78e79f04ab44b1 (patch) | |
tree | befd3275116005ca14752eabec0b0b3c4d257208 | |
parent | 768246124164243059b0eeb772d3bb5bf1db0db9 (diff) |
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.
-rw-r--r-- | libguile/deprecated.c | 15 | ||||
-rw-r--r-- | libguile/deprecated.h | 1 | ||||
-rw-r--r-- | libguile/threads.c | 35 | ||||
-rw-r--r-- | libguile/threads.h | 1 | ||||
-rw-r--r-- | test-suite/tests/threads.test | 16 |
5 files changed, 30 insertions, 38 deletions
diff --git a/libguile/deprecated.c b/libguile/deprecated.c index fd671e9e5..d2e01f3b7 100644 --- a/libguile/deprecated.c +++ b/libguile/deprecated.c @@ -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); +} + diff --git a/libguile/deprecated.h b/libguile/deprecated.h index d20ff5b5d..5948fc512 100644 --- a/libguile/deprecated.h +++ b/libguile/deprecated.h @@ -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); diff --git a/libguile/threads.c b/libguile/threads.c index d44d3b19e..5497eb057 100644 --- a/libguile/threads.c +++ b/libguile/threads.c @@ -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 diff --git a/libguile/threads.h b/libguile/threads.h index 821d27cda..1da7bbf4a 100644 --- a/libguile/threads.h +++ b/libguile/threads.h @@ -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); diff --git a/test-suite/tests/threads.test b/test-suite/tests/threads.test index 4b6aa2ad7..efdf36db2 100644 --- a/test-suite/tests/threads.test +++ b/test-suite/tests/threads.test @@ -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) - (signal-condition-variable c1) - (lock-mutex m2) - (unlock-mutex m1) - (unlock-mutex m2 - c2 - (+ (current-time) - 5)))))) + (let ((t (begin-thread + (lock-mutex m1) + (signal-condition-variable c1) + (lock-mutex m2) + (unlock-mutex m1) + (wait-condition-variable c2 m2 (+ (current-time) 5))))) (wait-condition-variable c1 m1) (unlock-mutex m1) (lock-mutex m2) |