SHOGUN
v3.2.0
|
00001 #include <shogun/lib/RefCount.h> 00002 00003 using namespace shogun; 00004 00005 int32_t RefCount::ref() 00006 { 00007 #ifdef HAVE_CXX11_ATOMIC 00008 int32_t count = rc.fetch_add(1)+1; 00009 #else 00010 lock.lock(); 00011 int32_t count = ++rc; 00012 lock.unlock(); 00013 #endif 00014 00015 return count; 00016 } 00017 00018 int32_t RefCount::unref() 00019 { 00020 #ifdef HAVE_CXX11_ATOMIC 00021 int32_t count = rc.fetch_sub(1)-1; 00022 #else 00023 lock.lock(); 00024 int32_t count = --rc; 00025 lock.unlock(); 00026 #endif 00027 00028 return count; 00029 } 00030 00031 int32_t RefCount::ref_count() 00032 { 00033 #ifdef HAVE_CXX11_ATOMIC 00034 int32_t count = rc.load(); 00035 #else 00036 lock.lock(); 00037 int32_t count = rc; 00038 lock.unlock(); 00039 #endif 00040 00041 return count; 00042 }