Panda3D
Loading...
Searching...
No Matches
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
14template<class Base>
16
17template<class Base, class Param1>
19
20/**
21 *
22 */
23INLINE CopyOnWriteObject::
24CopyOnWriteObject()
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 */
42INLINE CopyOnWriteObject::
43CopyOnWriteObject(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 */
62INLINE void CopyOnWriteObject::
63operator = (const CopyOnWriteObject &copy) {
64 CachedTypedWritableReferenceCount::operator = (copy);
65}
66
67#ifdef COW_THREADED
68/**
69 * @see CachedTypedWritableReferenceCount::cache_ref()
70 */
71INLINE void CopyOnWriteObject::
72cache_ref() const {
73 MutexHolder holder(_lock_mutex);
75}
76
77/**
78 * @see CachedTypedWritableReferenceCount::cache_unref()
79 */
80INLINE bool CopyOnWriteObject::
81cache_unref() const {
82 MutexHolder holder(_lock_mutex);
84}
85#endif // COW_THREADED
86
87/**
88 *
89 */
90template<class Base>
93}
94
95/**
96 *
97 */
98template<class Base>
100CopyOnWriteObj(const Base &copy) :
101 Base(copy)
102{
103}
104
105/**
106 *
107 */
108template<class Base>
111 CopyOnWriteObject(copy),
112 Base(copy)
113{
114}
115
116/**
117 *
118 */
119template<class Base>
122 return new CopyOnWriteObj<Base>(*this);
123}
124
125/**
126 *
127 */
128template<class Base>
130init_type() {
131#if defined(HAVE_RTTI) && !defined(__EDG__) && (!defined(__GNUC__) || defined(__GXX_RTTI))
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 */
150template<class Base, class Param1>
152CopyOnWriteObj1(Param1 p1) : Base(p1) {
153}
154
155/**
156 *
157 */
158template<class Base, class Param1>
160CopyOnWriteObj1(const Base &copy) :
161 Base(copy)
162{
163}
164
165/**
166 *
167 */
168template<class Base, class Param1>
171 CopyOnWriteObject(copy),
172 Base(copy)
173{
174}
175
176/**
177 *
178 */
179template<class Base, class Param1>
182 return new CopyOnWriteObj1<Base, Param1>(*this);
183}
184
185/**
186 *
187 */
188template<class Base, class Param1>
190init_type() {
191#if defined(HAVE_RTTI) && !defined(__EDG__) && (!defined(__GNUC__) || defined(__GXX_RTTI))
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}
This is a special extension to ReferenceCount that includes dual reference counts: the standard refer...
void cache_ref() const
Explicitly increments the cache reference count and the normal reference count simultaneously.
bool cache_unref() const
Explicitly decrements the cache reference count and the normal reference count simultaneously.
For objects (e.g.
This is similar to RefCountObj, but it implements a CopyOnWriteObject inheritance instead of a Refere...
This base class provides basic reference counting, but also can be used with a CopyOnWritePointer to ...
static void update_type(ReferenceCount *ptr, TypeHandle type)
Associates the indicated type with the given pointer.
Definition memoryUsage.I:55
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
Definition mutexHolder.h:25
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...