53
53
#define pthread_handler_t void *
54
54
typedef void *(* pthread_handler)(void *);
56
/* Test first for RTS or FSU threads */
58
#if defined(PTHREAD_SCOPE_GLOBAL) && !defined(PTHREAD_SCOPE_SYSTEM)
59
#define HAVE_rts_threads
60
extern int my_pthread_create_detached;
61
#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C))
62
#define PTHREAD_CREATE_DETACHED &my_pthread_create_detached
63
#define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_GLOBAL
64
#define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_LOCAL
65
#define USE_ALARM_THREAD
66
#endif /* defined(PTHREAD_SCOPE_GLOBAL) && !defined(PTHREAD_SCOPE_SYSTEM) */
68
#ifndef HAVE_NONPOSIX_SIGWAIT
69
#define my_sigwait(A,B) sigwait((A),(B))
71
int my_sigwait(const sigset_t *set,int *sig);
74
#ifdef HAVE_NONPOSIX_PTHREAD_MUTEX_INIT
75
#define pthread_mutex_init(a,b) my_pthread_mutex_init((a),(b))
76
extern int my_pthread_mutex_init(pthread_mutex_t *mp,
77
const pthread_mutexattr_t *attr);
78
#define pthread_cond_init(a,b) my_pthread_cond_init((a),(b))
79
extern int my_pthread_cond_init(pthread_cond_t *mp,
80
const pthread_condattr_t *attr);
81
#endif /* HAVE_NONPOSIX_PTHREAD_MUTEX_INIT */
83
56
#if defined(HAVE_SIGTHREADMASK) && !defined(HAVE_PTHREAD_SIGMASK)
84
57
#define pthread_sigmask(A,B,C) sigthreadmask((A),(B),(C))
87
#if !defined(HAVE_SIGWAIT) && !defined(HAVE_rts_threads) && !defined(sigwait) && !defined(alpha_linux_port) && !defined(HAVE_NONPOSIX_SIGWAIT)
88
int sigwait(sigset_t *setp, int *sigp); /* Use our implemention */
93
62
We define my_sigset() and use that instead of the system sigset() so that
130
99
#define pthread_cond_timedwait(A,B,C) my_pthread_cond_timedwait((A),(B),(C))
134
#if !defined(HAVE_PTHREAD_KEY_DELETE) && !defined(pthread_key_delete)
135
#define pthread_key_delete(A) pthread_dummy(0)
138
#ifdef HAVE_CTHREADS_WRAPPER /* For MacOSX */
139
#define pthread_cond_destroy(A) pthread_dummy(0)
140
#define pthread_mutex_destroy(A) pthread_dummy(0)
141
#define pthread_attr_delete(A) pthread_dummy(0)
142
#define pthread_condattr_delete(A) pthread_dummy(0)
143
#define pthread_attr_setstacksize(A,B) pthread_dummy(0)
144
#define pthread_equal(A,B) ((A) == (B))
145
#define pthread_cond_timedwait(a,b,c) pthread_cond_wait((a),(b))
146
#define pthread_attr_init(A) pthread_attr_create(A)
147
#define pthread_attr_destroy(A) pthread_attr_delete(A)
148
#define pthread_attr_setdetachstate(A,B) pthread_dummy(0)
149
#define pthread_create(A,B,C,D) pthread_create((A),*(B),(C),(D))
150
#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C))
151
#define pthread_kill(A,B) pthread_dummy((A) ? 0 : ESRCH)
152
#undef pthread_detach_this_thread
153
#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(&tmp); }
156
#ifdef HAVE_DARWIN5_THREADS
157
#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C))
158
#define pthread_kill(A,B) pthread_dummy((A) ? 0 : ESRCH)
159
#define pthread_condattr_init(A) pthread_dummy(0)
160
#define pthread_condattr_destroy(A) pthread_dummy(0)
161
#undef pthread_detach_this_thread
162
#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(tmp); }
165
#if (defined(HAVE_PTHREAD_ATTR_CREATE) && !defined(HAVE_SIGWAIT))
166
/* This is set on AIX_3_2 and Siemens unix (and DEC OSF/1 3.2 too) */
167
#define pthread_key_create(A,B) \
168
pthread_keycreate(A,(B) ?\
169
(pthread_destructor_t) (B) :\
170
(pthread_destructor_t) pthread_dummy)
171
#define pthread_attr_init(A) pthread_attr_create(A)
172
#define pthread_attr_destroy(A) pthread_attr_delete(A)
173
#define pthread_attr_setdetachstate(A,B) pthread_dummy(0)
174
#define pthread_create(A,B,C,D) pthread_create((A),*(B),(C),(D))
175
#ifndef pthread_sigmask
176
#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C))
178
#define pthread_kill(A,B) pthread_dummy((A) ? 0 : ESRCH)
179
#undef pthread_detach_this_thread
180
#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(&tmp); }
182
102
#define HAVE_PTHREAD_KILL
185
#if defined(HAVE_POSIX1003_4a_MUTEX) && !defined(DONT_REMAP_PTHREAD_FUNCTIONS)
186
#undef pthread_mutex_trylock
187
#define pthread_mutex_trylock(a) my_pthread_mutex_trylock((a))
188
int my_pthread_mutex_trylock(pthread_mutex_t *mutex);
191
104
#if !defined(HAVE_PTHREAD_YIELD_ONE_ARG) && !defined(HAVE_PTHREAD_YIELD_ZERO_ARG)
192
105
/* no pthread_yield() available */
264
177
#define safe_mutex_assert_owner(mp)
265
178
#define safe_mutex_assert_not_owner(mp)
267
#if defined(MY_PTHREAD_FASTMUTEX)
268
typedef struct st_my_pthread_fastmutex_t
270
pthread_mutex_t mutex;
272
} my_pthread_fastmutex_t;
273
void fastmutex_global_init(void);
275
int my_pthread_fastmutex_init(my_pthread_fastmutex_t *mp,
276
const pthread_mutexattr_t *attr);
277
int my_pthread_fastmutex_lock(my_pthread_fastmutex_t *mp);
279
#undef pthread_mutex_init
280
#undef pthread_mutex_lock
281
#undef pthread_mutex_unlock
282
#undef pthread_mutex_destroy
283
#undef pthread_mutex_wait
284
#undef pthread_mutex_timedwait
285
#undef pthread_mutex_t
286
#undef pthread_cond_wait
287
#undef pthread_cond_timedwait
288
#undef pthread_mutex_trylock
289
#define pthread_mutex_init(A,B) my_pthread_fastmutex_init((A),(B))
290
#define pthread_mutex_lock(A) my_pthread_fastmutex_lock(A)
291
#define pthread_mutex_unlock(A) pthread_mutex_unlock(&(A)->mutex)
292
#define pthread_mutex_destroy(A) pthread_mutex_destroy(&(A)->mutex)
293
#define pthread_cond_wait(A,B) pthread_cond_wait((A),&(B)->mutex)
294
#define pthread_cond_timedwait(A,B,C) pthread_cond_timedwait((A),&(B)->mutex,(C))
295
#define pthread_mutex_trylock(A) pthread_mutex_trylock(&(A)->mutex)
296
#define pthread_mutex_t my_pthread_fastmutex_t
297
#endif /* defined(MY_PTHREAD_FASTMUTEX) */
299
180
/* READ-WRITE thread locking */
301
#ifdef HAVE_BROKEN_RWLOCK /* For OpenUnix */
302
#undef HAVE_PTHREAD_RWLOCK_RDLOCK
303
#undef HAVE_RWLOCK_INIT
307
#if defined(USE_MUTEX_INSTEAD_OF_RW_LOCKS)
308
/* use these defs for simple mutex locking */
309
#define rw_lock_t pthread_mutex_t
310
#define my_rwlock_init(A,B) pthread_mutex_init((A),(B))
311
#define rw_rdlock(A) pthread_mutex_lock((A))
312
#define rw_wrlock(A) pthread_mutex_lock((A))
313
#define rw_tryrdlock(A) pthread_mutex_trylock((A))
314
#define rw_trywrlock(A) pthread_mutex_trylock((A))
315
#define rw_unlock(A) pthread_mutex_unlock((A))
316
#define rwlock_destroy(A) pthread_mutex_destroy((A))
317
#elif defined(HAVE_PTHREAD_RWLOCK_RDLOCK)
318
#define rw_lock_t pthread_rwlock_t
319
#define my_rwlock_init(A,B) pthread_rwlock_init((A),(B))
320
#define rw_rdlock(A) pthread_rwlock_rdlock(A)
321
#define rw_wrlock(A) pthread_rwlock_wrlock(A)
322
#define rw_tryrdlock(A) pthread_rwlock_tryrdlock((A))
323
#define rw_trywrlock(A) pthread_rwlock_trywrlock((A))
324
#define rw_unlock(A) pthread_rwlock_unlock(A)
325
#define rwlock_destroy(A) pthread_rwlock_destroy(A)
326
#elif defined(HAVE_RWLOCK_INIT)
327
#ifdef HAVE_RWLOCK_T /* For example Solaris 2.6-> */
328
#define rw_lock_t rwlock_t
330
#define my_rwlock_init(A,B) rwlock_init((A),USYNC_THREAD,0)
332
/* Use our own version of read/write locks */
333
typedef struct _my_rw_lock_t {
334
pthread_mutex_t lock; /* lock for structure */
335
pthread_cond_t readers; /* waiting readers */
336
pthread_cond_t writers; /* waiting writers */
337
int state; /* -1:writer,0:free,>0:readers */
338
int waiters; /* number of waiting writers */
341
#define rw_lock_t my_rw_lock_t
342
#define rw_rdlock(A) my_rw_rdlock((A))
343
#define rw_wrlock(A) my_rw_wrlock((A))
344
#define rw_tryrdlock(A) my_rw_tryrdlock((A))
345
#define rw_trywrlock(A) my_rw_trywrlock((A))
346
#define rw_unlock(A) my_rw_unlock((A))
347
#define rwlock_destroy(A) my_rwlock_destroy((A))
349
extern int my_rwlock_init(my_rw_lock_t *, void *);
350
extern int my_rwlock_destroy(my_rw_lock_t *);
351
extern int my_rw_rdlock(my_rw_lock_t *);
352
extern int my_rw_wrlock(my_rw_lock_t *);
353
extern int my_rw_unlock(my_rw_lock_t *);
354
extern int my_rw_tryrdlock(my_rw_lock_t *);
355
extern int my_rw_trywrlock(my_rw_lock_t *);
356
#endif /* USE_MUTEX_INSTEAD_OF_RW_LOCKS */
358
182
#ifndef HAVE_THR_SETCONCURRENCY
359
183
#define thr_setconcurrency(A) pthread_dummy(0)