ARC: default to a shared heap with --threads:on
This commit is contained in:
parent
bafb4f119c
commit
5aa7b1a44b
3 changed files with 15 additions and 5 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -67,6 +67,8 @@ proc nimNewObj(size: int): pointer {.compilerRtl.} =
|
|||
var orig = c_malloc(cuint s)
|
||||
nimZeroMem(orig, s)
|
||||
result = orig +! sizeof(RefHeader)
|
||||
elif compileOption("threads"):
|
||||
result = allocShared0(s) +! sizeof(RefHeader)
|
||||
else:
|
||||
result = alloc0(s) +! sizeof(RefHeader)
|
||||
when hasThreadSupport:
|
||||
|
|
@ -93,6 +95,8 @@ proc nimRawDispose(p: pointer) {.compilerRtl.} =
|
|||
quit 1
|
||||
when defined(useMalloc):
|
||||
c_free(p -! sizeof(RefHeader))
|
||||
elif compileOption("threads"):
|
||||
deallocShared(p -! sizeof(RefHeader))
|
||||
else:
|
||||
dealloc(p -! sizeof(RefHeader))
|
||||
if allocs > 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue