summary refs log tree commit diff stats
path: root/lib/system/allocators.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/system/allocators.nim')
-rw-r--r--lib/system/allocators.nim6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/system/allocators.nim b/lib/system/allocators.nim
index 43aae0111..e642999a8 100644
--- a/lib/system/allocators.nim
+++ b/lib/system/allocators.nim
@@ -46,18 +46,24 @@ proc getLocalAllocator*(): Allocator =
         result = c_malloc(cuint size)
         # XXX do we need this?
         nimZeroMem(result, size)
+      elif compileOption("threads"):
+        result = system.allocShared0(size)
       else:
         result = system.alloc0(size)
       inc a.allocCount
     result.dealloc = proc (a: Allocator; p: pointer; size: int) {.nimcall, raises: [].} =
       when defined(useMalloc) and not defined(nimscript):
         c_free(p)
+      elif compileOption("threads"):
+        system.deallocShared(p)
       else:
         system.dealloc(p)
       inc a.deallocCount
     result.realloc = proc (a: Allocator; p: pointer; oldSize, newSize: int): pointer {.nimcall, raises: [].} =
       when defined(useMalloc) and not defined(nimscript):
         result = c_realloc(p, cuint newSize)
+      elif compileOption("threads"):
+        result = system.reallocShared(p, newSize)
       else:
         result = system.realloc(p, newSize)
       nimZeroMem(result +! oldSize, newSize - oldSize)