File tree 2 files changed +23
-0
lines changed 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,10 @@ void cont_yield(cont_t*);
60
60
// return 1 if guard bytes were overwritten.
61
61
int cont_check (cont_t * cont );
62
62
63
+ // Go through stack and check how many bytes are most probably still unchanged
64
+ // and thus weren't used by the user code. i.e. that stack space is free. (high water mark)
65
+ int cont_get_free_stack (cont_t * cont );
66
+
63
67
// Check if yield() may be called. Returns true if we are running inside
64
68
// continuation stack
65
69
bool cont_can_yield (cont_t * cont );
Original file line number Diff line number Diff line change @@ -30,6 +30,12 @@ void ICACHE_RAM_ATTR cont_init(cont_t* cont) {
30
30
cont -> stack_guard2 = CONT_STACKGUARD ;
31
31
cont -> stack_end = cont -> stack + (sizeof (cont -> stack ) / 4 );
32
32
cont -> struct_start = (unsigned * ) cont ;
33
+
34
+ // fill stack with magic values to check high water mark
35
+ for (int pos = 0 ; pos < sizeof (cont -> stack ) / 4 ; pos ++ )
36
+ {
37
+ cont -> stack [pos ] = CONT_STACKGUARD ;
38
+ }
33
39
}
34
40
35
41
int ICACHE_RAM_ATTR cont_check (cont_t * cont ) {
@@ -38,6 +44,19 @@ int ICACHE_RAM_ATTR cont_check(cont_t* cont) {
38
44
return 0 ;
39
45
}
40
46
47
+ int ICACHE_RAM_ATTR cont_get_free_stack (cont_t * cont ) {
48
+ uint32_t * head = cont -> stack ;
49
+ int freeWords = 0 ;
50
+
51
+ while (* head == CONT_STACKGUARD )
52
+ {
53
+ head ++ ;
54
+ freeWords ++ ;
55
+ }
56
+
57
+ return freeWords * 4 ;
58
+ }
59
+
41
60
bool ICACHE_RAM_ATTR cont_can_yield (cont_t * cont ) {
42
61
return !ETS_INTR_WITHINISR () &&
43
62
cont -> pc_ret != 0 && cont -> pc_yield == 0 ;
You can’t perform that action at this time.
0 commit comments