summary refs log tree commit diff stats
path: root/lib/core
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-10-30 16:15:17 +0100
committerGitHub <noreply@github.com>2019-10-30 16:15:17 +0100
commit1746da2d9e3d802d990d9636d2f6887a4aeb5dc9 (patch)
tree687727e8d4b858eb74db2e07a1a778cff58a7bdd /lib/core
parentb5bb58164270a819cfb37655139251955541a964 (diff)
downloadNim-1746da2d9e3d802d990d9636d2f6887a4aeb5dc9.tar.gz
--gc:destructors now means Nim uses pure refcounting (#12557)
Diffstat (limited to 'lib/core')
-rw-r--r--lib/core/runtime_v2.nim22
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/core/runtime_v2.nim b/lib/core/runtime_v2.nim
index 5c9554ad8..fe4bf37bf 100644
--- a/lib/core/runtime_v2.nim
+++ b/lib/core/runtime_v2.nim
@@ -57,13 +57,13 @@ proc nimNewObj(size: int): pointer {.compilerRtl.} =
   else:
     inc allocs
 
-proc nimDecWeakRef(p: pointer) {.compilerRtl.} =
+proc nimDecWeakRef(p: pointer) {.compilerRtl, inl.} =
   when hasThreadSupport:
     atomicDec head(p).rc
   else:
     dec head(p).rc
 
-proc nimIncWeakRef(p: pointer) {.compilerRtl.} =
+proc nimIncRef(p: pointer) {.compilerRtl, inl.} =
   when hasThreadSupport:
     atomicInc head(p).rc
   else:
@@ -106,11 +106,25 @@ proc nimDestroyAndDispose(p: pointer) {.compilerRtl.} =
       cstderr.rawWrite "has destructor!\n"
   nimRawDispose(p)
 
-proc isObj(obj: PNimType, subclass: cstring): bool {.compilerproc.} =
+proc nimDecRefIsLast(p: pointer): bool {.compilerRtl, inl.} =
+  if p != nil:
+    when hasThreadSupport:
+      if atomicLoadN(addr head(p).rc, ATOMIC_RELAXED) == 0:
+        result = true
+      else:
+        if atomicDec(head(p).rc) <= 0:
+          result = true
+    else:
+      if head(p).rc == 0:
+        result = true
+      else:
+        dec head(p).rc
+
+proc isObj(obj: PNimType, subclass: cstring): bool {.compilerRtl, inl.} =
   proc strstr(s, sub: cstring): cstring {.header: "<string.h>", importc.}
 
   result = strstr(obj.name, subclass) != nil
 
-proc chckObj(obj: PNimType, subclass: cstring) {.compilerproc.} =
+proc chckObj(obj: PNimType, subclass: cstring) {.compilerRtl.} =
   # checks if obj is of type subclass:
   if not isObj(obj, subclass): sysFatal(ObjectConversionError, "invalid object conversion")