mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-02 04:40:29 +02:00
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.
This commit is contained in:
parent
c88d0cc402
commit
b410667e64
3 changed files with 12 additions and 42 deletions
|
@ -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"
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue