SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 }
int32_t ref_count()
Definition: RefCount.cpp:31
void unlock()
Definition: Lock.cpp:64
int32_t unref()
Definition: RefCount.cpp:18
int32_t ref()
Definition: RefCount.cpp:5
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
int32_t rc
Definition: RefCount.h:49
void lock()
Definition: Lock.cpp:57

SHOGUN Machine Learning Toolbox - Documentation