MCPcopy Create free account
hub / github.com/NthTensor/Forte / wait_for

Method wait_for

src/thread_pool.rs:1358–1373  ·  view source on GitHub ↗
(&self, latch: &Latch)

Source from the content-addressed store, hash-verified

1356 {
1357 let worker_ptr = WORKER_PTR.with(Cell::get);
1358 if !worker_ptr.is_null() {
1359 // SAFETY: `WORKER_PTR` is a thread-local `Cell` holding a raw
1360 // pointer to a `Worker`. It is only written to by
1361 // `Membership::activate`, which stores the address of a `Worker`
1362 // allocated within its own stack frame. Before it returns,
1363 // `activate` restores the previous value of `WORKER_PTR` (and it
1364 // aborts on panic, so this reset is guaranteed to occur). So the
1365 // `WORKER_PTR` is either null or a pointer to a live, immovable
1366 // `Worker`
1367 //
1368 // If the pointer is non-null, it is therefore sound to dereference
1369 // as a shared reference. Forming a `'static` reference is avoided
1370 // by passing the value into a closure, which bounds the reference's
1371 // lifetime to the closure body and prevents callers from retaining
1372 // it past the point where `activate` returns and the `Worker` is
1373 // freed.
1374 f(Some(unsafe { &*worker_ptr }))
1375 } else {
1376 f(None)

Callers 4

block_onMethod · 0.80
joinMethod · 0.80
broadcastMethod · 0.80
completeMethod · 0.80

Calls 3

checkMethod · 0.80
yield_nowMethod · 0.80
waitMethod · 0.45

Tested by

no test coverage detected