Arm the guard for one extraction on the calling thread: clear the latch and (re)compute the threshold. OS bounds are computed once per thread; the fallback budget is re-anchored at every call's entry stack pointer.
()
| 124 | /// and (re)compute the threshold. OS bounds are computed once per thread; |
| 125 | /// the fallback budget is re-anchored at every call's entry stack pointer. |
| 126 | pub fn begin() { |
| 127 | OVERFLOWED.with(|o| o.set(false)); |
| 128 | let cached = THRESHOLD.with(|t| t.get()); |
| 129 | if cached != 0 && THRESHOLD_IS_OS.with(|f| f.get()) { |
| 130 | return; |
| 131 | } |
| 132 | match os_stack_low() { |
| 133 | Some(low) => { |
| 134 | THRESHOLD.with(|t| t.set(low.saturating_add(RED_ZONE))); |
| 135 | THRESHOLD_IS_OS.with(|f| f.set(true)); |
| 136 | } |
| 137 | None => { |
| 138 | THRESHOLD.with(|t| t.set(current_sp().saturating_sub(FALLBACK_BUDGET).max(1))); |
| 139 | THRESHOLD_IS_OS.with(|f| f.set(false)); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /// `true` once the walker has descended to within `RED_ZONE` of the stack |
| 145 | /// limit. Latches `OVERFLOWED` so `run_guarded` can discard the result. A |
no test coverage detected