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
14 template<class Base>
15 TypeHandle CopyOnWriteObj<Base>::_type_handle;
16
17 template<class Base, class Param1>
18 TypeHandle CopyOnWriteObj1<Base, Param1>::_type_handle;
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) :
44 CachedTypedWritableReferenceCount(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::
72 cache_ref() const {
73 MutexHolder holder(_lock_mutex);
74 CachedTypedWritableReferenceCount::cache_ref();
75}
76
77/**
78 * @see CachedTypedWritableReferenceCount::cache_unref()
79 */
80INLINE bool CopyOnWriteObject::
81 cache_unref() const {
82 MutexHolder holder(_lock_mutex);
83 return CachedTypedWritableReferenceCount::cache_unref();
84}
85#endif // COW_THREADED
86
87/**
88 *
89 */
90 template<class Base>
91INLINE CopyOnWriteObj<Base>::
92 CopyOnWriteObj() {
93}
94
95/**
96 *
97 */
98 template<class Base>
99INLINE CopyOnWriteObj<Base>::
100 CopyOnWriteObj(const Base &copy) :
101 Base(copy)
102{
103}
104
105/**
106 *
107 */
108 template<class Base>
109INLINE CopyOnWriteObj<Base>::
110 CopyOnWriteObj(const CopyOnWriteObj<Base> &copy) :
111 CopyOnWriteObject(copy),
112 Base(copy)
113{
114}
115
116/**
117 *
118 */
119 template<class Base>
120PT(CopyOnWriteObject) CopyOnWriteObj<Base>::
121 make_cow_copy() {
122 return new CopyOnWriteObj<Base>(*this);
123}
124
125/**
126 *
127 */
128 template<class Base>
129 void CopyOnWriteObj<Base>::
130 init_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 */
150 template<class Base, class Param1>
151INLINE CopyOnWriteObj1<Base, Param1>::
152 CopyOnWriteObj1(Param1 p1) : Base(p1) {
153}
154
155/**
156 *
157 */
158 template<class Base, class Param1>
159INLINE CopyOnWriteObj1<Base, Param1>::
160 CopyOnWriteObj1(const Base &copy) :
161 Base(copy)
162{
163}
164
165/**
166 *
167 */
168 template<class Base, class Param1>
169INLINE CopyOnWriteObj1<Base, Param1>::
170 CopyOnWriteObj1(const CopyOnWriteObj1<Base, Param1> &copy) :
171 CopyOnWriteObject(copy),
172 Base(copy)
173{
174}
175
176/**
177 *
178 */
179 template<class Base, class Param1>
180PT(CopyOnWriteObject) CopyOnWriteObj1<Base, Param1>::
181 make_cow_copy() {
182 return new CopyOnWriteObj1<Base, Param1>(*this);
183}
184
185/**
186 *
187 */
188 template<class Base, class Param1>
189 void CopyOnWriteObj1<Base, Param1>::
190 init_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}
CachedTypedWritableReferenceCount
This is a special extension to ReferenceCount that includes dual reference counts: the standard refer...
Definition cachedTypedWritableReferenceCount.h:34
CachedTypedWritableReferenceCount::cache_ref
void cache_ref() const
Explicitly increments the cache reference count and the normal reference count simultaneously.
Definition cachedTypedWritableReferenceCount.I:119
CachedTypedWritableReferenceCount::cache_unref
bool cache_unref() const
Explicitly decrements the cache reference count and the normal reference count simultaneously.
Definition cachedTypedWritableReferenceCount.I:136
CopyOnWriteObj1
For objects (e.g.
Definition copyOnWriteObject.h:134
CopyOnWriteObj
This is similar to RefCountObj, but it implements a CopyOnWriteObject inheritance instead of a Refere...
Definition copyOnWriteObject.h:102
CopyOnWriteObject
This base class provides basic reference counting, but also can be used with a CopyOnWritePointer to ...
Definition copyOnWriteObject.h:41
MemoryUsage::update_type
static void update_type(ReferenceCount *ptr, TypeHandle type)
Associates the indicated type with the given pointer.
Definition memoryUsage.I:55
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
register_dynamic_type
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:73