| 1 | // a worker keeps running V after fork; its collector must forget vanished threads. |
| 2 | module engine |
| 3 | |
| 4 | $if gcboehm ? { |
| 5 | #include <gc/gc.h> |
| 6 | } |
| 7 | |
| 8 | fn C.GC_atfork_prepare() |
| 9 | fn C.GC_atfork_parent() |
| 10 | fn C.GC_atfork_child() |
| 11 | |
| 12 | fn fork_process() i32 { |
| 13 | // libgc documents these as no-ops when pthread_atfork handles the collector. |
| 14 | // explicit calls also support V builds whose collector has no automatic hooks. |
| 15 | $if gcboehm ? { |
| 16 | C.GC_atfork_prepare() |
| 17 | } |
| 18 | child := C.fork() |
| 19 | failure := if child < 0 { C.errno } else { 0 } |
| 20 | $if gcboehm ? { |
| 21 | if child == 0 { C.GC_atfork_child() } else { C.GC_atfork_parent() } |
| 22 | } |
| 23 | if child < 0 { C.errno = failure } |
| 24 | return child |
| 25 | } |
| 26 | |