oculus1
diff libovr/Src/Kernel/OVR_RefCount.cpp @ 3:b069a5c27388
added a couple more stuff, fixed all the LibOVR line endings
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 15 Sep 2013 04:10:05 +0300 |
parents | e2f9e4603129 |
children |
line diff
1.1 --- a/libovr/Src/Kernel/OVR_RefCount.cpp Sat Sep 14 17:51:03 2013 +0300 1.2 +++ b/libovr/Src/Kernel/OVR_RefCount.cpp Sun Sep 15 04:10:05 2013 +0300 1.3 @@ -1,1 +1,100 @@ 1.4 -/************************************************************************************ 1.5 1.6 Filename : OVR_RefCount.cpp 1.7 Content : Reference counting implementation 1.8 Created : September 19, 2012 1.9 Notes : 1.10 1.11 Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved. 1.12 1.13 Use of this software is subject to the terms of the Oculus license 1.14 agreement provided at the time of installation or download, or which 1.15 otherwise accompanies this software in either electronic or hard copy form. 1.16 1.17 ************************************************************************************/ 1.18 1.19 #include "OVR_RefCount.h" 1.20 #include "OVR_Atomic.h" 1.21 #include "OVR_Log.h" 1.22 1.23 namespace OVR { 1.24 1.25 #ifdef OVR_CC_ARM 1.26 void* ReturnArg0(void* p) 1.27 { 1.28 return p; 1.29 } 1.30 #endif 1.31 1.32 // ***** Reference Count Base implementation 1.33 1.34 RefCountImplCore::~RefCountImplCore() 1.35 { 1.36 // RefCount can be either 1 or 0 here. 1.37 // 0 if Release() was properly called. 1.38 // 1 if the object was declared on stack or as an aggregate. 1.39 OVR_ASSERT(RefCount <= 1); 1.40 } 1.41 1.42 #ifdef OVR_BUILD_DEBUG 1.43 void RefCountImplCore::reportInvalidDelete(void *pmem) 1.44 { 1.45 OVR_DEBUG_LOG( 1.46 ("Invalid delete call on ref-counted object at %p. Please use Release()", pmem)); 1.47 OVR_ASSERT(0); 1.48 } 1.49 #endif 1.50 1.51 RefCountNTSImplCore::~RefCountNTSImplCore() 1.52 { 1.53 // RefCount can be either 1 or 0 here. 1.54 // 0 if Release() was properly called. 1.55 // 1 if the object was declared on stack or as an aggregate. 1.56 OVR_ASSERT(RefCount <= 1); 1.57 } 1.58 1.59 #ifdef OVR_BUILD_DEBUG 1.60 void RefCountNTSImplCore::reportInvalidDelete(void *pmem) 1.61 { 1.62 OVR_DEBUG_LOG( 1.63 ("Invalid delete call on ref-counted object at %p. Please use Release()", pmem)); 1.64 OVR_ASSERT(0); 1.65 } 1.66 #endif 1.67 1.68 1.69 // *** Thread-Safe RefCountImpl 1.70 1.71 void RefCountImpl::AddRef() 1.72 { 1.73 AtomicOps<int>::ExchangeAdd_NoSync(&RefCount, 1); 1.74 } 1.75 void RefCountImpl::Release() 1.76 { 1.77 if ((AtomicOps<int>::ExchangeAdd_NoSync(&RefCount, -1) - 1) == 0) 1.78 delete this; 1.79 } 1.80 1.81 // *** Thread-Safe RefCountVImpl w/virtual AddRef/Release 1.82 1.83 void RefCountVImpl::AddRef() 1.84 { 1.85 AtomicOps<int>::ExchangeAdd_NoSync(&RefCount, 1); 1.86 } 1.87 void RefCountVImpl::Release() 1.88 { 1.89 if ((AtomicOps<int>::ExchangeAdd_NoSync(&RefCount, -1) - 1) == 0) 1.90 delete this; 1.91 } 1.92 1.93 // *** NON-Thread-Safe RefCountImpl 1.94 1.95 void RefCountNTSImpl::Release() const 1.96 { 1.97 RefCount--; 1.98 if (RefCount == 0) 1.99 delete this; 1.100 } 1.101 1.102 1.103 } // OVR 1.104 \ No newline at end of file 1.105 +/************************************************************************************ 1.106 + 1.107 +Filename : OVR_RefCount.cpp 1.108 +Content : Reference counting implementation 1.109 +Created : September 19, 2012 1.110 +Notes : 1.111 + 1.112 +Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved. 1.113 + 1.114 +Use of this software is subject to the terms of the Oculus license 1.115 +agreement provided at the time of installation or download, or which 1.116 +otherwise accompanies this software in either electronic or hard copy form. 1.117 + 1.118 +************************************************************************************/ 1.119 + 1.120 +#include "OVR_RefCount.h" 1.121 +#include "OVR_Atomic.h" 1.122 +#include "OVR_Log.h" 1.123 + 1.124 +namespace OVR { 1.125 + 1.126 +#ifdef OVR_CC_ARM 1.127 +void* ReturnArg0(void* p) 1.128 +{ 1.129 + return p; 1.130 +} 1.131 +#endif 1.132 + 1.133 +// ***** Reference Count Base implementation 1.134 + 1.135 +RefCountImplCore::~RefCountImplCore() 1.136 +{ 1.137 + // RefCount can be either 1 or 0 here. 1.138 + // 0 if Release() was properly called. 1.139 + // 1 if the object was declared on stack or as an aggregate. 1.140 + OVR_ASSERT(RefCount <= 1); 1.141 +} 1.142 + 1.143 +#ifdef OVR_BUILD_DEBUG 1.144 +void RefCountImplCore::reportInvalidDelete(void *pmem) 1.145 +{ 1.146 + OVR_DEBUG_LOG( 1.147 + ("Invalid delete call on ref-counted object at %p. Please use Release()", pmem)); 1.148 + OVR_ASSERT(0); 1.149 +} 1.150 +#endif 1.151 + 1.152 +RefCountNTSImplCore::~RefCountNTSImplCore() 1.153 +{ 1.154 + // RefCount can be either 1 or 0 here. 1.155 + // 0 if Release() was properly called. 1.156 + // 1 if the object was declared on stack or as an aggregate. 1.157 + OVR_ASSERT(RefCount <= 1); 1.158 +} 1.159 + 1.160 +#ifdef OVR_BUILD_DEBUG 1.161 +void RefCountNTSImplCore::reportInvalidDelete(void *pmem) 1.162 +{ 1.163 + OVR_DEBUG_LOG( 1.164 + ("Invalid delete call on ref-counted object at %p. Please use Release()", pmem)); 1.165 + OVR_ASSERT(0); 1.166 +} 1.167 +#endif 1.168 + 1.169 + 1.170 +// *** Thread-Safe RefCountImpl 1.171 + 1.172 +void RefCountImpl::AddRef() 1.173 +{ 1.174 + AtomicOps<int>::ExchangeAdd_NoSync(&RefCount, 1); 1.175 +} 1.176 +void RefCountImpl::Release() 1.177 +{ 1.178 + if ((AtomicOps<int>::ExchangeAdd_NoSync(&RefCount, -1) - 1) == 0) 1.179 + delete this; 1.180 +} 1.181 + 1.182 +// *** Thread-Safe RefCountVImpl w/virtual AddRef/Release 1.183 + 1.184 +void RefCountVImpl::AddRef() 1.185 +{ 1.186 + AtomicOps<int>::ExchangeAdd_NoSync(&RefCount, 1); 1.187 +} 1.188 +void RefCountVImpl::Release() 1.189 +{ 1.190 + if ((AtomicOps<int>::ExchangeAdd_NoSync(&RefCount, -1) - 1) == 0) 1.191 + delete this; 1.192 +} 1.193 + 1.194 +// *** NON-Thread-Safe RefCountImpl 1.195 + 1.196 +void RefCountNTSImpl::Release() const 1.197 +{ 1.198 + RefCount--; 1.199 + if (RefCount == 0) 1.200 + delete this; 1.201 +} 1.202 + 1.203 + 1.204 +} // OVR