File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -60,6 +60,10 @@ void cont_yield(cont_t*);
6060// return 1 if guard bytes were overwritten.
6161int cont_check (cont_t * cont );
6262
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+
6367// Check if yield() may be called. Returns true if we are running inside
6468// continuation stack
6569bool 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) {
3030 cont -> stack_guard2 = CONT_STACKGUARD ;
3131 cont -> stack_end = cont -> stack + (sizeof (cont -> stack ) / 4 );
3232 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+ }
3339}
3440
3541int ICACHE_RAM_ATTR cont_check (cont_t * cont ) {
@@ -38,6 +44,19 @@ int ICACHE_RAM_ATTR cont_check(cont_t* cont) {
3844 return 0 ;
3945}
4046
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+
4160bool ICACHE_RAM_ATTR cont_can_yield (cont_t * cont ) {
4261 return !ETS_INTR_WITHINISR () &&
4362 cont -> pc_ret != 0 && cont -> pc_yield == 0 ;
You can’t perform that action at this time.
0 commit comments