diff options
author | Andy Wingo <wingo@pobox.com> | 2019-05-25 17:17:49 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2019-05-25 17:17:49 +0200 |
commit | d1c2d7de2fed73be83a6213dcbf13247e19e457d (patch) | |
tree | cee4277e3791606200cff9197a6dc47957651aa2 /libguile/async.c | |
parent | 8b8ce79e83d65c47866696221b0a47382a835873 (diff) | |
download | guile-d1c2d7de2fed73be83a6213dcbf13247e19e457d.tar.gz |
Switch to use atomic_compare_exchange_strong
* libguile/atomics-internal.h (scm_atomic_compare_and_swap_scm): Change
to use same API as atomic-box-compare-and-swap!.
* libguile/intrinsics.c (atomic_compare_and_swap_scm): Remove loop, as
we're using the strong variant now.
* libguile/async.c (scm_i_async_pop, scm_i_async_push): Adapt to new API
of scm_atomic_compare_and_swap_scm.
Diffstat (limited to 'libguile/async.c')
-rw-r--r-- | libguile/async.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/libguile/async.c b/libguile/async.c index bd840762f..e10bc562b 100644 --- a/libguile/async.c +++ b/libguile/async.c @@ -1,4 +1,4 @@ -/* Copyright 1995-1998,2000-2002,2004,2006,2008-2011,2014,2018 +/* Copyright 1995-1998,2000-2002,2004,2006,2008-2011,2014,2018-2019 Free Software Foundation, Inc. This file is part of Guile. @@ -86,7 +86,7 @@ scm_i_async_push (scm_thread *t, SCM proc) disable that newly-severed tail by setting its cdr to #f. Not so nice, but oh well. */ asyncs = scm_atomic_ref_scm (&t->pending_asyncs); - do + while (1) { /* Traverse the asyncs list atomically. */ SCM walk; @@ -95,9 +95,13 @@ scm_i_async_push (scm_thread *t, SCM proc) walk = scm_atomic_ref_scm (SCM_CDRLOC (walk))) if (scm_is_eq (SCM_CAR (walk), proc)) return; + + SCM expected = asyncs; + asyncs = scm_atomic_compare_and_swap_scm + (&t->pending_asyncs, asyncs, scm_cons (proc, asyncs)); + if (scm_is_eq (asyncs, expected)) + return; } - while (!scm_atomic_compare_and_swap_scm (&t->pending_asyncs, &asyncs, - scm_cons (proc, asyncs))); } /* Precondition: there are pending asyncs. */ @@ -123,8 +127,9 @@ scm_i_async_pop (scm_thread *t) /* Sever the tail. */ if (scm_is_false (penultimate_pair)) { - if (!scm_atomic_compare_and_swap_scm (&t->pending_asyncs, &asyncs, - SCM_EOL)) + if (!scm_is_eq (asyncs, + scm_atomic_compare_and_swap_scm (&t->pending_asyncs, + asyncs, SCM_EOL))) continue; } else |