From fb1e8d8b754c47842523a44648a4de8f3ffb8b4f Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 20 Dec 2010 18:50:34 +0000 Subject: [PATCH] ThreadNumber: added (experimental). --- libs/libcommon/src/ThreadNumber.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 libs/libcommon/src/ThreadNumber.cpp diff --git a/libs/libcommon/src/ThreadNumber.cpp b/libs/libcommon/src/ThreadNumber.cpp new file mode 100644 index 00000000000..05cd4211921 --- /dev/null +++ b/libs/libcommon/src/ThreadNumber.cpp @@ -0,0 +1,12 @@ +#include + + +__thread unsigned thread_number = 0; +unsigned threads = 0; + +unsigned ThreadNumber::get() +{ + if (unlikely(!thread_number)) + thread_number = __sync_add_and_fetch(&threads, 1); + return thread_number; +}