MCPcopy Create free account
hub / github.com/async-profiler/async-profiler / initThreadLocalData

Method initThreadLocalData

src/threadLocalData.cpp:24–38  ·  view source on GitHub ↗

Initialize the *thread-local* profiler data key. The global data key (_profiler_data_key) should be initialized beforehand.

Source from the content-addressed store, hash-verified

22// Initialize the *thread-local* profiler data key. The global data key (_profiler_data_key)
23// should be initialized beforehand.
24asprof_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}

Callers

nothing calls this directly

Calls 1

mallocFunction · 0.85

Tested by

no test coverage detected