~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to include/my_pthread.h

  • Committer: Brian Aker
  • Date: 2008-06-28 06:00:33 UTC
  • Revision ID: brian@tangent.org-20080628060033-a2w679o67rnvbwcg
Further cleanup on pthreads.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#define EXTERNC
30
30
#endif /* __cplusplus */ 
31
31
 
32
 
#ifdef HAVE_rts_threads
33
 
#define sigwait org_sigwait
34
 
#include <signal.h>
35
 
#undef sigwait
36
 
#endif
37
32
#include <pthread.h>
38
33
#ifndef _REENTRANT
39
34
#define _REENTRANT
40
35
#endif
41
 
#ifdef HAVE_THR_SETCONCURRENCY
42
 
#include <thread.h>                     /* Probably solaris */
43
 
#endif
44
36
#ifdef HAVE_SCHED_H
45
37
#include <sched.h>
46
38
#endif
48
40
#include <synch.h>
49
41
#endif
50
42
 
51
 
extern int my_pthread_getprio(pthread_t thread_id);
52
 
 
53
43
#define pthread_key(T,V) pthread_key_t V
54
44
#define my_pthread_getspecific_ptr(T,V) my_pthread_getspecific(T,(V))
55
45
#define my_pthread_setspecific_ptr(T,V) pthread_setspecific(T,(void*) (V))
69
59
#define USE_ALARM_THREAD
70
60
#endif /* defined(PTHREAD_SCOPE_GLOBAL) && !defined(PTHREAD_SCOPE_SYSTEM) */
71
61
 
72
 
#if defined(_BSDI_VERSION) && _BSDI_VERSION < 199910
73
 
int sigwait(sigset_t *set, int *sig);
74
 
#endif
75
 
 
76
62
#ifndef HAVE_NONPOSIX_SIGWAIT
77
63
#define my_sigwait(A,B) sigwait((A),(B))
78
64
#else
80
66
#endif
81
67
 
82
68
#ifdef HAVE_NONPOSIX_PTHREAD_MUTEX_INIT
83
 
#ifndef SAFE_MUTEX
84
69
#define pthread_mutex_init(a,b) my_pthread_mutex_init((a),(b))
85
70
extern int my_pthread_mutex_init(pthread_mutex_t *mp,
86
71
                                 const pthread_mutexattr_t *attr);
87
 
#endif /* SAFE_MUTEX */
88
72
#define pthread_cond_init(a,b) my_pthread_cond_init((a),(b))
89
73
extern int my_pthread_cond_init(pthread_cond_t *mp,
90
74
                                const pthread_condattr_t *attr);
143
127
#define pthread_attr_setscope(A,B)
144
128
#endif
145
129
 
146
 
#if defined(HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT) && !defined(SAFE_MUTEX)
 
130
#if defined(HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT)
147
131
extern int my_pthread_cond_timedwait(pthread_cond_t *cond,
148
132
                                     pthread_mutex_t *mutex,
149
133
                                     struct timespec *abstime);
266
250
  const char *file;
267
251
  uint line,count;
268
252
  pthread_t thread;
269
 
#ifdef SAFE_MUTEX_DETECT_DESTROY
270
 
  struct st_safe_mutex_info_t *info;    /* to track destroying of mutexes */
271
 
#endif
272
253
} safe_mutex_t;
273
254
 
274
 
#ifdef SAFE_MUTEX_DETECT_DESTROY
275
 
/*
276
 
  Used to track the destroying of mutexes. This needs to be a seperate
277
 
  structure because the safe_mutex_t structure could be freed before
278
 
  the mutexes are destroyed.
279
 
*/
280
 
 
281
 
typedef struct st_safe_mutex_info_t
282
 
{
283
 
  struct st_safe_mutex_info_t *next;
284
 
  struct st_safe_mutex_info_t *prev;
285
 
  const char *init_file;
286
 
  uint32 init_line;
287
 
} safe_mutex_info_t;
288
 
#endif /* SAFE_MUTEX_DETECT_DESTROY */
289
 
 
290
255
int safe_mutex_init(safe_mutex_t *mp, const pthread_mutexattr_t *attr,
291
256
                    const char *file, uint line);
