27 if (_cow_object ==
nullptr) {
32 while (_cow_object->_lock_status == CopyOnWriteObject::LS_locked_write) {
33 if (_cow_object->_locking_thread == current_thread) {
36 if (util_cat.is_debug()) {
38 << *current_thread <<
" waiting on " << _cow_object->get_type()
39 <<
" " << _cow_object <<
", held by " << *_cow_object->_locking_thread
42 _cow_object->_lock_cvar.wait();
45 _cow_object->_lock_status = CopyOnWriteObject::LS_locked_read;
46 _cow_object->_locking_thread = current_thread;
49 #endif // COW_THREADED 63 if (_cow_object ==
nullptr) {
69 _cow_object->_lock_mutex.lock();
70 while (_cow_object->_lock_status == CopyOnWriteObject::LS_locked_write &&
71 _cow_object->_locking_thread != current_thread) {
72 if (util_cat.is_debug()) {
74 << *current_thread <<
" waiting on " << _cow_object->get_type()
75 <<
" " << _cow_object <<
", held by " << *_cow_object->_locking_thread
78 _cow_object->_lock_cvar.wait();
81 if (_cow_object->_lock_status == CopyOnWriteObject::LS_locked_read) {
84 if (util_cat.is_debug()) {
86 <<
"Making copy of " << _cow_object->get_type()
87 <<
" because it is locked in read mode.\n";
91 _cow_object->CachedTypedWritableReferenceCount::cache_unref();
92 _cow_object->_lock_mutex.unlock();
95 _cow_object = new_object;
96 _cow_object->CachedTypedWritableReferenceCount::cache_ref();
97 _cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
98 _cow_object->_locking_thread = current_thread;
106 if (util_cat.is_debug()) {
108 <<
"Making copy of " << _cow_object->get_type()
109 <<
" because it is shared by " << _cow_object->
get_ref_count()
114 _cow_object->CachedTypedWritableReferenceCount::cache_unref();
115 _cow_object->_lock_mutex.unlock();
118 _cow_object = new_object;
119 _cow_object->CachedTypedWritableReferenceCount::cache_ref();
120 _cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
121 _cow_object->_locking_thread = current_thread;
133 _cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
134 _cow_object->_locking_thread = current_thread;
135 _cow_object->_lock_mutex.unlock();
140 #endif // COW_THREADED get_ref_count
Returns the current reference count.
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CopyOnWriteObject * get_write_pointer()
Returns a pointer locked for write.
get_current_thread
Returns a pointer to the currently-executing Thread object.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_cache_ref_count
Returns the current reference count.
This base class provides basic reference counting, but also can be used with a CopyOnWritePointer to ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A thread; that is, a lightweight process.
const CopyOnWriteObject * get_read_pointer(Thread *current_thread) const
Returns a pointer locked for read.