1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! `JobRef` — inline 16-byte task representation that replaces
//! `Box<dyn FnOnce>` as the pool's transport type.
//!
//! Rayon's `rayon-core::job::JobRef` is the pattern: a pair of
//! `(fn_ptr, data_ptr)` carrying a monomorphized trampoline plus an
//! opaque pointer to a caller-owned heap or stack cell. Copy-safe,
//! Send by assertion, 16 bytes on 64-bit targets. The old `Box<dyn
//! FnOnce>` costs one `Box::new` allocation per task; at ~1200 submits
//! per Siamese-tracker inference on 6T that's a non-trivial 50-100 µs
//! on the hot path plus the cache footprint of every Box allocation.
//!
//! Used by `YscvPool::install`, `YscvPool::join`, and
//! `YscvPool::par_for_each_index`. Each caller holds the backing
//! storage (a `StackJob<F>` or a `MultiJob<F>` in the par_for_each case)
//! on its own stack frame and passes `&raw` pointers through; the pool
//! type-erases them into `JobRef`.
//!
//! # Safety invariant
//!
//! `JobRef::execute` dereferences `data_ptr` and invokes `fn_ptr`. The
//! caller must guarantee the backing storage outlives every worker's
//! dereference. The public `YscvPool` APIs enforce this by blocking
//! the caller until every job has executed:
//!
//! - `install` blocks on the result channel recv.
//! - `join` blocks on the second-job channel recv.
//! - `par_for_each_index` spin-waits on the stack latch.
//!
//! All three paths hold the relevant stack cells alive for the full
//! lifetime of any worker's dereference, matching rayon's own
//! discipline.
/// Type-erased job descriptor used by the pool's injector and deques.
///
/// The `fn_ptr` is a static function item (no heap, no closure env),
/// and `data` points to caller-owned storage that the `fn_ptr`
/// re-interprets. See module docs for the lifetime contract.
pub
// SAFETY: `JobRef` carries raw pointers but the contract (caller-enforced
// via blocking) says the pointee outlives every dereference. The
// `fn_ptr` is a `fn` item, statically `'static`, always Send+Sync.
unsafe
unsafe