oculus1

diff libovr/Src/Kernel/OVR_RefCount.cpp @ 1:e2f9e4603129

added LibOVR and started a simple vr wrapper.
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Sep 2013 16:14:59 +0300
parents
children b069a5c27388
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libovr/Src/Kernel/OVR_RefCount.cpp	Sat Sep 14 16:14:59 2013 +0300
     1.3 @@ -0,0 +1,1 @@
     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