From 5385798838983ece7510f5c8ad9993cee3a0386c Mon Sep 17 00:00:00 2001 From: Hans Raaf Date: Wed, 25 May 2016 02:23:44 +0200 Subject: Made nimphpext work with gc:stack. --- lib/system/gc_stack.nim | 20 +++++++++++++++++++- lib/system/threads.nim | 4 ++-- 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: -- cgit 1.4.1-2-gfad0 t&id=fa0e67c172ec110ebd419f34506ff0dfaad02042'>baremetal/403unicode.mu
blob: ea45f707ccf3d6bfc99162a66e5e81dfa8f3d0c7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193