SHOGUN  6.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
RefCount.h
Go to the documentation of this file.
1 #ifndef _REFCOUNT__H__
2 #define _REFCOUNT__H__
3 
4 #include <shogun/lib/config.h>
5 #include <shogun/lib/common.h>
6 #include <atomic>
7 
8 namespace shogun
9 {
13 class RefCount
14 {
15 public:
20  RefCount(int32_t ref_start=0) : rc(ref_start) {};
21 
27  {
28  return rc.fetch_add(1, std::memory_order_relaxed)+1;
29  }
30 
36  {
37  return rc.fetch_sub(1, std::memory_order_acquire)-1;
38  }
39 
45  {
46  return rc.load(std::memory_order_acquire);
47  }
48 
49 private:
51  std::atomic<int32_t> rc;
52 };
53 }
54 
55 #endif //_REFCOUNT__H__
SG_FORCED_INLINE int32_t ref()
Definition: RefCount.h:26
#define SG_FORCED_INLINE
Definition: common.h:91
RefCount(int32_t ref_start=0)
Definition: RefCount.h:20
SG_FORCED_INLINE int32_t unref()
Definition: RefCount.h:35
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
SG_FORCED_INLINE int32_t ref_count()
Definition: RefCount.h:44

SHOGUN Machine Learning Toolbox - Documentation