mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +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"
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue