Skip to content
This repository has been archived by the owner on Aug 29, 2022. It is now read-only.

Commit

Permalink
Use paired failure order during atomic lazy init
Browse files Browse the repository at this point in the history
  • Loading branch information
zwaldowski committed Mar 26, 2020
1 parent 66df0ae commit 869f871
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Sources/CAtomics/include/CAtomics.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ const void *_Nullable bnr_atomic_exchange(bnr_atomic_ptr_t target, const void *_
}

BNR_ATOMIC_INLINE BNR_ATOMIC_WARN_UNUSED_RESULT
bool bnr_atomic_compare_and_swap(bnr_atomic_ptr_t target, const void *_Nullable expected, const void *_Nullable desired, bnr_atomic_memory_order_t order) {
return atomic_compare_exchange_strong_explicit((const void *_Atomic *)target, &expected, desired, order, memory_order_relaxed);
bool bnr_atomic_compare_and_swap(bnr_atomic_ptr_t target, const void *_Nullable expected, const void *_Nullable desired, bnr_atomic_memory_order_t order, bnr_atomic_memory_order_t failureOrder) {
return atomic_compare_exchange_strong_explicit((const void *_Atomic *)target, &expected, desired, order, failureOrder);
}

BNR_ATOMIC_INLINE BNR_ATOMIC_WARN_UNUSED_RESULT
Expand Down
6 changes: 3 additions & 3 deletions Sources/Deferred/Atomics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ func bnr_atomic_exchange(_ target: bnr_atomic_ptr_t, _ desired: UnsafeRawPointer
return old
}

func bnr_atomic_compare_and_swap(_ target: bnr_atomic_ptr_t, _ expected: UnsafeRawPointer?, _ desired: UnsafeRawPointer?, _ order: bnr_atomic_memory_order_t) -> Bool {
func bnr_atomic_compare_and_swap(_ target: bnr_atomic_ptr_t, _ expected: UnsafeRawPointer?, _ desired: UnsafeRawPointer?, _ order: bnr_atomic_memory_order_t, _ failureOrder: bnr_atomic_memory_order_t) -> Bool {
var expected = expected
var desired = desired
return DarwinAtomics.shared.compareExchange(MemoryLayout<UnsafeRawPointer?>.size, target, &expected, &desired, order, .relaxed)
return DarwinAtomics.shared.compareExchange(MemoryLayout<UnsafeRawPointer?>.size, target, &expected, &desired, order, failureOrder)
}

func bnr_atomic_load_and_wait(_ target: bnr_atomic_ptr_t) -> UnsafeRawPointer {
Expand Down Expand Up @@ -119,7 +119,7 @@ func bnr_atomic_store<T: AnyObject>(_ target: UnsafeMutablePointer<T?>, _ desire
func bnr_atomic_initialize_once<T: AnyObject>(_ target: UnsafeMutablePointer<T?>, _ desired: T) -> Bool {
let rawTarget = UnsafeMutableRawPointer(target).assumingMemoryBound(to: UnsafeRawPointer?.self)
let retainedDesired = Unmanaged.passRetained(desired)
let wonRace = bnr_atomic_compare_and_swap(rawTarget, nil, retainedDesired.toOpaque(), .acq_rel)
let wonRace = bnr_atomic_compare_and_swap(rawTarget, nil, retainedDesired.toOpaque(), .acq_rel, .acquire)
if !wonRace {
retainedDesired.release()
}
Expand Down

0 comments on commit 869f871

Please sign in to comment.