~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_thr_init.c

Removed/replaced DBUG symbols and standardized TRUE/FALSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
*/
20
20
 
21
21
#include "mysys_priv.h"
22
 
#include <mystrings/m_string.h>
 
22
#include <m_string.h>
23
23
#include <signal.h>
24
24
 
25
 
uint32_t thd_lib_detected= 0;
 
25
uint thd_lib_detected= 0;
26
26
 
27
27
#ifdef USE_TLS
28
28
pthread_key(struct st_my_thread_var*, THR_KEY_mysys);
33
33
                THR_LOCK_lock,THR_LOCK_isam,THR_LOCK_myisam,THR_LOCK_heap,
34
34
                THR_LOCK_net, THR_LOCK_charset, THR_LOCK_threads, THR_LOCK_time;
35
35
pthread_cond_t  THR_COND_threads;
36
 
uint32_t            THR_thread_count= 0;
37
 
uint32_t                my_thread_end_wait_time= 5;
 
36
uint            THR_thread_count= 0;
 
37
uint            my_thread_end_wait_time= 5;
38
38
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
39
39
pthread_mutex_t LOCK_localtime_r;
40
40
#endif
66
66
#endif /* TARGET_OS_LINUX */
67
67
 
68
68
 
69
 
static uint32_t get_thread_lib(void);
 
69
static uint get_thread_lib(void);
70
70
 
71
71
/*
72
72
  initialize thread environment
79
79
    1  error (Couldn't create THR_KEY_mysys)
80
80
*/
81
81
 
82
 
bool my_thread_global_init(void)
 
82
my_bool my_thread_global_init(void)
83
83
{
84
84
  int pth_ret;
85
85
  thd_lib_detected= get_thread_lib();
168
168
void my_thread_global_end(void)
169
169
{
170
170
  struct timespec abstime;
171
 
  bool all_threads_killed= 1;
 
171
  my_bool all_threads_killed= 1;
172
172
 
173
173
  set_timespec(abstime, my_thread_end_wait_time);
174
174
  pthread_mutex_lock(&THR_LOCK_threads);
227
227
static my_thread_id thread_id= 0;
228
228
 
229
229
/*
230
 
  Allocate thread specific memory for the thread, used by mysys
 
230
  Allocate thread specific memory for the thread, used by mysys and dbug
231
231
 
232
232
  SYNOPSIS
233
233
    my_thread_init()
238
238
    case the checking of mutex_locks will not work until
239
239
    the pthread_self thread specific variable is initialized.
240
240
 
 
241
   This function may called multiple times for a thread, for example
 
242
   if one uses my_init() followed by mysql_server_init().
 
243
 
241
244
  RETURN
242
245
    0  ok
243
246
    1  Fatal error; mysys/dbug functions can't be used
244
247
*/
245
248
 
246
 
bool my_thread_init(void)
 
249
my_bool my_thread_init(void)
247
250
{
248
251
  struct st_my_thread_var *tmp;
249
 
  bool error=0;
 
252
  my_bool error=0;
250
253
 
251
254
#ifdef EXTRA_DEBUG_THREADS
252
255
  fprintf(stderr,"my_thread_init(): thread_id: 0x%lx\n",
253
 
          (uint32_t) pthread_self());
 
256
          (ulong) pthread_self());
254
257
#endif  
255
258
 
256
259
  if (pthread_getspecific(THR_KEY_mysys))
276
279
  tmp->id= ++thread_id;
277
280
  ++THR_thread_count;
278
281
  pthread_mutex_unlock(&THR_LOCK_threads);
 
282
#ifndef DBUG_OFF
 
283
  /* Generate unique name for thread */
 
284
  (void) my_thread_name();
 
285
#endif
279
286
 
280
287
end:
281
288
  return error;
305
312
#endif  
306
313
  if (tmp && tmp->init)
307
314
  {
 
315
#if !defined(DBUG_OFF)
 
316
    /* tmp->dbug is allocated inside DBUG library */
 
317
    if (tmp->dbug)
 
318
    {
 
319
      DBUG_POP();
 
320
      free(tmp->dbug);
 
321
      tmp->dbug=0;
 
322
    }
 
323
#endif
308
324
#if !defined(__bsdi__) && !defined(__OpenBSD__)
309
325
 /* bsdi and openbsd 3.5 dumps core here */
310
326
    pthread_cond_destroy(&tmp->suspend);
320
336
      Decrement counter for number of running threads. We are using this
321
337
      in my_thread_global_end() to wait until all threads have called
322
338
      my_thread_end and thus freed all memory they have allocated in
323
 
      my_thread_init() 
 
339
      my_thread_init() and DBUG_xxxx
324
340
    */
325
341
    pthread_mutex_lock(&THR_LOCK_threads);
326
 
    assert(THR_thread_count != 0);
 
342
    DBUG_ASSERT(THR_thread_count != 0);
327
343
    if (--THR_thread_count == 0)
328
344
      pthread_cond_signal(&THR_COND_threads);
329
345
   pthread_mutex_unlock(&THR_LOCK_threads);
358
374
  return my_thread_var->id;
359
375
}
360
376
 
361
 
static uint32_t get_thread_lib(void)
 
377
#ifdef DBUG_OFF
 
378
const char *my_thread_name(void)
 
379
{
 
380
  return "no_name";
 
381
}
 
382
 
 
383
#else
 
384
 
 
385
const char *my_thread_name(void)
 
386
{
 
387
  char name_buff[100];
 
388
  struct st_my_thread_var *tmp=my_thread_var;
 
389
  if (!tmp->name[0])
 
390
  {
 
391
    my_thread_id id= my_thread_dbug_id();
 
392
    sprintf(name_buff,"T@%lu", (ulong) id);
 
393
    strmake(tmp->name,name_buff,THREAD_NAME_SIZE);
 
394
  }
 
395
  return tmp->name;
 
396
}
 
397
#endif /* DBUG_OFF */
 
398
 
 
399
 
 
400
static uint get_thread_lib(void)
362
401
{
363
402
#ifdef _CS_GNU_LIBPTHREAD_VERSION
364
403
  char buff[64];