15 #include "copyOnWritePointer.h" 16 #include "config_util.h" 17 #include "config_pipeline.h" 39 while (_cow_object->_lock_status == CopyOnWriteObject::LS_locked_write) {
40 if (_cow_object->_locking_thread == current_thread) {
43 if (util_cat.is_debug()) {
45 << *current_thread <<
" waiting on " << _cow_object->get_type()
46 <<
" " << _cow_object <<
", held by " << *_cow_object->_locking_thread
49 _cow_object->_lock_cvar.wait();
52 _cow_object->_lock_status = CopyOnWriteObject::LS_locked_read;
53 _cow_object->_locking_thread = current_thread;
56 #endif // COW_THREADED 80 _cow_object->_lock_mutex.acquire();
81 while (_cow_object->_lock_status == CopyOnWriteObject::LS_locked_write &&
82 _cow_object->_locking_thread != current_thread) {
83 if (util_cat.is_debug()) {
85 << *current_thread <<
" waiting on " << _cow_object->get_type()
86 <<
" " << _cow_object <<
", held by " << *_cow_object->_locking_thread
89 _cow_object->_lock_cvar.wait();
92 if (_cow_object->_lock_status == CopyOnWriteObject::LS_locked_read) {
95 if (util_cat.is_debug()) {
97 <<
"Making copy of " << _cow_object->get_type()
98 <<
" because it is locked in read mode.\n";
102 _cow_object->CachedTypedWritableReferenceCount::cache_unref();
103 _cow_object->_lock_mutex.release();
106 _cow_object = new_object;
107 _cow_object->CachedTypedWritableReferenceCount::cache_ref();
108 _cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
109 _cow_object->_locking_thread = current_thread;
117 if (util_cat.is_debug()) {
119 <<
"Making copy of " << _cow_object->get_type()
120 <<
" because it is shared by " << _cow_object->
get_ref_count()
125 _cow_object->CachedTypedWritableReferenceCount::cache_unref();
126 _cow_object->_lock_mutex.release();
129 _cow_object = new_object;
130 _cow_object->CachedTypedWritableReferenceCount::cache_ref();
131 _cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
132 _cow_object->_locking_thread = current_thread;
144 _cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
145 _cow_object->_locking_thread = current_thread;
146 _cow_object->_lock_mutex.release();
151 #endif // COW_THREADED const CopyOnWriteObject * get_read_pointer() const
Returns a pointer locked for read.
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
int get_cache_ref_count() const
Returns the current reference count.
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
CopyOnWriteObject * get_write_pointer()
Returns a pointer locked for write.
int get_ref_count() const
Returns the current reference count.
This base class provides basic reference counting, but also can be used with a CopyOnWritePointer to ...
A thread; that is, a lightweight process.