52 |
/* This is an interface between Guile and the pthreads thread package. */ |
/* This is an interface between Guile and the pthreads thread package. */ |
53 |
|
|
54 |
#include <pthread.h> |
#include <pthread.h> |
55 |
|
#include <sched.h> |
56 |
|
|
57 |
/* MDJ 021209 <djurfeldt@nada.kth.se>: |
/* MDJ 021209 <djurfeldt@nada.kth.se>: |
58 |
The separation of the plugin interface and the low-level C API |
The separation of the plugin interface and the low-level C API |
66 |
|
|
67 |
#define scm_i_plugin_thread_join pthread_join |
#define scm_i_plugin_thread_join pthread_join |
68 |
#define scm_i_plugin_thread_detach pthread_detach |
#define scm_i_plugin_thread_detach pthread_detach |
69 |
#define scm_i_plugin_thread_self pthread_self |
#define scm_i_plugin_thread_self pthread_self |
70 |
|
#define scm_i_plugin_thread_yield sched_yield |
71 |
|
|
72 |
#define scm_t_mutex pthread_mutex_t |
/* Size is checked in scm_init_pthread_threads */ |
73 |
|
#ifdef SCM_DEBUG_THREADS |
74 |
|
#define SCM_MUTEX_MAXSIZE (9 * sizeof (long)) |
75 |
|
#else |
76 |
|
#define SCM_MUTEX_MAXSIZE (6 * sizeof (long)) |
77 |
|
#endif |
78 |
|
typedef struct { char _[SCM_MUTEX_MAXSIZE]; } scm_t_mutex; |
79 |
#define scm_t_mutexattr pthread_mutexattr_t |
#define scm_t_mutexattr pthread_mutexattr_t |
80 |
|
|
81 |
extern scm_t_mutexattr scm_i_plugin_mutex; /* The "fast" mutex. */ |
extern scm_t_mutexattr scm_i_plugin_mutex; /* The "fast" mutex. */ |
82 |
|
|
83 |
#define scm_i_plugin_mutex_init pthread_mutex_init |
#ifdef SCM_DEBUG_THREADS |
84 |
#define scm_i_plugin_mutex_destroy pthread_mutex_destroy |
int scm_i_plugin_mutex_init (scm_t_mutex *, const scm_t_mutexattr *); |
85 |
#define scm_i_plugin_mutex_lock pthread_mutex_lock |
int scm_i_plugin_mutex_lock (scm_t_mutex *); |
86 |
#define scm_i_plugin_mutex_trylock pthread_mutex_trylock |
int scm_i_plugin_mutex_unlock (scm_t_mutex *); |
87 |
#define scm_i_plugin_mutex_unlock pthread_mutex_unlock |
#else |
88 |
|
#define scm_i_plugin_mutex_init(m,a) \ |
89 |
|
pthread_mutex_init ((pthread_mutex_t *) (m), (a)) |
90 |
|
#define scm_i_plugin_mutex_lock(m) \ |
91 |
|
pthread_mutex_lock ((pthread_mutex_t *) (m)) |
92 |
|
#define scm_i_plugin_mutex_unlock(m) \ |
93 |
|
pthread_mutex_unlock ((pthread_mutex_t *) (m)) |
94 |
|
#endif |
95 |
|
#define scm_i_plugin_mutex_destroy(m) \ |
96 |
|
pthread_mutex_destroy ((pthread_mutex_t *) (m)) |
97 |
|
#define scm_i_plugin_mutex_trylock(m) \ |
98 |
|
pthread_mutex_trylock ((pthread_mutex_t *) (m)) |
99 |
|
|
100 |
/* Size is checked in scm_init_pthread_threads */ |
/* Size is checked in scm_init_pthread_threads */ |
101 |
#define SCM_REC_MUTEX_MAXSIZE (8 * sizeof (long)) |
#ifdef SCM_DEBUG_THREADS |
102 |
|
#define SCM_REC_MUTEX_MAXSIZE (SCM_MUTEX_MAXSIZE + 3 * sizeof (long)) |
103 |
|
#else |
104 |
|
#ifdef SCM_MUTEX_RECURSIVE |
105 |
|
#define SCM_REC_MUTEX_MAXSIZE SCM_MUTEX_MAXSIZE |
106 |
|
#else |
107 |
|
#define SCM_REC_MUTEX_MAXSIZE (SCM_MUTEX_MAXSIZE + 2 * sizeof (long)) |
108 |
|
#endif |
109 |
|
#endif |
110 |
typedef struct { char _[SCM_REC_MUTEX_MAXSIZE]; } scm_t_rec_mutex; |
typedef struct { char _[SCM_REC_MUTEX_MAXSIZE]; } scm_t_rec_mutex; |
111 |
|
|
112 |
extern scm_t_mutexattr scm_i_plugin_rec_mutex; |
extern scm_t_mutexattr scm_i_plugin_rec_mutex; |
113 |
|
|
114 |
#ifdef SCM_MUTEX_RECURSIVE /* pthreads has recursive mutexes! */ |
#if defined (SCM_MUTEX_RECURSIVE) && !defined (SCM_DEBUG_THREADS) |
115 |
|
/* pthreads has recursive mutexes! */ |
116 |
#define scm_i_plugin_rec_mutex_init(m,a) \ |
#define scm_i_plugin_rec_mutex_init(m,a) \ |
117 |
pthread_mutex_init ((pthread_mutex_t *) (m), (a)) |
pthread_mutex_init ((pthread_mutex_t *) (m), (a)) |
118 |
#define scm_i_plugin_rec_mutex_destroy(m) \ |
#define scm_i_plugin_rec_mutex_destroy(m) \ |
135 |
|
|
136 |
#define scm_i_plugin_cond_init pthread_cond_init |
#define scm_i_plugin_cond_init pthread_cond_init |
137 |
#define scm_i_plugin_cond_destroy pthread_cond_destroy |
#define scm_i_plugin_cond_destroy pthread_cond_destroy |
138 |
#define scm_i_plugin_cond_wait pthread_cond_wait |
#define scm_i_plugin_cond_wait(c, m) \ |
139 |
#define scm_i_plugin_cond_timedwait pthread_cond_timedwait |
pthread_cond_wait ((c), (pthread_mutex_t *) (m)) |
140 |
|
#define scm_i_plugin_cond_timedwait(c, m, t) \ |
141 |
|
pthread_cond_timedwait ((c), (pthread_mutex_t *) (m), (t)) |
142 |
#define scm_i_plugin_cond_signal pthread_cond_signal |
#define scm_i_plugin_cond_signal pthread_cond_signal |
143 |
#define scm_i_plugin_cond_broadcast pthread_cond_broadcast |
#define scm_i_plugin_cond_broadcast pthread_cond_broadcast |
144 |
|
|