aboutsummaryrefslogtreecommitdiffstats
path: root/LibOVRKernel/Src/Kernel/OVR_RefCount.cpp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-03-28 02:08:11 +0100
committerSven Gothel <[email protected]>2015-03-28 02:08:11 +0100
commit450aa6f7df9e67dd256b86f94e65eaf707032aad (patch)
tree04aa207d84ddc8ca246d2573aaaf756b3ce8a0b5 /LibOVRKernel/Src/Kernel/OVR_RefCount.cpp
parent3c7b8a17e907f4ef2afd9f77db566a3f6179cbe4 (diff)
parent4207f9c279e832e3afcb3f5fc6cd8d84cb4cfe4c (diff)
Merge branch 'vanilla_0.5.0.1' into jogamp_0.5.0.1
Conflicts: LibOVR/Include/OVR_CAPI_0_5_0.h LibOVR/Src/CAPI/CAPI_HMDState.cpp LibOVR/Src/Displays/OVR_Win32_Dxgi_Display.h LibOVR/Src/Kernel/OVR_System.cpp LibOVR/Src/OVR_CAPI.cpp LibOVR/Src/OVR_Profile.cpp LibOVRKernel/Src/Kernel/OVR_ThreadsWinAPI.cpp LibOVRKernel/Src/Kernel/OVR_Types.h
Diffstat (limited to 'LibOVRKernel/Src/Kernel/OVR_RefCount.cpp')
-rw-r--r--LibOVRKernel/Src/Kernel/OVR_RefCount.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/LibOVRKernel/Src/Kernel/OVR_RefCount.cpp b/LibOVRKernel/Src/Kernel/OVR_RefCount.cpp
new file mode 100644
index 0000000..b04ad29
--- /dev/null
+++ b/LibOVRKernel/Src/Kernel/OVR_RefCount.cpp
@@ -0,0 +1,105 @@
+/************************************************************************************
+
+Filename : OVR_RefCount.cpp
+Content : Reference counting implementation
+Created : September 19, 2012
+Notes :
+
+Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
+
+Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
+you may not use the Oculus VR Rift SDK except in compliance with the License,
+which is provided at the time of installation or download, or which
+otherwise accompanies this software in either electronic or hard copy form.
+
+You may obtain a copy of the License at
+
+http://www.oculusvr.com/licenses/LICENSE-3.2
+
+Unless required by applicable law or agreed to in writing, the Oculus VR SDK
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+************************************************************************************/
+
+#include "OVR_RefCount.h"
+#include "OVR_Atomic.h"
+#include "OVR_Log.h"
+
+namespace OVR {
+
+
+// ***** Reference Count Base implementation
+
+RefCountImplCore::~RefCountImplCore()
+{
+ // RefCount can be either 1 or 0 here.
+ // 0 if Release() was properly called.
+ // 1 if the object was declared on stack or as an aggregate.
+ OVR_ASSERT(RefCount <= 1);
+}
+
+#ifdef OVR_BUILD_DEBUG
+void RefCountImplCore::reportInvalidDelete(void *pmem)
+{
+ OVR_DEBUG_LOG(
+ ("Invalid delete call on ref-counted object at %p. Please use Release()", pmem));
+ OVR_ASSERT(0);
+}
+#endif
+
+RefCountNTSImplCore::~RefCountNTSImplCore()
+{
+ // RefCount can be either 1 or 0 here.
+ // 0 if Release() was properly called.
+ // 1 if the object was declared on stack or as an aggregate.
+ OVR_ASSERT(RefCount <= 1);
+}
+
+#ifdef OVR_BUILD_DEBUG
+void RefCountNTSImplCore::reportInvalidDelete(void *pmem)
+{
+ OVR_DEBUG_LOG(
+ ("Invalid delete call on ref-counted object at %p. Please use Release()", pmem));
+ OVR_ASSERT(0);
+}
+#endif
+
+
+// *** Thread-Safe RefCountImpl
+
+void RefCountImpl::AddRef()
+{
+ AtomicOps<int>::ExchangeAdd_NoSync(&RefCount, 1);
+}
+void RefCountImpl::Release()
+{
+ if ((AtomicOps<int>::ExchangeAdd_NoSync(&RefCount, -1) - 1) == 0)
+ delete this;
+}
+
+// *** Thread-Safe RefCountVImpl w/virtual AddRef/Release
+
+void RefCountVImpl::AddRef()
+{
+ AtomicOps<int>::ExchangeAdd_NoSync(&RefCount, 1);
+}
+void RefCountVImpl::Release()
+{
+ if ((AtomicOps<int>::ExchangeAdd_NoSync(&RefCount, -1) - 1) == 0)
+ delete this;
+}
+
+// *** NON-Thread-Safe RefCountImpl
+
+void RefCountNTSImpl::Release() const
+{
+ RefCount--;
+ if (RefCount == 0)
+ delete this;
+}
+
+
+} // OVR