(stw: &super::StopTheWorldState)
| 245 | /// (like `_PyThreadState_Suspend` + `_PyThreadState_Attach`). |
| 246 | #[cfg(all(unix, feature = "threading"))] |
| 247 | pub 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] |
no test coverage detected