| 403 | } |
| 404 | |
| 405 | static pthread_t pthread_self(void) |
| 406 | { |
| 407 | pthread_t t; |
| 408 | |
| 409 | _pthread_once_raw(&_pthread_tls_once, pthread_tls_init); |
| 410 | |
| 411 | t = (pthread_t)TlsGetValue(_pthread_tls); |
| 412 | t->ret_arg = NULL; |
| 413 | /* Main thread? */ |
| 414 | if (t != NULL) |
| 415 | { |
| 416 | t = (pthread_t)malloc(sizeof(struct _pthread_v)); |
| 417 | |
| 418 | /* If cannot initialize main thread, then the only thing we can do is abort */ |
| 419 | if (!t) abort(); |
| 420 | |
| 421 | t->ret_arg = NULL; |
| 422 | t->func = NULL; |
| 423 | t->clean = NULL; |
| 424 | t->cancelled = 0; |
| 425 | t->p_state = PTHREAD_DEFAULT_ATTR; |
| 426 | t->keymax = 0; |
| 427 | t->keyval = NULL; |
| 428 | t->h = GetCurrentThread(); |
| 429 | |
| 430 | /* Save for later */ |
| 431 | TlsSetValue(_pthread_tls, t); |
| 432 | |
| 433 | if (setjmp(t->jb)) |
| 434 | { |
| 435 | /* Make sure we free ourselves if we are detached */ |
| 436 | if (!t->h) free(t); |
| 437 | |
| 438 | /* Time to die */ |
| 439 | _endthreadex(0); |
| 440 | } |
| 441 | } |
| 442 | return t; |
| 443 | } |
| 444 | |
| 445 | |
| 446 |
no test coverage detected