MCPcopy Index your code
hub / github.com/RustPython/RustPython / suspend_if_needed

Function suspend_if_needed

crates/vm/src/vm/thread.rs:247–267  ·  view source on GitHub ↗
(stw: &super::StopTheWorldState)

Source from the content-addressed store, hash-verified

245/// (like `_PyThreadState_Suspend` + `_PyThreadState_Attach`).
246#[cfg(all(unix, feature = "threading"))]
247pub fn suspend_if_needed(stw: &super::StopTheWorldState) {
248 let should_suspend = CURRENT_THREAD_SLOT.with(|slot| {
249 slot.borrow()
250 .as_ref()
251 .is_some_and(|s| s.stop_requested.load(Ordering::Relaxed))
252 });
253 if !should_suspend {
254 return;
255 }
256
257 if !stw.requested.load(Ordering::Acquire) {
258 CURRENT_THREAD_SLOT.with(|slot| {
259 if let Some(s) = slot.borrow().as_ref() {
260 s.stop_requested.store(false, Ordering::Release);
261 }
262 });
263 return;
264 }
265
266 do_suspend(stw);
267}
268
269#[cfg(all(unix, feature = "threading"))]
270#[cold]

Callers 1

check_signalsMethod · 0.85

Calls 6

do_suspendFunction · 0.85
withMethod · 0.80
as_refMethod · 0.45
borrowMethod · 0.45
loadMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected