@@ -99,19 +99,17 @@ get_write_pointer() {
99
99
}
100
100
101
101
PT (CopyOnWriteObject) new_object = _cow_object->make_cow_copy ();
102
+ _cow_object->CachedTypedWritableReferenceCount ::cache_unref ();
103
+ _cow_object->_lock_mutex .release ();
102
104
103
- // We can't call cache_unref_delete, because we hold the lock.
104
- if (!_cow_object->CachedTypedWritableReferenceCount ::cache_unref ()) {
105
- _cow_object->_lock_mutex .release ();
106
- delete _cow_object;
107
- } else {
108
- _cow_object->_lock_mutex .release ();
109
- }
105
+ MutexHolder holder (new_object->_lock_mutex );
110
106
_cow_object = new_object;
111
- _cow_object->cache_ref ();
107
+ _cow_object->CachedTypedWritableReferenceCount :: cache_ref ();
112
108
_cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
113
109
_cow_object->_locking_thread = current_thread;
114
110
111
+ return new_object;
112
+
115
113
} else if (_cow_object->get_cache_ref_count () > 1 ) {
116
114
// No one else has it specifically read-locked, but there are
117
115
// other CopyOnWritePointers holding the same object, so we should
@@ -124,19 +122,17 @@ get_write_pointer() {
124
122
}
125
123
126
124
PT (CopyOnWriteObject) new_object = _cow_object->make_cow_copy ();
125
+ _cow_object->CachedTypedWritableReferenceCount ::cache_unref ();
126
+ _cow_object->_lock_mutex .release ();
127
127
128
- // We can't call cache_unref_delete, because we hold the lock.
129
- if (!_cow_object->CachedTypedWritableReferenceCount ::cache_unref ()) {
130
- _cow_object->_lock_mutex .release ();
131
- delete _cow_object;
132
- } else {
133
- _cow_object->_lock_mutex .release ();
134
- }
128
+ MutexHolder holder (new_object->_lock_mutex );
135
129
_cow_object = new_object;
136
- _cow_object->cache_ref ();
130
+ _cow_object->CachedTypedWritableReferenceCount :: cache_ref ();
137
131
_cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
138
132
_cow_object->_locking_thread = current_thread;
139
133
134
+ return new_object;
135
+
140
136
} else {
141
137
// No other thread has the pointer locked, and we're the only
142
138
// CopyOnWritePointer with this object. We can safely write to it
0 commit comments