Panda3D
copyOnWriteObject.cxx
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.cxx
10  * @author drose
11  * @date 2007-04-09
12  */
13 
14 #include "copyOnWriteObject.h"
15 #include "mutexHolder.h"
16 #include "pnotify.h"
17 
18 TypeHandle CopyOnWriteObject::_type_handle;
19 
20 #ifdef COW_THREADED
21 /**
22  * Explicitly decrements the reference count. See ReferenceCount::unref().
23  *
24  * In the case of a CopyOnWriteObject, when the reference count decrements
25  * down to the cache reference count, the object is implicitly unlocked.
26  */
28 unref() const {
29  MutexHolder holder(_lock_mutex);
32  ((CopyOnWriteObject *)this)->_lock_status = LS_unlocked;
33  ((CopyOnWriteObject *)this)->_locking_thread = nullptr;
34  ((CopyOnWriteObject *)this)->_lock_cvar.notify();
35  }
36  return is_zero;
37 }
38 
39 /**
40  * Explicitly increments the cache reference count only. Don't use this.
41  *
42  * In the case of a CopyOnWriteObject, when the reference count decrements
43  * down to the cache reference count, the object is implicitly unlocked.
44  */
46 cache_ref_only() const {
47  MutexHolder holder(_lock_mutex);
50  ((CopyOnWriteObject *)this)->_lock_status = LS_unlocked;
51  ((CopyOnWriteObject *)this)->_locking_thread = nullptr;
52  ((CopyOnWriteObject *)this)->_lock_cvar.notify();
53  }
54 }
55 #endif // COW_THREADED
MutexHolder
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
Definition: mutexHolder.h:25
pnotify.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
copyOnWriteObject.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CopyOnWriteObject
This base class provides basic reference counting, but also can be used with a CopyOnWritePointer to ...
Definition: copyOnWriteObject.h:41
mutexHolder.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ReferenceCount::unref
virtual bool unref() const
Explicitly decrements the reference count.
Definition: referenceCount.I:179
CachedTypedWritableReferenceCount::cache_ref_only
void cache_ref_only() const
Decrements the cache reference count without affecting the normal reference count.
Definition: cachedTypedWritableReferenceCount.I:168
CachedTypedWritableReferenceCount::get_cache_ref_count
get_cache_ref_count
Returns the current reference count.
Definition: cachedTypedWritableReferenceCount.h:47
ReferenceCount::get_ref_count
get_ref_count
Returns the current reference count.
Definition: referenceCount.h:53