~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_pthread.h

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
*/
92
92
#if defined(HAVE_SIGACTION) && !defined(my_sigset)
93
93
#define my_sigset(A,B) do { struct sigaction l_s; sigset_t l_set; int l_rc; \
94
 
                            DBUG_ASSERT((A) != 0);                          \
 
94
                            assert((A) != 0);                          \
95
95
                            sigemptyset(&l_set);                            \
96
96
                            l_s.sa_handler = (B);                           \
97
97
                            l_s.sa_mask   = l_set;                          \
98
98
                            l_s.sa_flags   = 0;                             \
99
99
                            l_rc= sigaction((A), &l_s, (struct sigaction *) NULL);\
100
 
                            DBUG_ASSERT(l_rc == 0);                         \
 
100
                            assert(l_rc == 0);                         \
101
101
                          } while (0)
102
102
#elif defined(HAVE_SIGSET) && !defined(my_sigset)
103
103
#define my_sigset(A,B) sigset((A),(B))
105
105
#define my_sigset(A,B) signal((A),(B))
106
106
#endif
107
107
 
108
 
#ifndef my_pthread_setprio
109
 
#if defined(HAVE_PTHREAD_SETPRIO_NP)            /* FSU threads */
110
 
#define my_pthread_setprio(A,B) pthread_setprio_np((A),(B))
111
 
#elif defined(HAVE_PTHREAD_SETPRIO)
112
 
#define my_pthread_setprio(A,B) pthread_setprio((A),(B))
113
 
#else
114
 
extern void my_pthread_setprio(pthread_t thread_id,int prior);
115
 
#endif
116
 
#endif
117
 
 
118
108
#ifndef my_pthread_attr_setprio
119
109
#ifdef HAVE_PTHREAD_ATTR_SETPRIO
120
110
#define my_pthread_attr_setprio(A,B) pthread_attr_setprio((A),(B))
217
207
#ifndef set_timespec_nsec
218
208
#define set_timespec_nsec(ABSTIME,NSEC) \
219
209
{ \
220
 
  ulonglong now= my_getsystime() + (NSEC/100); \
221
 
  (ABSTIME).ts_sec=  (now / ULL(10000000)); \
222
 
  (ABSTIME).ts_nsec= (now % ULL(10000000) * 100 + ((NSEC) % 100)); \
 
210
  uint64_t now= my_getsystime() + (NSEC/100); \
 
211
  (ABSTIME).ts_sec=  (now / 10000000UL); \
 
212
  (ABSTIME).ts_nsec= (now % 10000000UL * 100 + ((NSEC) % 100)); \
223
213
}
224
214
#endif /* !set_timespec_nsec */
225
215
#else
235
225
#ifndef set_timespec_nsec
236
226
#define set_timespec_nsec(ABSTIME,NSEC) \
237
227
{\
238
 
  ulonglong now= my_getsystime() + (NSEC/100); \
239
 
  (ABSTIME).tv_sec=  (time_t) (now / ULL(10000000));                  \
240
 
  (ABSTIME).tv_nsec= (long) (now % ULL(10000000) * 100 + ((NSEC) % 100)); \
 
228
  uint64_t now= my_getsystime() + (NSEC/100); \
 
229
  (ABSTIME).tv_sec=  (time_t) (now / 10000000UL);                  \
 
230
  (ABSTIME).tv_nsec= (long) (now % 10000000UL * 100 + ((NSEC) % 100)); \
241
231
}
242
232
#endif /* !set_timespec_nsec */
243
233
#endif /* HAVE_TIMESPEC_TS_SEC */
248
238
{
249
239
  pthread_mutex_t global,mutex;
250
240
  const char *file;
251
 
  uint line,count;
 
241
  uint32_t line,count;
252
242
  pthread_t thread;
253
243
} safe_mutex_t;
254
244
 
255
245
int safe_mutex_init(safe_mutex_t *mp, const pthread_mutexattr_t *attr,
256
 
                    const char *file, uint line);
257
 
int safe_mutex_lock(safe_mutex_t *mp, my_bool try_lock, const char *file, uint line);
258
 
int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint line);
259
 
int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint line);
 
246
                    const char *file, uint32_t line);
 
