Skip to content

Commit 68fc921

Browse files
authored
fix atomics memory ordering for sharedptr
Consume was used in the original pr nim-lang/Nim#10485, haven't questioned before nim-lang/Nim#19212
1 parent 5fcec8b commit 68fc921

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

threading/smartptrs.nim

+2-4
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,13 @@ type
8181

8282
proc `=destroy`*[T](p: var SharedPtr[T]) =
8383
if p.val != nil:
84-
if p.val[].counter.load(Consume) == 0:
84+
if fetchSub(p.val[].counter, 1, AcqRel) == 0:
8585
`=destroy`(p.val[])
8686
deallocShared(p.val)
87-
else:
88-
atomicDec(p.val[].counter)
8987

9088
proc `=copy`*[T](dest: var SharedPtr[T], src: SharedPtr[T]) =
9189
if src.val != nil:
92-
atomicInc(src.val[].counter)
90+
discard fetchAdd(src.val[].counter, 1, Relaxed)
9391
if dest.val != nil:
9492
`=destroy`(dest)
9593
dest.val = src.val

0 commit comments

Comments
 (0)