Skip to content

macOS: add ThreadSupport (no-op suspend/resume)#3036

Open
tomjn wants to merge 1 commit into
beyond-all-reason:masterfrom
tomjn:mac/threadsupport-stub
Open

macOS: add ThreadSupport (no-op suspend/resume)#3036
tomjn wants to merge 1 commit into
beyond-all-reason:masterfrom
tomjn:mac/threadsupport-stub

Conversation

@tomjn

@tomjn tomjn commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

What

Adds rts/System/Platform/Mac/ThreadSupport.cpp and wires it into the Mac threading sources.

The Linux ThreadSupport suspends/resumes threads via a SIGUSR1 signal handler plus getcontext()/ucontext_t — none of which has a portable macOS equivalent. This macOS version provides:

  • Suspend() / Resume() as no-ops (macOS has no signal-based thread suspend).
  • ThreadStart / SetupCurrentThreadControls — the thread setup/start plumbing (create the ThreadControls, record pthread_self(), signal initialization, run the task).

QoS / performance cores

Deliberately not handled here. Performance-core preference is a QoS hint applied in Threading::SetAffinity() (see the macOS affinity change), which the main and worker threads already reach via SetAffinityHelper() (ThreadPool.cpp). Keeping it in one place avoids applying the QoS class twice.

CMake

On APPLE, sources_engine_System_Platform_Mac previously pulled in Platform/Linux/ThreadSupport.cpp — which doesn't compile on macOS (it uses SYS_gettid/sigaction/ucontext). This swaps that out: the new Mac/ThreadSupport.cpp is added to sources_engine_System_Threading_Mac, and the Linux file is dropped from sources_engine_System_Platform_Mac (otherwise both would compile on APPLE → duplicate symbols).

Cross-platform safety

Mac-only: the only lists touched are the *_Mac ones, used solely under if(APPLE). Windows and Linux builds are byte-for-byte unaffected.

Adapted from the macOS bring-up (#2991) as a standalone, reviewable piece (minus the QoS, which lives with the affinity change).

Note: macOS isn't in CI yet, so this is verified by inspection, not a build. It's part of standing up the headless unitsync build on Apple Silicon.

Comment thread rts/System/Platform/Mac/ThreadSupport.cpp Outdated
The Linux ThreadSupport suspends/resumes threads via a SIGUSR1 handler
plus getcontext()/ucontext_t, which has no portable macOS equivalent. Add
a macOS ThreadSupport.cpp providing no-op Suspend()/Resume() and the
thread setup/start plumbing, and wire it into the Mac threading sources.

Performance-core preference is handled separately as a QoS hint in
Threading::SetAffinity (the main and worker threads reach it via
SetAffinityHelper), so it is not duplicated here.

Mac-only: the file is in sources_engine_System_Threading_Mac, so Windows
and Linux builds are unaffected.
@tomjn tomjn force-pushed the mac/threadsupport-stub branch from c5a6ff0 to 9d51525 Compare June 20, 2026 15:10
@sprunk sprunk added the big mac Part of the big push to support Mac. label Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

big mac Part of the big push to support Mac.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants