1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include "se_thread.h"
- #include <stdlib.h>
- static pthread_key_t g_tid_key;
- static pthread_once_t g_key_once = PTHREAD_ONCE_INIT;
- static void create_key()
- {
- pthread_key_create(&g_tid_key, NULL);
- }
- se_thread_id_t get_thread_id()
- {
- if(pthread_once(&g_key_once, create_key) != 0)
- abort();
-
-
- se_thread_id_t tid = (se_thread_id_t)(size_t)pthread_getspecific(g_tid_key);
- if( tid == 0)
- {
- tid = se_get_threadid();
-
-
-
-
-
- pthread_setspecific(g_tid_key, (void*)(size_t)tid);
- }
- return tid;
- }
|