15 #include "copyOnWritePointer.h"
16 #include "mutexHolder.h"
17 #include "config_util.h"
18 #include "config_pipeline.h"
32 get_read_pointer()
const {
40 while (_cow_object->_lock_status == CopyOnWriteObject::LS_locked_write) {
41 if (_cow_object->_locking_thread == current_thread) {
44 if (util_cat.is_debug()) {
46 << *current_thread <<
" waiting on " << _cow_object->get_type()
47 <<
" " << _cow_object <<
", held by " << *_cow_object->_locking_thread
50 _cow_object->_lock_cvar.wait();
53 _cow_object->_lock_status = CopyOnWriteObject::LS_locked_read;
54 _cow_object->_locking_thread = current_thread;
57 #endif // COW_THREADED
82 while (_cow_object->_lock_status == CopyOnWriteObject::LS_locked_write &&
83 _cow_object->_locking_thread != current_thread) {
84 if (util_cat.is_debug()) {
86 << *current_thread <<
" waiting on " << _cow_object->get_type()
87 <<
" " << _cow_object <<
", held by " << *_cow_object->_locking_thread
90 _cow_object->_lock_cvar.wait();
93 if (_cow_object->_lock_status == CopyOnWriteObject::LS_locked_read) {
94 nassertr(_cow_object->get_ref_count() > _cow_object->get_cache_ref_count(), NULL);
96 if (util_cat.is_debug()) {
98 <<
"Making copy of " << _cow_object->get_type()
99 <<
" because it is locked in read mode.\n";
102 cache_unref_delete(_cow_object);
103 _cow_object = new_object;
104 _cow_object->cache_ref();
106 } else if (_cow_object->get_cache_ref_count() > 1) {
110 if (util_cat.is_debug()) {
112 <<
"Making copy of " << _cow_object->get_type()
113 <<
" because it is shared by " << _cow_object->get_ref_count()
118 cache_unref_delete(_cow_object);
119 _cow_object = new_object;
120 _cow_object->cache_ref();
131 _cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
132 _cow_object->_locking_thread = current_thread;
136 #endif // COW_THREADED
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
This base class provides basic reference counting, but also can be used with a CopyOnWritePointer to ...
This safely stores the primary, owned pointer to a CopyOnWriteObject.
A thread; that is, a lightweight process.