|
|
@@ -12,7 +12,6 @@
|
|
|
*/
|
|
|
|
|
|
#include "copyOnWritePointer.h"
|
|
|
-#include "mutexHolder.h"
|
|
|
#include "config_util.h"
|
|
|
#include "config_pipeline.h"
|
|
|
|
|
|
@@ -69,7 +68,7 @@ get_write_pointer() {
|
|
|
|
|
|
Thread *current_thread = Thread::get_current_thread();
|
|
|
|
|
|
- MutexHolder holder(_cow_object->_lock_mutex);
|
|
|
+ _cow_object->_lock_mutex.acquire();
|
|
|
while (_cow_object->_lock_status == CopyOnWriteObject::LS_locked_write &&
|
|
|
_cow_object->_locking_thread != current_thread) {
|
|
|
if (util_cat.is_debug()) {
|
|
|
@@ -89,10 +88,20 @@ get_write_pointer() {
|
|
|
<< "Making copy of " << _cow_object->get_type()
|
|
|
<< " because it is locked in read mode.\n";
|
|
|
}
|
|
|
+
|
|
|
PT(CopyOnWriteObject) new_object = _cow_object->make_cow_copy();
|
|
|
- cache_unref_delete(_cow_object);
|
|
|
+
|
|
|
+ // We can't call cache_unref_delete, because we hold the lock.
|
|
|
+ if (!_cow_object->CachedTypedWritableReferenceCount::cache_unref()) {
|
|
|
+ _cow_object->_lock_mutex.release();
|
|
|
+ delete _cow_object;
|
|
|
+ } else {
|
|
|
+ _cow_object->_lock_mutex.release();
|
|
|
+ }
|
|
|
_cow_object = new_object;
|
|
|
_cow_object->cache_ref();
|
|
|
+ _cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
|
|
|
+ _cow_object->_locking_thread = current_thread;
|
|
|
|
|
|
} else if (_cow_object->get_cache_ref_count() > 1) {
|
|
|
// No one else has it specifically read-locked, but there are other
|
|
|
@@ -106,9 +115,18 @@ get_write_pointer() {
|
|
|
}
|
|
|
|
|
|
PT(CopyOnWriteObject) new_object = _cow_object->make_cow_copy();
|
|
|
- cache_unref_delete(_cow_object);
|
|
|
+
|
|
|
+ // We can't call cache_unref_delete, because we hold the lock.
|
|
|
+ if (!_cow_object->CachedTypedWritableReferenceCount::cache_unref()) {
|
|
|
+ _cow_object->_lock_mutex.release();
|
|
|
+ delete _cow_object;
|
|
|
+ } else {
|
|
|
+ _cow_object->_lock_mutex.release();
|
|
|
+ }
|
|
|
_cow_object = new_object;
|
|
|
_cow_object->cache_ref();
|
|
|
+ _cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
|
|
|
+ _cow_object->_locking_thread = current_thread;
|
|
|
|
|
|
} else {
|
|
|
// No other thread has the pointer locked, and we're the only
|
|
|
@@ -118,9 +136,10 @@ get_write_pointer() {
|
|
|
// We can't assert that there are no outstanding ordinary references to
|
|
|
// it, though, since the creator of the object might have saved himself a
|
|
|
// reference.
|
|
|
+ _cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
|
|
|
+ _cow_object->_locking_thread = current_thread;
|
|
|
+ _cow_object->_lock_mutex.release();
|
|
|
}
|
|
|
- _cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
|
|
|
- _cow_object->_locking_thread = current_thread;
|
|
|
|
|
|
return _cow_object;
|
|
|
}
|