shared untraced heap; bugfix: mem corruptions in message passing code

This commit is contained in:
Araq 2011-07-18 23:59:39 +02:00
commit 81a917390b
8 changed files with 151 additions and 87 deletions

View file

@ -47,9 +47,9 @@ proc contains(s: TCellSeq, c: PCell): bool {.inline.} =
proc add(s: var TCellSeq, c: PCell) {.inline.} =
if s.len >= s.cap:
s.cap = s.cap * 3 div 2
var d = cast[PCellArray](unlockedAlloc(s.cap * sizeof(PCell)))
var d = cast[PCellArray](Alloc(s.cap * sizeof(PCell)))
copyMem(d, s.d, s.len * sizeof(PCell))
unlockedDealloc(s.d)
Dealloc(s.d)
s.d = d
# XXX: realloc?
s.d[s.len] = c
@ -58,10 +58,10 @@ proc add(s: var TCellSeq, c: PCell) {.inline.} =
proc init(s: var TCellSeq, cap: int = 1024) =
s.len = 0
s.cap = cap
s.d = cast[PCellArray](unlockedAlloc0(cap * sizeof(PCell)))
s.d = cast[PCellArray](Alloc0(cap * sizeof(PCell)))
proc deinit(s: var TCellSeq) =
unlockedDealloc(s.d)
Dealloc(s.d)
s.d = nil
s.len = 0
s.cap = 0
@ -70,7 +70,7 @@ const
InitCellSetSize = 1024 # must be a power of two!
proc Init(s: var TCellSet) =
s.data = cast[PPageDescArray](unlockedAlloc0(InitCellSetSize * sizeof(PPageDesc)))
s.data = cast[PPageDescArray](Alloc0(InitCellSetSize * sizeof(PPageDesc)))
s.max = InitCellSetSize-1
s.counter = 0
s.head = nil
@ -79,10 +79,10 @@ proc Deinit(s: var TCellSet) =
var it = s.head
while it != nil:
var n = it.next
unlockedDealloc(it)
Dealloc(it)
it = n
s.head = nil # play it safe here
unlockedDealloc(s.data)
Dealloc(s.data)
s.data = nil
s.counter = 0
@ -110,11 +110,11 @@ proc CellSetRawInsert(t: TCellSet, data: PPageDescArray, desc: PPageDesc) =
proc CellSetEnlarge(t: var TCellSet) =
var oldMax = t.max
t.max = ((t.max+1)*2)-1
var n = cast[PPageDescArray](unlockedAlloc0((t.max + 1) * sizeof(PPageDesc)))
var n = cast[PPageDescArray](Alloc0((t.max + 1) * sizeof(PPageDesc)))
for i in 0 .. oldmax:
if t.data[i] != nil:
CellSetRawInsert(t, n, t.data[i])
unlockedDealloc(t.data)
Dealloc(t.data)
t.data = n
proc CellSetPut(t: var TCellSet, key: TAddress): PPageDesc =
@ -132,7 +132,7 @@ proc CellSetPut(t: var TCellSet, key: TAddress): PPageDesc =
while t.data[h] != nil: h = nextTry(h, t.max)
sysAssert(t.data[h] == nil)
# the new page descriptor goes into result
result = cast[PPageDesc](unlockedAlloc0(sizeof(TPageDesc)))
result = cast[PPageDesc](Alloc0(sizeof(TPageDesc)))
result.next = t.head
result.key = key
t.head = result