Skip to content

Commit c966e77

Browse files
authored
Merge pull request #13 from planetis-m/patch-3
fix atomics memory ordering for sharedptr
2 parents e6c5365 + 3f605ce commit c966e77

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: threading/smartptrs.nim

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ 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 p.val[].counter.load(Acquire) == 0:
8585
`=destroy`(p.val[])
8686
deallocShared(p.val)
8787
else:
88-
atomicDec(p.val[].counter)
88+
discard fetchSub(p.val[].counter, 1, Release)
8989

9090
proc `=copy`*[T](dest: var SharedPtr[T], src: SharedPtr[T]) =
9191
if src.val != nil:
92-
atomicInc(src.val[].counter)
92+
discard fetchAdd(src.val[].counter, 1, Relaxed)
9393
if dest.val != nil:
9494
`=destroy`(dest)
9595
dest.val = src.val

0 commit comments

Comments
 (0)