Skip to content

Commit

Permalink
Merge pull request #13 from planetis-m/patch-3
Browse files Browse the repository at this point in the history
fix atomics memory ordering for sharedptr
  • Loading branch information
Araq authored Dec 11, 2021
2 parents e6c5365 + 3f605ce commit c966e77
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions threading/smartptrs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ type

proc `=destroy`*[T](p: var SharedPtr[T]) =
if p.val != nil:
if p.val[].counter.load(Consume) == 0:
if p.val[].counter.load(Acquire) == 0:
`=destroy`(p.val[])
deallocShared(p.val)
else:
atomicDec(p.val[].counter)
discard fetchSub(p.val[].counter, 1, Release)

proc `=copy`*[T](dest: var SharedPtr[T], src: SharedPtr[T]) =
if src.val != nil:
atomicInc(src.val[].counter)
discard fetchAdd(src.val[].counter, 1, Relaxed)
if dest.val != nil:
`=destroy`(dest)
dest.val = src.val
Expand Down

0 comments on commit c966e77

Please sign in to comment.