~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to include/my_pthread.h

MergingĀ mainline

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
 
                            assert((A) != 0);                          \
 
94
                            DBUG_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
 
                            assert(l_rc == 0);                         \
 
100
                            DBUG_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
 
108
118
#ifndef my_pthread_attr_setprio
109
119
#ifdef HAVE_PTHREAD_ATTR_SETPRIO
110
120
#define my_pthread_attr_setprio(A,B) pthread_attr_setprio((A),(B))
207
217
#ifndef set_timespec_nsec
208
218
#define set_timespec_nsec(ABSTIME,NSEC) \
209
219
{ \
210
 
  uint64_t now= my_getsystime() + (NSEC/100); \
211
 
  (ABSTIME).ts_sec=  (now / 10000000UL); \
212
 
  (ABSTIME).ts_nsec= (now % 10000000UL * 100 + ((NSEC) % 100)); \
 
220
  ulonglong now= my_getsystime() + (NSEC/100); \
 
221
  (ABSTIME).ts_sec=  (now / 10000000ULL); \
 
222
  (ABSTIME).ts_nsec= (now % 10000000ULL * 100 + ((NSEC) % 100)); \
213
223
}
214
224
#endif /* !set_timespec_nsec */
215
225
#else
225
235
#ifndef set_timespec_nsec
226
236
#define set_timespec_nsec(ABSTIME,NSEC) \
227
237
{\
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)); \
 
238
  ulonglong now= my_getsystime() + (NSEC/100); \
 
239
  (ABSTIME).tv_sec=  (time_t) (now / 10000000ULL);                  \
 
240
  (ABSTIME).tv_nsec= (long) (now % 10000000ULL * 100 + ((NSEC) % 100)); \
231
241
}
232
242
#endif /* !set_timespec_nsec */
233
243
#endif /* HAVE_TIMESPEC_TS_SEC */
238
248
{
239
249
  pthread_mutex_t global,mutex;
240
250
  const char *file;
241
 
  uint32_t line,count;
 
251
  uint line,count;
242
252
  pthread_t thread;
243
253
} safe_mutex_t;
244
254
 
245
255
int safe_mutex_init(safe_mutex_t *mp, const pthread_mutexattr_t *attr,
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);
 
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);
250
260
int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file,
251
 
                   uint32_t line);
 
261
                   uint line);
252
262
int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
253
 
                        struct timespec *abstime, const char *file, uint32_t line);
 
263
                        struct timespec *abstime, const char *file, uint line);
254
264
void safe_mutex_global_init(void);
255
265
void safe_mutex_end(FILE *file);
256
266
 
262
272
typedef struct st_my_pthread_fastmutex_t
263
273
{
264
274
  pthread_mutex_t mutex;
265
 
  uint32_t spins;
 
275
  uint spins;
266
276
} my_pthread_fastmutex_t;
267
277
void fastmutex_global_init(void);
268
278
 
378
388
 
379
389
typedef ulong my_thread_id;
380
390
 
381
 
extern bool my_thread_global_init(void);
 
391
extern my_bool my_thread_global_init(void);
382
392
extern void my_thread_global_end(void);
383
 
extern bool my_thread_init(void);
 
393
extern my_bool my_thread_init(void);
384
394
extern void my_thread_end(void);
385
395
extern const char *my_thread_name(void);
386
396
extern my_thread_id my_thread_dbug_id(void);
388
398
/* All thread specific variables are in the following struct */
389
399
 
390
400
#define THREAD_NAME_SIZE 10
 
401
#ifndef DEFAULT_THREAD_STACK
 
402
#if SIZEOF_CHARP > 4
391
403
/*
392
 
  Drizzle can survive with 32K, but some glibc libraries require > 128K stack
393
 
  to resolve hostnames. Also recursive stored procedures needs stack.
 
404
  MySQL can survive with 32K, but some glibc libraries require > 128K stack
 
405
  To resolve hostnames. Also recursive stored procedures needs stack.
394
406
*/
395
 
#define DEFAULT_THREAD_STACK    (256*INT32_C(1024))
 
407
#define DEFAULT_THREAD_STACK    (256*1024L)
 
408
#else
 
409
#define DEFAULT_THREAD_STACK    (192*1024)
 
410
#endif
 
411
#endif
396
412
 
397
413
struct st_my_thread_var
398
414
{
404
420
  my_thread_id id;
405
421
  int cmp_length;
406
422
  int volatile abort;
407
 
  bool init;
 
423
  my_bool init;
408
424
  struct st_my_thread_var *next,**prev;
409
425
  void *opt_info;
 
426
#ifndef DBUG_OFF
 
427
  void *dbug;
 
428
  char name[THREAD_NAME_SIZE+1];
 
429
#endif
410
430
};
411
431
 
412
432
extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const));
413
 
extern uint32_t my_thread_end_wait_time;
 
433
extern uint my_thread_end_wait_time;
414
434
#define my_thread_var (_my_thread_var())
415
435
/*
416
436
  Keep track of shutdown,signal, and main threads so that my_end() will not
423
443
#define THD_LIB_NPTL  2
424
444
#define THD_LIB_LT    4
425
445
 
426
 
extern uint32_t thd_lib_detected;
 
446
extern uint thd_lib_detected;
427
447
 
428
448
/*
429
449
  thread_safe_xxx functions are for critical statistic or counters.