Panda3D
copyOnWriteObject.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file copyOnWriteObject.I
10  * @author drose
11  * @date 2007-04-09
12  */
13 
14 template<class Base>
16 
17 template<class Base, class Param1>
19 
20 /**
21  *
22  */
23 INLINE CopyOnWriteObject::
24 CopyOnWriteObject()
25 #ifdef COW_THREADED
26  : _lock_mutex("CopyOnWriteObject::_lock"),
27  _lock_cvar(_lock_mutex)
28 #endif
29 {
30 #ifdef DO_MEMORY_USAGE
31  MemoryUsage::update_type(this, this);
32 #endif
33 #ifdef COW_THREADED
34  _lock_status = LS_unlocked;
35  _locking_thread = nullptr;
36 #endif // COW_THREADED
37 }
38 
39 /**
40  *
41  */
42 INLINE CopyOnWriteObject::
43 CopyOnWriteObject(const CopyOnWriteObject &copy) :
45 #ifdef COW_THREADED
46  , _lock_mutex("CopyOnWriteObject::_lock"),
47  _lock_cvar(_lock_mutex)
48 #endif
49 {
50 #ifdef DO_MEMORY_USAGE
51  MemoryUsage::update_type(this, this);
52 #endif
53 #ifdef COW_THREADED
54  _lock_status = LS_unlocked;
55  _locking_thread = nullptr;
56 #endif // COW_THREADED
57 }
58 
59 /**
60  *
61  */
62 INLINE void CopyOnWriteObject::
63 operator = (const CopyOnWriteObject &copy) {
64  CachedTypedWritableReferenceCount::operator = (copy);
65 }
66 
67 #ifdef COW_THREADED
68 /**
69  * @see CachedTypedWritableReferenceCount::cache_ref()
70  */
71 INLINE void CopyOnWriteObject::
72 cache_ref() const {
73  MutexHolder holder(_lock_mutex);
75 }
76 
77 /**
78  * @see CachedTypedWritableReferenceCount::cache_unref()
79  */
80 INLINE bool CopyOnWriteObject::
81 cache_unref() const {
82  MutexHolder holder(_lock_mutex);
84 }
85 #endif // COW_THREADED
86 
87 /**
88  *
89  */
90 template<class Base>
93 }
94 
95 /**
96  *
97  */
98 template<class Base>
100 CopyOnWriteObj(const Base &copy) :
101  Base(copy)
102 {
103 }
104 
105 /**
106  *
107  */
108 template<class Base>
111  CopyOnWriteObject(copy),
112  Base(copy)
113 {
114 }
115 
116 /**
117  *
118  */
119 template<class Base>
121 make_cow_copy() {
122  return new CopyOnWriteObj<Base>(*this);
123 }
124 
125 /**
126  *
127  */
128 template<class Base>
130 init_type() {
131 #if defined(HAVE_RTTI) && !defined(__EDG__)
132  // If we have RTTI, we can determine the name of the base type.
133  std::string base_name = typeid(Base).name();
134 #else
135  std::string base_name = "unknown";
136 #endif
137 
138  TypeHandle base_type = register_dynamic_type(base_name);
139 
140  CopyOnWriteObject::init_type();
141  _type_handle =
142  register_dynamic_type("CopyOnWriteObj<" + base_name + ">",
143  base_type,
144  CopyOnWriteObject::get_class_type());
145 }
146 
147 /**
148  *
149  */
150 template<class Base, class Param1>
152 CopyOnWriteObj1(Param1 p1) : Base(p1) {
153 }
154 
155 /**
156  *
157  */
158 template<class Base, class Param1>
160 CopyOnWriteObj1(const Base &copy) :
161  Base(copy)
162 {
163 }
164 
165 /**
166  *
167  */
168 template<class Base, class Param1>
171  CopyOnWriteObject(copy),
172  Base(copy)
173 {
174 }
175 
176 /**
177  *
178  */
179 template<class Base, class Param1>
181 make_cow_copy() {
182  return new CopyOnWriteObj1<Base, Param1>(*this);
183 }
184 
185 /**
186  *
187  */
188 template<class Base, class Param1>
190 init_type() {
191 #if defined(HAVE_RTTI) && !defined(__EDG__)
192  // If we have RTTI, we can determine the name of the base type.
193  std::string base_name = typeid(Base).name();
194 #else
195  std::string base_name = "unknown";
196 #endif
197 
198  TypeHandle base_type = register_dynamic_type(base_name);
199 
200  CopyOnWriteObject::init_type();
201  _type_handle =
202  register_dynamic_type("CopyOnWriteObj1<" + base_name + ">",
203  base_type,
204  CopyOnWriteObject::get_class_type());
205 }
For objects (e.g.
This is a special extension to ReferenceCount that includes dual reference counts: the standard refer...
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
Definition: mutexHolder.h:25
bool cache_unref() const
Explicitly decrements the cache reference count and the normal reference count simultaneously.
void cache_ref() const
Explicitly increments the cache reference count and the normal reference count simultaneously.
static void update_type(ReferenceCount *ptr, TypeHandle type)
Associates the indicated type with the given pointer.
Definition: memoryUsage.I:55
This base class provides basic reference counting, but also can be used with a CopyOnWritePointer to ...
This is similar to RefCountObj, but it implements a CopyOnWriteObject inheritance instead of a Refere...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
TypeHandle register_dynamic_type(const std::string &name)
This is essentially similar to register_type(), except that it doesn't store a reference to any TypeH...
Definition: register_type.I:69