Coroutines realtime support

This commit is contained in:
Rokas Kupstys 2017-02-17 16:49:17 +02:00
commit d69b701dde

View file

@ -67,6 +67,8 @@ type
prev: ptr GcStack prev: ptr GcStack
next: ptr GcStack next: ptr GcStack
bottom: pointer bottom: pointer
when withRealTime:
bottomSaved: pointer
pos: pointer pos: pointer
maxStackSize: int maxStackSize: int
@ -929,19 +931,40 @@ when withRealTime:
collectCTBody(gch) collectCTBody(gch)
release(gch) release(gch)
proc GC_step*(us: int, strongAdvice = false, stackSize = -1) {.noinline.} = when defined(nimCoroutines):
var stackTop {.volatile.}: pointer proc GC_step*(us: int, strongAdvice = false, stackSize = -1) {.noinline.} =
let prevStackBottom = gch.stackBottom if stackSize >= 0:
if stackSize >= 0: var stackTop {.volatile.}: pointer
stackTop = addr(stackTop) gch.activeStack.pos = addr(stackTop)
when stackIncreases:
gch.stackBottom = cast[pointer]( for stack in gch.stack.items():
cast[ByteAddress](stackTop) - sizeof(pointer) * 6 - stackSize) stack.bottomSaved = stack.bottom
else: when stackIncreases:
gch.stackBottom = cast[pointer]( stack.bottom = cast[pointer](
cast[ByteAddress](stackTop) + sizeof(pointer) * 6 + stackSize) cast[ByteAddress](stack.pos) - sizeof(pointer) * 6 - stackSize)
GC_step(gch, us, strongAdvice) else:
gch.stackBottom = prevStackBottom stack.bottom = cast[pointer](
cast[ByteAddress](stack.pos) + sizeof(pointer) * 6 + stackSize)
GC_step(gch, us, strongAdvice)
if stackSize >= 0:
for stack in gch.stack.items():
stack.bottom = stack.bottomSaved
else:
proc GC_step*(us: int, strongAdvice = false, stackSize = -1) {.noinline.} =
var stackTop {.volatile.}: pointer
let prevStackBottom = gch.stackBottom
if stackSize >= 0:
stackTop = addr(stackTop)
when stackIncreases:
gch.stackBottom = cast[pointer](
cast[ByteAddress](stackTop) - sizeof(pointer) * 6 - stackSize)
else:
gch.stackBottom = cast[pointer](
cast[ByteAddress](stackTop) + sizeof(pointer) * 6 + stackSize)
GC_step(gch, us, strongAdvice)
gch.stackBottom = prevStackBottom
when not defined(useNimRtl): when not defined(useNimRtl):
proc GC_disable() = proc GC_disable() =