247
int safe_mutex_lock(safe_mutex_t *mp, bool try_lock, const char *file, uint32_t line);
 
248
int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint32_t line);
 
249
int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint32_t line);
260
250
int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file,
261
 
                   uint line);
 
251
                   uint32_t line);
262
252
int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
263
 
                        struct timespec *abstime, const char *file, uint line);
 
253
                        struct timespec *abstime, const char *file, uint32_t line);
264
254
void safe_mutex_global_init(void);
265
255
void safe_mutex_end(FILE *file);
266
256
 
272
262
typedef struct st_my_pthread_fastmutex_t
273
263
{
274
264
  pthread_mutex_t mutex;
275
 
  uint spins;
 
265
  uint32_t spins;
276
266
} my_pthread_fastmutex_t;
277
267
void fastmutex_global_init(void);
278
268
 
388
378
 
389
379
typedef ulong my_thread_id;
390
380
 
391
 
extern my_bool my_thread_global_init(void);
 
381
extern bool my_thread_global_init(void);
392
382
extern void my_thread_global_end(void);
393
 
extern my_bool my_thread_init(void);
 
383
extern bool my_thread_init(void);
394
384
extern void my_thread_end(void);
395
385
extern const char *my_thread_name(void);
396
386
extern my_thread_id my_thread_dbug_id(void);
398
388
/* All thread specific variables are in the following struct */
399
389
 
400
390
#define THREAD_NAME_SIZE 10
401
 
#ifndef DEFAULT_THREAD_STACK
402
 
#if SIZEOF_CHARP > 4
403
391
/*
404
 
  MySQL can survive with 32K, but some glibc libraries require > 128K stack
405
 
  To resolve hostnames. Also recursive stored procedures needs stack.
 
392
  Drizzle can survive with 32K, but some glibc libraries require > 128K stack
 
393
  to resolve hostnames. Also recursive stored procedures needs stack.
406
394
*/
407
 
#define DEFAULT_THREAD_STACK    (256*1024L)
408
 
#else
409
 
#define DEFAULT_THREAD_STACK    (192*1024)
410
 
#endif
411
 
#endif
 
395
#define DEFAULT_THREAD_STACK    (256*INT32_C(1024))
412
396
 
413
397
struct st_my_thread_var
414
398
{
420
404
  my_thread_id id;
421
405
  int cmp_length;
422
406
  int volatile abort;
423
 
  my_bool init;
 
407
  bool init;
424
408
  struct st_my_thread_var *next,**prev;
425
409
  void *opt_info;
426
 
#ifndef DBUG_OFF
427
 
  void *dbug;
428
 
  char name[THREAD_NAME_SIZE+1];
429
 
#endif
430
410
};
431
411
 
432
412
extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const));
433
 
extern uint my_thread_end_wait_time;
 
413
extern uint32_t my_thread_end_wait_time;
434
414
#define my_thread_var (_my_thread_var())
435
415
/*
436
416
  Keep track of shutdown,signal, and main threads so that my_end() will not
443
423
#define THD_LIB_NPTL  2
444
424
#define THD_LIB_LT    4
445
425
 
446
 
extern uint thd_lib_detected;
 
426
extern uint32_t thd_lib_detected;
447
427
 
448
428
/*
449
429
  thread_safe_xxx functions are for critical statistic or counters.
453
433
  to use my_atomic operations instead.
454
434
*/
455
435
 
456
 
/*
457
 
  Warning:
458
 
  When compiling without threads, this file is not included.
459
 
  See the *other* declarations of thread_safe_xxx in include/my_global.h
460
 
 
461
 
  Second warning:
462
 
  See include/config-win.h, for yet another implementation.
463
 
*/
464
 
#ifdef THREAD
465
436
#ifndef thread_safe_increment
466
437
#define thread_safe_increment(V,L) \
467
438
        (pthread_mutex_lock((L)), (V)++, pthread_mutex_unlock((L)))
475
446
#define thread_safe_sub(V,C,L) \
476
447
        (pthread_mutex_lock((L)), (V)-=(C), pthread_mutex_unlock((L)))
477
448
#endif
478
 
#endif
479
449
 
480
450
/*
481
451
  statistics_xxx functions are for non critical statistic,