Merge pull request #4213 from oderwat/nimphpext-stack-gc

Made nimphpext work with gc:stack.
This commit is contained in:
Andreas Rumpf 2016-05-25 02:55:24 +02:00
commit ad70fb4ffe
2 changed files with 21 additions and 3 deletions

View file

@ -8,6 +8,22 @@
# "Stack GC" for embedded devices or ultra performance requirements. # "Stack GC" for embedded devices or ultra performance requirements.
when defined(nimphpext):
proc roundup(x, v: int): int {.inline.} =
result = (x + (v-1)) and not (v-1)
proc emalloc(size: int): pointer {.importc:"_emalloc".}
proc efree(mem: pointer) {.importc:"_efree".}
proc osAllocPages(size: int): pointer {.inline.} =
emalloc(size)
proc osTryAllocPages(size: int): pointer {.inline.} =
emalloc(size)
proc osDeallocPages(p: pointer, size: int) {.inline.} =
efree(p)
else:
include osalloc include osalloc
# We manage memory as a thread local stack. Since the allocation pointer # We manage memory as a thread local stack. Since the allocation pointer
@ -100,6 +116,7 @@ proc allocSlowPath(r: var MemRegion; size: int) =
fresh.size = s fresh.size = s
fresh.head = nil fresh.head = nil
fresh.tail = nil fresh.tail = nil
fresh.next = nil
inc r.totalSize, s inc r.totalSize, s
let old = r.tail let old = r.tail
if old == nil: if old == nil:
@ -168,6 +185,7 @@ proc setObstackPtr*(r: var MemRegion; sp: StackPtr) =
proc obstackPtr*(): StackPtr = tlRegion.obstackPtr() proc obstackPtr*(): StackPtr = tlRegion.obstackPtr()
proc setObstackPtr*(sp: StackPtr) = tlRegion.setObstackPtr(sp) proc setObstackPtr*(sp: StackPtr) = tlRegion.setObstackPtr(sp)
proc deallocAll*() = tlRegion.deallocAll()
proc joinRegion*(dest: var MemRegion; src: MemRegion) = proc joinRegion*(dest: var MemRegion; src: MemRegion) =
# merging is not hard. # merging is not hard.

View file

@ -301,7 +301,7 @@ type
## a pointer as a thread ID. ## a pointer as a thread ID.
{.deprecated: [TThread: Thread, TThreadId: ThreadId].} {.deprecated: [TThread: Thread, TThreadId: ThreadId].}
when not defined(boehmgc) and not hasSharedHeap and not defined(gogc): when not defined(boehmgc) and not hasSharedHeap and not defined(gogc) and not defined(gcstack):
proc deallocOsPages() proc deallocOsPages()
when defined(boehmgc): when defined(boehmgc):
@ -331,7 +331,7 @@ else:
proc threadProcWrapStackFrame[TArg](thrd: ptr Thread[TArg]) = proc threadProcWrapStackFrame[TArg](thrd: ptr Thread[TArg]) =
when defined(boehmgc): when defined(boehmgc):
boehmGC_call_with_stack_base(threadProcWrapDispatch[TArg], thrd) boehmGC_call_with_stack_base(threadProcWrapDispatch[TArg], thrd)
elif not defined(nogc) and not defined(gogc): elif not defined(nogc) and not defined(gogc) and not defined(gcstack):
var p {.volatile.}: proc(a: ptr Thread[TArg]) {.nimcall.} = var p {.volatile.}: proc(a: ptr Thread[TArg]) {.nimcall.} =
threadProcWrapDispatch[TArg] threadProcWrapDispatch[TArg]
when not hasSharedHeap: when not hasSharedHeap: