Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
OVR_RefCount.cpp
Go to the documentation of this file.
1 /************************************************************************************
2 
3 Filename : OVR_RefCount.cpp
4 Content : Reference counting implementation
5 Created : September 19, 2012
6 Notes :
7 
8 Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
9 
10 Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
11 you may not use the Oculus VR Rift SDK except in compliance with the License,
12 which is provided at the time of installation or download, or which
13 otherwise accompanies this software in either electronic or hard copy form.
14 
15 You may obtain a copy of the License at
16 
17 http://www.oculusvr.com/licenses/LICENSE-3.1
18 
19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
24 
25 ************************************************************************************/
26 
27 #include "OVR_RefCount.h"
28 #include "OVR_Atomic.h"
29 #include "OVR_Log.h"
30 
31 namespace OVR {
32 
33 #ifdef OVR_CC_ARM
34 void* ReturnArg0(void* p)
35 {
36  return p;
37 }
38 #endif
39 
40 // ***** Reference Count Base implementation
41 
43 {
44  // RefCount can be either 1 or 0 here.
45  // 0 if Release() was properly called.
46  // 1 if the object was declared on stack or as an aggregate.
47  OVR_ASSERT(RefCount <= 1);
48 }
49 
50 #ifdef OVR_BUILD_DEBUG
51 void RefCountImplCore::reportInvalidDelete(void *pmem)
52 {
54  ("Invalid delete call on ref-counted object at %p. Please use Release()", pmem));
55  OVR_ASSERT(0);
56 }
57 #endif
58 
60 {
61  // RefCount can be either 1 or 0 here.
62  // 0 if Release() was properly called.
63  // 1 if the object was declared on stack or as an aggregate.
64  OVR_ASSERT(RefCount <= 1);
65 }
66 
67 #ifdef OVR_BUILD_DEBUG
68 void RefCountNTSImplCore::reportInvalidDelete(void *pmem)
69 {
71  ("Invalid delete call on ref-counted object at %p. Please use Release()", pmem));
72  OVR_ASSERT(0);
73 }
74 #endif
75 
76 
77 // *** Thread-Safe RefCountImpl
78 
80 {
82 }
84 {
85  if ((AtomicOps<int>::ExchangeAdd_NoSync(&RefCount, -1) - 1) == 0)
86  delete this;
87 }
88 
89 // *** Thread-Safe RefCountVImpl w/virtual AddRef/Release
90 
92 {
94 }
96 {
97  if ((AtomicOps<int>::ExchangeAdd_NoSync(&RefCount, -1) - 1) == 0)
98  delete this;
99 }
100 
101 // *** NON-Thread-Safe RefCountImpl
102 
104 {
105  RefCount--;
106  if (RefCount == 0)
107  delete this;
108 }
109 
110 
111 } // OVR
void Release() const
volatile int RefCount
Definition: OVR_RefCount.h:65
virtual void Release()
void * ReturnArg0(void *p)
#define OVR_ASSERT(p)
static C ExchangeAdd_NoSync(volatile C *p, C val)
Definition: OVR_Atomic.h:583
#define OVR_DEBUG_LOG(args)
Definition: OVR_Log.h:196
virtual void AddRef()