MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / ThreadPools_GetThreadID

Function ThreadPools_GetThreadID

src/util/thpool/pools.c:88–112  ·  view source on GitHub ↗

retrieve current thread id 0 redis-main 1..N + 1 readers N + 2.. writers

Source from the content-addressed store, hash-verified

86// 1..N + 1 readers
87// N + 2.. writers
88int ThreadPools_GetThreadID
89(
90 void
91) {
92 ASSERT(_readers_thpool != NULL);
93 ASSERT(_writers_thpool != NULL);
94
95 // thpool_get_thread_id returns -1 if pthread_self isn't in the thread pool
96 // most likely Redis main thread
97 int thread_id;
98 pthread_t pthread = pthread_self();
99 int readers_count = thpool_num_threads(_readers_thpool);
100
101 // search in writers
102 thread_id = thpool_get_thread_id(_writers_thpool, pthread);
103 // compensate for Redis main thread
104 if(thread_id != -1) return readers_count + thread_id + 1;
105
106 // search in readers pool
107 thread_id = thpool_get_thread_id(_readers_thpool, pthread);
108 // compensate for Redis main thread
109 if(thread_id != -1) return thread_id + 1;
110
111 return 0; // assuming Redis main thread
112}
113
114// pause all thread pools
115void ThreadPools_Pause

Callers 7

Globals_TrackCommandCtxFunction · 0.85
SlowLog_AddFunction · 0.85
SlowLog_ReplayFunction · 0.85
_GraphContext_FreeFunction · 0.85
get_thread_friendly_idFunction · 0.85

Calls 2

thpool_num_threadsFunction · 0.85
thpool_get_thread_idFunction · 0.85

Tested by 2

get_thread_friendly_idFunction · 0.68