[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 09/17: Simplify critical section implementation
From: |
Andy Wingo |
Subject: |
[Guile-commits] 09/17: Simplify critical section implementation |
Date: |
Tue, 1 Nov 2016 22:50:44 +0000 (UTC) |
wingo pushed a commit to branch master
in repository guile.
commit b410667e6434ef62a9c050dc4cbbff6f32a0c656
Author: Andy Wingo <address@hidden>
Date: Tue Nov 1 22:48:19 2016 +0100
Simplify critical section implementation
* libguile/async.h (SCM_CRITICAL_SECTION_START)
(SCM_CRITICAL_SECTION_END): Define in just one way.
* libguile/async.c (critical_section_mutex): New static variable.
(scm_critical_section_start, scm_critical_section_end): Inline
internal body of critical section gates.
(scm_init_async): Init critical_section_mutex.
* libguile/threads.c (scm_threads_prehistory): Don't declare critical
section mutex here.
---
libguile/async.c | 16 ++++++++++------
libguile/async.h | 32 ++------------------------------
libguile/threads.c | 6 ------
3 files changed, 12 insertions(+), 42 deletions(-)
diff --git a/libguile/async.c b/libguile/async.c
index aa4f508..d7b266b 100644
--- a/libguile/async.c
+++ b/libguile/async.c
@@ -299,21 +299,23 @@ scm_c_call_with_unblocked_asyncs (void *(*proc) (void
*data), void *data)
}
-/* These are function variants of the same-named macros (uppercase) for use
- outside of libguile. This is so that `SCM_I_CURRENT_THREAD', which may
- reside in TLS, is not accessed from outside of libguile. It thus allows
- libguile to be built with the "local-dynamic" TLS model. */
+static scm_i_pthread_mutex_t critical_section_mutex;
void
scm_critical_section_start (void)
{
- SCM_CRITICAL_SECTION_START;
+ scm_i_pthread_mutex_lock (&critical_section_mutex);
+ SCM_I_CURRENT_THREAD->block_asyncs++;
+ SCM_I_CURRENT_THREAD->critical_section_level++;
}
void
scm_critical_section_end (void)
{
- SCM_CRITICAL_SECTION_END;
+ SCM_I_CURRENT_THREAD->critical_section_level--;
+ SCM_I_CURRENT_THREAD->block_asyncs--;
+ scm_i_pthread_mutex_unlock (&critical_section_mutex);
+ scm_async_tick ();
}
@@ -321,6 +323,8 @@ scm_critical_section_end (void)
void
scm_init_async ()
{
+ scm_i_pthread_mutex_init (&critical_section_mutex,
+ scm_i_pthread_mutexattr_recursive);
#include "libguile/async.x"
}
diff --git a/libguile/async.h b/libguile/async.h
index 578e901..b709894 100644
--- a/libguile/async.h
+++ b/libguile/async.h
@@ -48,39 +48,11 @@ SCM_API void scm_dynwind_unblock_asyncs (void);
/* Critical sections */
-/* XXX - every critical section needs to be examined whether the
- requirements for SCM_CRITICAL_SECTION_START/END are fulfilled. See
- the manual.
-*/
-
-/* Defined in threads.c. */
-SCM_INTERNAL scm_i_pthread_mutex_t scm_i_critical_section_mutex;
-
SCM_API void scm_critical_section_start (void);
SCM_API void scm_critical_section_end (void);
-#ifdef BUILDING_LIBGUILE
-
-# define SCM_CRITICAL_SECTION_START \
- do { \
- scm_i_pthread_mutex_lock (&scm_i_critical_section_mutex); \
- SCM_I_CURRENT_THREAD->block_asyncs++; \
- SCM_I_CURRENT_THREAD->critical_section_level++; \
- } while (0)
-# define SCM_CRITICAL_SECTION_END \
- do { \
- SCM_I_CURRENT_THREAD->critical_section_level--; \
- SCM_I_CURRENT_THREAD->block_asyncs--; \
- scm_i_pthread_mutex_unlock (&scm_i_critical_section_mutex); \
- scm_async_tick (); \
- } while (0)
-
-#else /* !BUILDING_LIBGUILE */
-
-# define SCM_CRITICAL_SECTION_START scm_critical_section_start ()
-# define SCM_CRITICAL_SECTION_END scm_critical_section_end ()
-
-#endif /* !BUILDING_LIBGUILE */
+#define SCM_CRITICAL_SECTION_START scm_critical_section_start ()
+#define SCM_CRITICAL_SECTION_END scm_critical_section_end ()
SCM_INTERNAL void scm_init_async (void);
diff --git a/libguile/threads.c b/libguile/threads.c
index b2b3528..c27a7ea 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -1939,10 +1939,6 @@ static scm_i_pthread_cond_t wake_up_cond;
static int threads_initialized_p = 0;
-/* This mutex is used by SCM_CRITICAL_SECTION_START/END.
- */
-scm_i_pthread_mutex_t scm_i_critical_section_mutex;
-
static SCM dynwind_critical_section_mutex;
void
@@ -1971,8 +1967,6 @@ scm_threads_prehistory (void *base)
PTHREAD_MUTEX_RECURSIVE);
#endif
- scm_i_pthread_mutex_init (&scm_i_critical_section_mutex,
- scm_i_pthread_mutexattr_recursive);
scm_i_pthread_mutex_init (&scm_i_misc_mutex, NULL);
scm_i_pthread_cond_init (&wake_up_cond, NULL);
- [Guile-commits] 06/17: Remove unused internal definitions, (continued)
- [Guile-commits] 06/17: Remove unused internal definitions, Andy Wingo, 2016/11/01
- [Guile-commits] 13/17: Mutex in dynamic linker, Andy Wingo, 2016/11/01
- [Guile-commits] 11/17: Mutex instead of critical section in gc.c, Andy Wingo, 2016/11/01
- [Guile-commits] 16/17: Threads no longer track critical section level, Andy Wingo, 2016/11/01
- [Guile-commits] 03/17: threads: Use a mutex instead of a critical section., Andy Wingo, 2016/11/01
- [Guile-commits] 07/17: Mutexes instead of critical sections in stime.c, Andy Wingo, 2016/11/01
- [Guile-commits] 01/17: api-scheduling.texi: Syntactic cleanups., Andy Wingo, 2016/11/01
- [Guile-commits] 08/17: Mutex instead of critical sectoin in symbol->keyword, Andy Wingo, 2016/11/01
- [Guile-commits] 05/17: regexec comment fix, Andy Wingo, 2016/11/01
- [Guile-commits] 15/17: Remove call/cc assertion about critical sections, Andy Wingo, 2016/11/01
- [Guile-commits] 09/17: Simplify critical section implementation,
Andy Wingo <=
- [Guile-commits] 10/17: Mutex instead of critical section in GOOPS, Andy Wingo, 2016/11/01
- [Guile-commits] 02/17: Add scm_yield to manual alongside yield, Andy Wingo, 2016/11/01
- [Guile-commits] 12/17: Remove critical section in scm_debug_options, Andy Wingo, 2016/11/01
- [Guile-commits] 14/17: Remove last critical section use, Andy Wingo, 2016/11/01
- [Guile-commits] 17/17: Deprecate critical sections, Andy Wingo, 2016/11/01