Skip to content

Commit a94db20

Browse files
authored
Merge pull request #6 from 0dminnimda/foolproof-init-and-finish
Foolproof coroutine_init and coroutine_finish
2 parents d4ab4a2 + 5b03266 commit a94db20

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

coroutine.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,14 @@ void coroutine_switch_context(void *rsp, Sleep_Mode sm, int fd)
200200

201201
void coroutine_init(void)
202202
{
203+
if (contexts.count != 0) return;
203204
da_append(&contexts, (Context){0});
204205
da_append(&active, 0);
205206
}
206207

207208
void coroutine_finish(void)
208209
{
210+
if (contexts.count == 0) return;
209211
if (active.items[current] == 0) {
210212
for (size_t i = 1; i < contexts.count; ++i) {
211213
munmap(contexts.items[i].stack_base, STACK_CAPACITY);

0 commit comments

Comments
 (0)