summaryrefslogtreecommitdiff
path: root/libguile/atomics-internal.h
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2019-05-25 17:17:49 +0200
committerAndy Wingo <wingo@pobox.com>2019-05-25 17:17:49 +0200
commitd1c2d7de2fed73be83a6213dcbf13247e19e457d (patch)
treecee4277e3791606200cff9197a6dc47957651aa2 /libguile/atomics-internal.h
parent8b8ce79e83d65c47866696221b0a47382a835873 (diff)
downloadguile-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/atomics-internal.h')
-rw-r--r--libguile/atomics-internal.h26
1 files changed, 13 insertions, 13 deletions
diff --git a/libguile/atomics-internal.h b/libguile/atomics-internal.h
index 7acc37f88..e15ea3564 100644
--- a/libguile/atomics-internal.h
+++ b/libguile/atomics-internal.h
@@ -1,7 +1,7 @@
#ifndef SCM_ATOMICS_INTERNAL_H
#define SCM_ATOMICS_INTERNAL_H
-/* Copyright 2016,2018
+/* Copyright 2016,2018-2019
Free Software Foundation, Inc.
This file is part of Guile.
@@ -75,13 +75,14 @@ scm_atomic_swap_scm (SCM *loc, SCM val)
atomic_uintptr_t *a_loc = (atomic_uintptr_t *) loc;
return SCM_PACK (atomic_exchange (a_loc, SCM_UNPACK (val)));
}
-static inline _Bool
-scm_atomic_compare_and_swap_scm (SCM *loc, SCM *expected, SCM desired)
+static inline SCM
+scm_atomic_compare_and_swap_scm (SCM *loc, SCM expected, SCM desired)
{
atomic_uintptr_t *a_loc = (atomic_uintptr_t *) loc;
- return atomic_compare_exchange_weak (a_loc,
- (uintptr_t *) expected,
- SCM_UNPACK (desired));
+ SCM result = expected;
+ atomic_compare_exchange_strong (a_loc, (uintptr_t *) &result,
+ SCM_UNPACK (desired));
+ return result;
}
#else /* HAVE_STDATOMIC_H */
@@ -161,20 +162,19 @@ scm_atomic_swap_scm (SCM *loc, SCM val)
scm_i_pthread_mutex_unlock (&atomics_lock);
return ret;
}
-static inline int
-scm_atomic_compare_and_swap_scm (SCM *loc, SCM *expected, SCM desired)
+static inline SCM
+scm_atomic_compare_and_swap_scm (SCM *loc, SCM expected, SCM desired)
{
- int ret;
+ SCM ret;
scm_i_pthread_mutex_lock (&atomics_lock);
- if (*loc == *expected)
+ if (*loc == expected)
{
*loc = desired;
- ret = 1;
+ ret = expected;
}
else
{
- *expected = *loc;
- ret = 0;
+ ret = *loc;
}
scm_i_pthread_mutex_unlock (&atomics_lock);
return ret;