Initialize the *thread-local* profiler data key. The global data key (_profiler_data_key) should be initialized beforehand.
| 22 | // Initialize the *thread-local* profiler data key. The global data key (_profiler_data_key) |
| 23 | // should be initialized beforehand. |
| 24 | asprof_thread_local_data* ThreadLocalData::initThreadLocalData(pthread_key_t profiler_data_key) { |
| 25 | // Initialize. Since this is a thread-local, it is not racy. |
| 26 | asprof_thread_local_data* val = (asprof_thread_local_data*) malloc(sizeof(asprof_thread_local_data)); |
| 27 | if (val == NULL) { |
| 28 | // would rather not insert random aborts into code. This |
| 29 | // will make the code try again next time, which is fine. |
| 30 | return NULL; |
| 31 | } |
| 32 | val->sample_counter = 0; |
| 33 | if (pthread_setspecific(profiler_data_key, (void*)val) != 0) { |
| 34 | free((void*)val); |
| 35 | return NULL; |
| 36 | } |
| 37 | return val; |
| 38 | } |