Panda3D

Loading...
Searching...
No Matches
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 */
27 bool CopyOnWriteObject::
28 unref() const {
29 MutexHolder holder(_lock_mutex);
30 bool is_zero = CachedTypedWritableReferenceCount::unref();
31 if (get_ref_count() == get_cache_ref_count()) {
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 */
45 void CopyOnWriteObject::
46 cache_ref_only() const {
47 MutexHolder holder(_lock_mutex);
48 CachedTypedWritableReferenceCount::cache_ref_only();
49 if (get_ref_count() == get_cache_ref_count()) {
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
CachedTypedWritableReferenceCount::get_cache_ref_count
get_cache_ref_count
Returns the current reference count.
Definition cachedTypedWritableReferenceCount.h:47
CachedTypedWritableReferenceCount::cache_ref_only
void cache_ref_only() const
Decrements the cache reference count without affecting the normal reference count.
Definition cachedTypedWritableReferenceCount.I:168
ReferenceCount::get_ref_count
get_ref_count
Returns the current reference count.
Definition referenceCount.h:53
ReferenceCount::unref
virtual bool unref() const
Explicitly decrements the reference count.
Definition referenceCount.I:179
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.
mutexHolder.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pnotify.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.