292
257
int safe_mutex_lock(safe_mutex_t *mp, my_bool try_lock, const char *file, uint line);
300
265
void safe_mutex_end(FILE *file);
301
266
 
302
267
        /* Wrappers if safe mutex is actually used */
303
 
#ifdef SAFE_MUTEX
304
 
#undef pthread_mutex_init
305
 
#undef pthread_mutex_lock
306
 
#undef pthread_mutex_unlock
307
 
#undef pthread_mutex_destroy
308
 
#undef pthread_mutex_wait
309
 
#undef pthread_mutex_timedwait
310
 
#undef pthread_mutex_t
311
 
#undef pthread_cond_wait
312
 
#undef pthread_cond_timedwait
313
 
#undef pthread_mutex_trylock
314
 
#define pthread_mutex_init(A,B) safe_mutex_init((A),(B),__FILE__,__LINE__)
315
 
#define pthread_mutex_lock(A) safe_mutex_lock((A), FALSE, __FILE__, __LINE__)
316
 
#define pthread_mutex_unlock(A) safe_mutex_unlock((A),__FILE__,__LINE__)
317
 
#define pthread_mutex_destroy(A) safe_mutex_destroy((A),__FILE__,__LINE__)
318
 
#define pthread_cond_wait(A,B) safe_cond_wait((A),(B),__FILE__,__LINE__)
319
 
#define pthread_cond_timedwait(A,B,C) safe_cond_timedwait((A),(B),(C),__FILE__,__LINE__)
320
 
#define pthread_mutex_trylock(A) safe_mutex_lock((A), TRUE, __FILE__, __LINE__)
321
 
#define pthread_mutex_t safe_mutex_t
322
 
#define safe_mutex_assert_owner(mp) \
323
 
          DBUG_ASSERT((mp)->count > 0 && \
324
 
                      pthread_equal(pthread_self(), (mp)->thread))
325
 
#define safe_mutex_assert_not_owner(mp) \
326
 
          DBUG_ASSERT(! (mp)->count || \
327
 
                      ! pthread_equal(pthread_self(), (mp)->thread))
328
 
#else
329
268
#define safe_mutex_assert_owner(mp)
330
269
#define safe_mutex_assert_not_owner(mp)
331
 
#endif /* SAFE_MUTEX */
332
270
 
333
 
#if defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX)
 
271
#if defined(MY_PTHREAD_FASTMUTEX)
334
272
typedef struct st_my_pthread_fastmutex_t
335
273
{
336
274
  pthread_mutex_t mutex;
360
298
#define pthread_cond_timedwait(A,B,C) pthread_cond_timedwait((A),&(B)->mutex,(C))
361
299
#define pthread_mutex_trylock(A) pthread_mutex_trylock(&(A)->mutex)
362
300
#define pthread_mutex_t my_pthread_fastmutex_t
363
 
#endif /* defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX) */
 
301
#endif /* defined(MY_PTHREAD_FASTMUTEX) */
364
302
 
365
303
        /* READ-WRITE thread locking */
366
304
 
544
482
/*
545
483
  statistics_xxx functions are for non critical statistic,
546
484
  maintained in global variables.
547
 
  When compiling with SAFE_STATISTICS:
548
 
  - race conditions can not occur.
549
 
  - some locking occurs, which may cause performance degradation.
550
 
 
551
 
  When compiling without SAFE_STATISTICS:
552
485
  - race conditions can occur, making the result slightly inaccurate.
553
486
  - the lock given is not honored.
554
487
*/
555
 
#ifdef SAFE_STATISTICS
556
 
#define statistic_increment(V,L) thread_safe_increment((V),(L))
557
 
#define statistic_decrement(V,L) thread_safe_decrement((V),(L))
558
 
#define statistic_add(V,C,L)     thread_safe_add((V),(C),(L))
559
 
#define statistic_sub(V,C,L)     thread_safe_sub((V),(C),(L))
560
 
#else
561
488
#define statistic_decrement(V,L) (V)--
562
489
#define statistic_increment(V,L) (V)++
563
490
#define statistic_add(V,C,L)     (V)+=(C)
564
491
#define statistic_sub(V,C,L)     (V)-=(C)
565
 
#endif /* SAFE_STATISTICS */
566
492
 
567
493
/*
568
494
  No locking needed, the counter is owned by the thread