retrieve current thread id 0 redis-main 1..N + 1 readers N + 2.. writers
| 86 | // 1..N + 1 readers |
| 87 | // N + 2.. writers |
| 88 | int 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 |
| 115 | void ThreadPools_Pause |