File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -260,8 +260,16 @@ _dispatch_muxnote_retain(dispatch_muxnote_t dmn)
260260static void
261261_dispatch_muxnote_release (dispatch_muxnote_t dmn )
262262{
263- uintptr_t refcount = os_atomic_dec (& dmn -> dmn_refcount , relaxed );
263+ // We perform a minor optimization here - perform the decrement with
264+ // release semantics. In the case that we are going to dispose of the
265+ // value, we perform the acquire fence. This reduces the cost on the
266+ // normal path by avoiding the acquire fence. This should be more
267+ // beneficial on ARM64, as X64 being TSO'ed doesn't gain much. However,
268+ // `mfence` being isolated should hopefully be a bit more efficient than
269+ // the repeated `lock` if there is contention.
270+ uintptr_t refcount = os_atomic_dec (& dmn -> dmn_refcount , release );
264271 if (refcount == 0 ) {
272+ os_atomic_thread_fence (acquire );
265273 _dispatch_muxnote_dispose (dmn );
266274 } else if (refcount == UINTPTR_MAX ) {
267275 DISPATCH_INTERNAL_CRASH (0 , "muxnote refcount underflow" );
You can’t perform that action at this time.
0 commit comments