SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RefCount.cpp
Go to the documentation of this file.
1 #include <shogun/lib/RefCount.h>
2 
3 using namespace shogun;
4 
5 int32_t RefCount::ref()
6 {
7 #ifdef HAVE_CXX11_ATOMIC
8  int32_t count = rc.fetch_add(1)+1;
9 #else
10  lock.lock();
11  int32_t count = ++rc;
12  lock.unlock();
13 #endif
14 
15  return count;
16 }
17 
18 int32_t RefCount::unref()
19 {
20 #ifdef HAVE_CXX11_ATOMIC
21  int32_t count = rc.fetch_sub(1)-1;
22 #else
23  lock.lock();
24  int32_t count = --rc;
25  lock.unlock();
26 #endif
27 
28  return count;
29 }
30 
32 {
33 #ifdef HAVE_CXX11_ATOMIC
34  int32_t count = rc.load();
35 #else
36  lock.lock();
37  int32_t count = rc;
38  lock.unlock();
39 #endif
40 
41  return count;
42 }

SHOGUN Machine Learning Toolbox - Documentation