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
//! Stage-worker support for fork-unsafe hosts (GUI applications).
//!
//! FEFF stages are isolated per process. On plain Unix processes that is
//! done with `fork()`; but a forked child of a process that has initialized
//! AppKit/Metal (any macOS GUI app embedding this library) aborts in the
//! Objective-C runtime before the stage can run. Running stages in-process
//! is not an alternative for multi-stage pipelines because FEFF's Fortran
//! modules keep allocated state between stages (e.g. `lrstat` in
//! m_stkets.f90), which only a fresh process resets.
//!
//! The solution mirrors the original FEFF design of one executable per
//! stage: re-exec the host executable as a single-stage worker. Hosts opt in
//! by calling [`init`] at the very top of `main()`, before any GUI
//! initialization:
//!
//! ```text
//! fn main() {
//! feff10::worker::init(); // never returns in worker processes
//! // ... GUI setup ...
//! }
//! ```
//!
//! With the hook installed, [`StageIsolation::Auto`](crate::config::StageIsolation)
//! transparently uses worker processes when the host is fork-unsafe.
use Path;
use ;
use crateStage;
/// Environment variable carrying the stage to run in a worker process.
pub const ENV_STAGE: &str = "FEFF10_WORKER_STAGE";
/// Environment variable carrying the working directory for the stage.
pub const ENV_DIR: &str = "FEFF10_WORKER_DIR";
static INSTALLED: AtomicBool = new;
/// Whether [`init`] has been called in this process.
/// Install the stage-worker hook. Call first thing in `main()`.
///
/// When the current process was spawned as a stage worker (the worker
/// environment variables are set), this runs that single stage and exits —
/// it never returns. Otherwise it records that the hook is installed (so
/// `StageIsolation::Auto` may use worker processes) and returns.