~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_thr_init.cc

  • Committer: Monty
  • Date: 2008-11-23 09:50:11 UTC
  • mfrom: (602 drizzle)
  • mto: This revision was merged to the branch mainline in revision 603.
  • Revision ID: mordred@palanthas.inaugust.com-20081123095011-4fc0daxxumw90eko
MergedĀ inĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
  thread variables.
19
19
*/
20
20
 
 
21
#include <stdio.h>
21
22
#include <mysys/mysys_priv.h>
22
23
#include <mysys/my_pthread.h>
23
24
#include <mystrings/m_string.h>
41
42
#else
42
43
pthread_key_t THR_KEY_mysys;
43
44
#endif /* USE_TLS */
44
 
pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open,
45
 
                THR_LOCK_lock,THR_LOCK_isam,THR_LOCK_myisam,THR_LOCK_heap,
46
 
                THR_LOCK_net, THR_LOCK_charset, THR_LOCK_threads, THR_LOCK_time;
 
45
pthread_mutex_t THR_LOCK_open;
 
46
pthread_mutex_t THR_LOCK_lock;
 
47
pthread_mutex_t THR_LOCK_charset; 
 
48
pthread_mutex_t THR_LOCK_threads; 
 
49
pthread_mutex_t THR_LOCK_time;
47
50
pthread_cond_t  THR_COND_threads;
48
51
uint32_t            THR_thread_count= 0;
49
52
uint32_t                my_thread_end_wait_time= 5;
50
 
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
51
 
pthread_mutex_t LOCK_localtime_r;
52
 
#endif
53
 
#ifndef HAVE_GETHOSTBYNAME_R
54
 
pthread_mutex_t LOCK_gethostbyname_r;
55
 
#endif
56
53
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
57
54
pthread_mutexattr_t my_fast_mutexattr;
58
55
#endif
103
100
    return 1;
104
101
  }
105
102
 
106
 
#ifdef TARGET_OS_LINUX
107
 
  /*
108
 
    BUG#24507: Race conditions inside current NPTL pthread_exit()
109
 
    implementation.
110
 
 
111
 
    To avoid a possible segmentation fault during concurrent
112
 
    executions of pthread_exit(), a dummy thread is spawned which
113
 
    initializes internal variables of pthread lib. See bug description
114
 
    for a full explanation.
115
 
 
116
 
    TODO: Remove this code when fixed versions of glibc6 are in common
117
 
    use.
118
 
  */
119
 
  if (thd_lib_detected == THD_LIB_NPTL)
120
 
  {
121
 
    pthread_t       dummy_thread;
122
 
    pthread_attr_t  dummy_thread_attr;
123
 
 
124
 
    pthread_attr_init(&dummy_thread_attr);
125
 
    pthread_attr_setdetachstate(&dummy_thread_attr, PTHREAD_CREATE_DETACHED);
126
 
 
127
 
    pthread_create(&dummy_thread,&dummy_thread_attr,
128
 
                   nptl_pthread_exit_hack_handler, NULL);
129
 
  }
130
 
#endif /* TARGET_OS_LINUX */
131
 
 
132
103
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
133
104
  /*
134
105
    Set mutex type to "fast" a.k.a "adaptive"
152
123
                            PTHREAD_MUTEX_ERRORCHECK);
153
124
#endif
154
125
 
155
 
  pthread_mutex_init(&THR_LOCK_malloc,MY_MUTEX_INIT_FAST);
156
126
  pthread_mutex_init(&THR_LOCK_open,MY_MUTEX_INIT_FAST);
157
127
  pthread_mutex_init(&THR_LOCK_lock,MY_MUTEX_INIT_FAST);
158
 
  pthread_mutex_init(&THR_LOCK_isam,MY_MUTEX_INIT_SLOW);
159
 
  pthread_mutex_init(&THR_LOCK_myisam,MY_MUTEX_INIT_SLOW);
160
 
  pthread_mutex_init(&THR_LOCK_heap,MY_MUTEX_INIT_FAST);
161
 
  pthread_mutex_init(&THR_LOCK_net,MY_MUTEX_INIT_FAST);
162
128
  pthread_mutex_init(&THR_LOCK_charset,MY_MUTEX_INIT_FAST);
163
129
  pthread_mutex_init(&THR_LOCK_threads,MY_MUTEX_INIT_FAST);
164
130
  pthread_mutex_init(&THR_LOCK_time,MY_MUTEX_INIT_FAST);
165
131
  pthread_cond_init(&THR_COND_threads, NULL);
166
 
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
167
 
  pthread_mutex_init(&LOCK_localtime_r,MY_MUTEX_INIT_SLOW);
168
 
#endif
169
 
#ifndef HAVE_GETHOSTBYNAME_R
170
 
  pthread_mutex_init(&LOCK_gethostbyname_r,MY_MUTEX_INIT_SLOW);
171
 
#endif
172
132
  if (my_thread_init())
173
133
  {
174
134
    my_thread_global_end();                     /* Clean up */
215
175
#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
216
176
  pthread_mutexattr_destroy(&my_errorcheck_mutexattr);
217
177
#endif
218
 
  pthread_mutex_destroy(&THR_LOCK_malloc);
219
178
  pthread_mutex_destroy(&THR_LOCK_open);
220
179
  pthread_mutex_destroy(&THR_LOCK_lock);
221
 
  pthread_mutex_destroy(&THR_LOCK_isam);
222
 
  pthread_mutex_destroy(&THR_LOCK_myisam);
223
 
  pthread_mutex_destroy(&THR_LOCK_heap);
224
 
  pthread_mutex_destroy(&THR_LOCK_net);
225
180
  pthread_mutex_destroy(&THR_LOCK_time);
226
181
  pthread_mutex_destroy(&THR_LOCK_charset);
227
182
  if (all_threads_killed)
229
184
    pthread_mutex_destroy(&THR_LOCK_threads);
230
185
    pthread_cond_destroy(&THR_COND_threads);
231
186
  }
232
 
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
233
 
  pthread_mutex_destroy(&LOCK_localtime_r);
234
 
#endif
235
 
#ifndef HAVE_GETHOSTBYNAME_R
236
 
  pthread_mutex_destroy(&LOCK_gethostbyname_r);
237
 
#endif
238
187
}
239
188
 
240
189
static my_thread_id thread_id= 0;