| 262 | */ |
| 263 | |
| 264 | my_bool my_thread_init(void) |
| 265 | { |
| 266 | struct st_my_thread_var *tmp; |
| 267 | my_bool error=0; |
| 268 | |
| 269 | if (!my_thread_global_init_done) |
| 270 | return 1; /* cannot proceed with unintialized library */ |
| 271 | |
| 272 | #ifdef EXTRA_DEBUG_THREADS |
| 273 | fprintf(stderr,"my_thread_init(): thread_id: 0x%lx\n", |
| 274 | (ulong) pthread_self()); |
| 275 | #endif |
| 276 | |
| 277 | if (_my_thread_var()) |
| 278 | { |
| 279 | #ifdef EXTRA_DEBUG_THREADS |
| 280 | fprintf(stderr,"my_thread_init() called more than once in thread 0x%lx\n", |
| 281 | (long) pthread_self()); |
| 282 | #endif |
| 283 | goto end; |
| 284 | } |
| 285 | |
| 286 | #ifdef _MSC_VER |
| 287 | install_sigabrt_handler(); |
| 288 | #endif |
| 289 | |
| 290 | if (!(tmp= (struct st_my_thread_var *) calloc(1, sizeof(*tmp)))) |
| 291 | { |
| 292 | error= 1; |
| 293 | goto end; |
| 294 | } |
| 295 | set_mysys_var(tmp); |
| 296 | tmp->pthread_self= pthread_self(); |
| 297 | mysql_mutex_init(key_my_thread_var_mutex, &tmp->mutex, MY_MUTEX_INIT_FAST); |
| 298 | mysql_cond_init(key_my_thread_var_suspend, &tmp->suspend, NULL); |
| 299 | |
| 300 | #if defined(_GNU_SOURCE) && (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) |
| 301 | { |
| 302 | pthread_attr_t attr; |
| 303 | char* stack_addr; |
| 304 | size_t stack_size; |
| 305 | |
| 306 | if (pthread_attr_init(&attr) || |
| 307 | pthread_getattr_np(tmp->pthread_self, &attr) || |
| 308 | pthread_attr_getstack(&attr, (void**)&stack_addr, &stack_size)) |
| 309 | { |
| 310 | error= 1; |
| 311 | goto end; |
| 312 | } |
| 313 | tmp->stack_ends_here= stack_addr; |
| 314 | |
| 315 | if (pthread_attr_destroy(&attr)) |
| 316 | { |
| 317 | error= 1; |
| 318 | goto end; |
| 319 | } |
| 320 | } |
| 321 | #else //defined(_GNU_SOURCE) && (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) |