~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_thr_init.c

  • Committer: Monty Taylor
  • Date: 2008-07-05 19:00:59 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: monty@inaugust.com-20080705190059-3vfbd3ebpmzaw5e5
Fixed unsigned long int, format specifiers and functions. 

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
 
#if TIME_WITH_SYS_TIME
26
 
# include <sys/time.h>
27
 
# include <time.h>
28
 
#else
29
 
# if HAVE_SYS_TIME_H
30
 
#  include <sys/time.h>
31
 
# else
32
 
#  include <time.h>
33
 
# endif
34
 
#endif  
35
 
 
36
 
uint32_t thd_lib_detected= 0;
 
25
uint thd_lib_detected= 0;
37
26
 
38
27
#ifdef USE_TLS
39
28
pthread_key(struct st_my_thread_var*, THR_KEY_mysys);
44
33
                THR_LOCK_lock,THR_LOCK_isam,THR_LOCK_myisam,THR_LOCK_heap,
45
34
                THR_LOCK_net, THR_LOCK_charset, THR_LOCK_threads, THR_LOCK_time;
46
35
pthread_cond_t  THR_COND_threads;
47
 
uint32_t            THR_thread_count= 0;
48
 
uint32_t                my_thread_end_wait_time= 5;
 
36
uint            THR_thread_count= 0;
 
37
uint            my_thread_end_wait_time= 5;
49
38
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
50
39
pthread_mutex_t LOCK_localtime_r;
51
40
#endif
77
66
#endif /* TARGET_OS_LINUX */
78
67
 
79
68
 
80
 
static uint32_t get_thread_lib(void);
 
69
static uint get_thread_lib(void);
81
70
 
82
71
/*
83
72
  initialize thread environment
90
79
    1  error (Couldn't create THR_KEY_mysys)
91
80
*/
92
81
 
93
 
bool my_thread_global_init(void)
 
82
my_bool my_thread_global_init(void)
94
83
{
95
84
  int pth_ret;
96
85
  thd_lib_detected= get_thread_lib();
179
168
void my_thread_global_end(void)
180
169
{
181
170
  struct timespec abstime;
182
 
  bool all_threads_killed= 1;
 
171
  my_bool all_threads_killed= 1;
183
172
 
184
173
  set_timespec(abstime, my_thread_end_wait_time);
185
174
  pthread_mutex_lock(&THR_LOCK_threads);
238
227
static my_thread_id thread_id= 0;
239
228
 
240
229
/*
241
 
  Allocate thread specific memory for the thread, used by mysys
 
230
  Allocate thread specific memory for the thread, used by mysys and dbug
242
231
 
243
232
  SYNOPSIS
244
233
    my_thread_init()
249
238
    case the checking of mutex_locks will not work until
250
239
    the pthread_self thread specific variable is initialized.
251
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
 
252
244
  RETURN
253
245
    0  ok
254
246
    1  Fatal error; mysys/dbug functions can't be used
255
247
*/
256
248
 
257
 
bool my_thread_init(void)
 
249
my_bool my_thread_init(void)
258
250
{
259
251
  struct st_my_thread_var *tmp;
260
 
  bool error=0;
 
252
  my_bool error=0;
261
253
 
262
254
#ifdef EXTRA_DEBUG_THREADS
263
255
  fprintf(stderr,"my_thread_init(): thread_id: 0x%lx\n",
264
 
          (uint32_t) pthread_self());
 
256
          (ulong) pthread_self());
265
257
#endif  
266
258
 
267
259
  if (pthread_getspecific(THR_KEY_mysys))
287
279
  tmp->id= ++thread_id;
288
280
  ++THR_thread_count;
289
281
  pthread_mutex_unlock(&THR_LOCK_threads);
 
282
#ifndef DBUG_OFF
 
283
  /* Generate unique name for thread */
 
284
  (void) my_thread_name();
 
285
#endif
290
286
 
291
287
end:
292
288
  return error;
316
312
#endif  
317
313
  if (tmp && tmp->init)
318
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
319
324
#if !defined(__bsdi__) && !defined(__OpenBSD__)
320
325
 /* bsdi and openbsd 3.5 dumps core here */
321
326
    pthread_cond_destroy(&tmp->suspend);
331
336
      Decrement counter for number of running threads. We are using this
332
337
      in my_thread_global_end() to wait until all threads have called
333
338
      my_thread_end and thus freed all memory they have allocated in
334
 
      my_thread_init() 
 
339
      my_thread_init() and DBUG_xxxx
335
340
    */
336
341
    pthread_mutex_lock(&THR_LOCK_threads);
337
 
    assert(THR_thread_count != 0);
 
342
    DBUG_ASSERT(THR_thread_count != 0);
338
343
    if (--THR_thread_count == 0)
339
344
      pthread_cond_signal(&THR_COND_threads);
340
345
   pthread_mutex_unlock(&THR_LOCK_threads);
353
358
  if (!tmp)
354
359
  {
355
360
    my_thread_init();
356
 
    tmp=(struct st_my_thread_var*)pthread_getspecific(THR_KEY_mysys);
 
361
    tmp=my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys);
357
362
  }
358
363
#endif
359
364
  return tmp;
369
374
  return my_thread_var->id;
370
375
}
371
376
 
372
 
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)
373
401
{
374
402
#ifdef _CS_GNU_LIBPTHREAD_VERSION
375
403
  char buff[64];