1
Fork 0
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:
Andy Wingo 2016-11-01 22:48:19 +01:00
parent c88d0cc402
commit b410667e64
3 changed files with 12 additions and 42 deletions

View file

@ -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);