8 months ago |
37 |
1 |
#include <stdio.h> | ||
2 |
#include <stddef.h> | ||||
3 |
#include "coroutine.h" | ||||
4 |
#include "generator.h" | ||||
5 |
#include "asleep.h" | ||||
6 |
#include "task.h" | ||||
7 |
|||||
8 |
#include <dirent.h> | ||||
9 |
#include <string.h> | ||||
10 |
#include <stdlib.h> | ||||
11 |
#include <time.h> | ||||
12 |
|||||
5 months ago |
13 |
#define DEMO_STACK_SIZE (8192*sizeof(void *)) | |||
8 months ago |
37 |
14 |
|||
15 |
void *chaindeeper(void *param){ | ||||
16 |
// enough headroom for printf on an Intel Mac - your system may be different | ||||
17 |
if (Coroutine_GetStackHeadroom() < 2000){ | ||||
5 months ago |
18 |
void *result; | |||
5 months ago |
19 |
bool fail = Coroutine_Chain(DEMO_STACK_SIZE, chaindeeper, param, &result); | |||
5 months ago |
20 |
return fail ? NULL : result; | |||
8 months ago |
37 |
21 |
} | ||
7 months ago |
22 |
printf("%ld %ld\n", (long)param, Coroutine_GetStackHeadroom()); | |||
8 months ago |
37 |
23 |
long depth = (long)param; | ||
24 |
if (depth > 10000){ | ||||
25 |
return NULL; | ||||
26 |
} | ||||
27 |
return chaindeeper((void *)(depth + 1)); | ||||
28 |
} | ||||
29 |
|||||
30 |
|||||
31 |
void *chaintest( | ||||
32 |
void *param | ||||
33 |
){ | ||||
34 |
(void)param; | ||||
35 |
|||||
36 |
chaindeeper((void *)0); | ||||
37 |
|||||
38 |
return param; | ||||
39 |
} | ||||
40 |
|||||
41 |
|||||
42 |
int main(int argc, char *argv[]) { | ||||
43 |
(void)argc; | ||||
44 |
(void)argv; | ||||
45 |
|||||
46 |
Coroutine_StartSystem(); | ||||
5 months ago |
47 |
Coroutine_Run(DEMO_STACK_SIZE, chaintest, NULL, NULL); | |||
8 months ago |
37 |
48 |
Coroutine_Report report = Coroutine_StopSystem(); | ||
49 |
|||||
5 months ago |
50 |
printf("%d routines using a pool of %d, min headroom %zu\n", report.coroutines_created, report.coroutines_pool_size, report.lowest_headroom); | |||
8 months ago |
37 |
51 |
} | ||
52 |