mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
ThreadNumber: fixed error.
This commit is contained in:
parent
e673533a0b
commit
623f5a7680
@ -1,3 +1,6 @@
|
||||
#include <pthread.h>
|
||||
#include <Yandex/optimization.h>
|
||||
|
||||
#include <Yandex/ThreadNumber.h>
|
||||
|
||||
|
||||
@ -6,7 +9,13 @@ unsigned threads = 0;
|
||||
|
||||
unsigned ThreadNumber::get()
|
||||
{
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
if (unlikely(!thread_number))
|
||||
thread_number = __sync_add_and_fetch(&threads, 1);
|
||||
{
|
||||
pthread_mutex_lock(&mutex);
|
||||
if (likely(!thread_number))
|
||||
thread_number = ++threads;
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
return thread_number;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user