1 contributor
69 lines2.0 KB
Newer
Older
-
+
commited
{line.log.rev}
on
6 months ago
55
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 *))
6 months ago
55
14
15
Coroutine *cor_main;
16
17
typedef struct {
18
intptr_t headroom;
19
bool canstartcoroutine;
20
} TestResult;
21
22
23
void *stacktest(
24
void *param
25
){
26
TestResult *testresult = (TestResult *)param;
5 months ago
27
if (Coroutine_CanStartCoroutine(DEMO_STACK_SIZE)){
28
Coroutine *cor = Coroutine_New(DEMO_STACK_SIZE, stacktest);
6 months ago
55
29
Coroutine_Delete(cor);
30
}
31
testresult->headroom = Coroutine_GetStackHeadroom();
5 months ago
32
testresult->canstartcoroutine = Coroutine_CanStartCoroutine(DEMO_STACK_SIZE);
6 months ago
55
33
34
return NULL;
35
}
36
37
38
int main(int argc, char *argv[]) {
39
(void)argc;
40
(void)argv;
41
42
unsigned char *stack_now = (unsigned char *)&argc;
43
44
printf("Various stack headrooms:\n");
45
intptr_t limitnocoroutine;
46
TestResult testresult;
47
48
// what stack do we get with no stack limit set
49
Coroutine_StartSystem();
5 months ago
50
cor_main = Coroutine_New(DEMO_STACK_SIZE, stacktest);
6 months ago
55
51
limitnocoroutine = Coroutine_GetStackHeadroom();
52
Coroutine_Run_Coroutine(cor_main, &testresult);
53
Coroutine_Delete(cor_main);
54
printf("No stack limit: %ld %ld %d\n", limitnocoroutine, testresult.headroom, testresult.canstartcoroutine);
55
Coroutine_StopSystem();
56
57
// what stack do we get with an undersize stack limit
5 months ago
58
for (size_t stacksize = DEMO_STACK_SIZE/2; stacksize < DEMO_STACK_SIZE*4; stacksize += DEMO_STACK_SIZE/2){
6 months ago
55
59
Coroutine_StartSystem();
60
Coroutine_SetStackLimit(stack_now - stacksize);
5 months ago
61
cor_main = Coroutine_New(DEMO_STACK_SIZE, stacktest);
6 months ago
55
62
limitnocoroutine = Coroutine_GetStackHeadroom();
63
Coroutine_Run_Coroutine(cor_main, &testresult);
64
Coroutine_Delete(cor_main);
65
printf("Stack=%ld: %ld, %ld %d\n", stacksize, limitnocoroutine, testresult.headroom, testresult.canstartcoroutine);
66
Coroutine_StopSystem();
67
}
68
}
69