summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorHans Raaf <hara@oderwat.de>2016-05-25 02:23:44 +0200
committerHans Raaf <hara@oderwat.de>2016-05-25 02:25:48 +0200
commit5385798838983ece7510f5c8ad9993cee3a0386c (patch)
tree73387e6f00255db170c236430d831a9a4d03b30b /lib
parentbcc91a319c7b638c3db2da6afe6bd2b06ebf7e0e (diff)
downloadNim-5385798838983ece7510f5c8ad9993cee3a0386c.tar.gz
Made nimphpext work with gc:stack.
Diffstat (limited to 'lib')
-rw-r--r--lib/system/gc_stack.nim20
-rw-r--r--lib/system/threads.nim4
2 files changed, 21 insertions, 3 deletions
diff --git a/lib/system/gc_stack.nim b/lib/system/gc_stack.nim
index c251a4d0b..37d19db89 100644
--- a/lib/system/gc_stack.nim
+++ b/lib/system/gc_stack.nim
@@ -8,7 +8,23 @@
 
 # "Stack GC" for embedded devices or ultra performance requirements.
 
-include osalloc
+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
 
 # We manage memory as a thread local stack. Since the allocation pointer
 # is detached from the control flow pointer, this model is vastly more
@@ -100,6 +116,7 @@ proc allocSlowPath(r: var MemRegion; size: int) =
   fresh.size = s
   fresh.head = nil
   fresh.tail = nil
+  fresh.next = nil
   inc r.totalSize, s
   let old = r.tail
   if old == nil:
@@ -168,6 +185,7 @@ proc setObstackPtr*(r: var MemRegion; sp: StackPtr) =
 
 proc obstackPtr*(): StackPtr = tlRegion.obstackPtr()
 proc setObstackPtr*(sp: StackPtr) = tlRegion.setObstackPtr(sp)
+proc deallocAll*() = tlRegion.deallocAll()
 
 proc joinRegion*(dest: var MemRegion; src: MemRegion) =
   # merging is not hard.
diff --git a/lib/system/threads.nim b/lib/system/threads.nim
index bdb737e35..99927fbac 100644
--- a/lib/system/threads.nim
+++ b/lib/system/threads.nim
@@ -301,7 +301,7 @@ type
                                        ## a pointer as a thread ID.
 {.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()
 
 when defined(boehmgc):
@@ -331,7 +331,7 @@ else:
 proc threadProcWrapStackFrame[TArg](thrd: ptr Thread[TArg]) =
   when defined(boehmgc):
     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.} =
       threadProcWrapDispatch[TArg]
     when not hasSharedHeap: