mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-05 04:27:44 +00:00
atomic loads do not require a mutable location [backport]
This commit is contained in:
@@ -98,7 +98,7 @@ when defined(cpp) or defined(nimdoc):
|
||||
|
||||
# Access operations
|
||||
|
||||
proc load*[T](location: var Atomic[T]; order: MemoryOrder = moSequentiallyConsistent): T {.importcpp: "#.load(@)".}
|
||||
proc load*[T](location: Atomic[T]; order: MemoryOrder = moSequentiallyConsistent): T {.importcpp: "#.load(@)".}
|
||||
## Atomically obtains the value of the atomic object.
|
||||
|
||||
proc store*[T](location: var Atomic[T]; desired: T; order: MemoryOrder = moSequentiallyConsistent) {.importcpp: "#.store(@)".}
|
||||
@@ -245,7 +245,7 @@ else:
|
||||
proc clear*(location: var AtomicFlag; order: MemoryOrder = moSequentiallyConsistent) =
|
||||
discard interlockedAnd(addr(location), 0'i8)
|
||||
|
||||
proc load*[T: Trivial](location: var Atomic[T]; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} =
|
||||
proc load*[T: Trivial](location: Atomic[T]; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} =
|
||||
cast[T](interlockedOr(addr(location.value), (nonAtomicType(T))0))
|
||||
proc store*[T: Trivial](location: var Atomic[T]; desired: T; order: MemoryOrder = moSequentiallyConsistent) {.inline.} =
|
||||
discard interlockedExchange(addr(location.value), cast[nonAtomicType(T)](desired))
|
||||
@@ -332,7 +332,7 @@ else:
|
||||
|
||||
{.pop.}
|
||||
|
||||
proc load*[T: Trivial](location: var Atomic[T]; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} =
|
||||
proc load*[T: Trivial](location: Atomic[T]; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} =
|
||||
cast[T](atomic_load_explicit[nonAtomicType(T), typeof(location.value)](addr(location.value), order))
|
||||
proc store*[T: Trivial](location: var Atomic[T]; desired: T; order: MemoryOrder = moSequentiallyConsistent) {.inline.} =
|
||||
atomic_store_explicit(addr(location.value), cast[nonAtomicType(T)](desired), order)
|
||||
@@ -367,7 +367,7 @@ else:
|
||||
finally:
|
||||
clear(location.guard, moRelease)
|
||||
|
||||
proc load*[T: not Trivial](location: var Atomic[T]; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} =
|
||||
proc load*[T: not Trivial](location: Atomic[T]; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} =
|
||||
withLock(location, order):
|
||||
result = location.nonAtomicValue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user