summaryrefslogtreecommitdiff
path: root/libguile/atomics-internal.h
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2016-10-26 22:32:51 +0200
committerAndy Wingo <wingo@pobox.com>2016-10-26 22:50:26 +0200
commitc957ec7ab0f0a028910dc737e12191f7bdc1ca93 (patch)
tree5949cfd1de4a7eecfacb35611430498a53b4c2fe /libguile/atomics-internal.h
parentf3bfe29235199e12b961c3fd1fa92666ad031d0d (diff)
downloadguile-c957ec7ab0f0a028910dc737e12191f7bdc1ca93.tar.gz
Use atomics for async interrupts
* libguile/__scm.h (SCM_TICK): Always define as scm_async_tick(). * libguile/error.c (scm_syserror, scm_syserror_msg): * libguile/fports.c (fport_read, fport_write): * libguile/_scm.h (SCM_SYSCALL): Replace SCM_ASYNC_TICK with scm_async_tick (). (SCM_ASYNC_TICK, SCM_ASYNC_TICK_WITH_CODE) (SCM_ASYNC_TICK_WITH_GUARD_CODE): Remove internal definitions. We inline into vm-engine.c, the only place where it matters. * libguile/async.h: * libguile/async.c (scm_async_tick, scm_i_setup_sleep): (scm_i_reset_sleep, scm_system_async_mark_for_thread): * libguile/threads.h (struct scm_thread_wake_data): * libguile/threads.h (scm_i_thread): * libguile/threads.c (block_self, guilify_self_1, scm_std_select): Rewrite to use sequentially-consistent atomic references. * libguile/atomics-internal.h (scm_atomic_set_pointer): (scm_atomic_ref_pointer): New definitions. * libguile/finalizers.c (queue_finalizer_async): We can allocate, so just use scm_system_async_mark_for_thread instead of the set-cdr! shenanigans. * libguile/scmsigs.c (take_signal): * libguile/gc.c (queue_after_gc_hook): Adapt to new asyncs mechanism. Can't allocate but we're just manipulating the current thread when no other threads are running so we should be good. * libguile/vm-engine.c (VM_HANDLE_INTERRUPTS): Inline the async_tick business.
Diffstat (limited to 'libguile/atomics-internal.h')
-rw-r--r--libguile/atomics-internal.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/libguile/atomics-internal.h b/libguile/atomics-internal.h
index 9d18cbc1a..9074d8cc3 100644
--- a/libguile/atomics-internal.h
+++ b/libguile/atomics-internal.h
@@ -45,6 +45,16 @@ scm_atomic_compare_and_swap_uint32 (uint32_t *loc, uint32_t *expected,
return atomic_compare_exchange_weak (loc, expected, desired);
}
static inline void
+scm_atomic_set_pointer (void **loc, void *val)
+{
+ atomic_store (loc, val);
+}
+static inline void *
+scm_atomic_ref_pointer (void **loc)
+{
+ return atomic_load (loc);
+}
+static inline void
scm_atomic_set_scm (SCM *loc, SCM val)
{
atomic_store (loc, val);
@@ -100,6 +110,23 @@ scm_atomic_compare_and_swap_uint32 (uint32_t *loc, uint32_t *expected,
}
static inline void
+scm_atomic_set_pointer (void **loc, void *val)
+{
+ scm_i_pthread_mutex_lock (&atomics_lock);
+ *loc = val;
+ scm_i_pthread_mutex_unlock (&atomics_lock);
+}
+static inline void *
+scm_atomic_ref_pointer (void **loc)
+{
+ void *ret;
+ scm_i_pthread_mutex_lock (&atomics_lock);
+ ret = *loc;
+ scm_i_pthread_mutex_unlock (&atomics_lock);
+ return ret;
+}
+
+static inline void
scm_atomic_set_scm (SCM *loc, SCM val)
{
scm_i_pthread_mutex_lock (&atomics_lock);