Skip to content

Commit

Permalink
add a note about the dispatch_once block
Browse files Browse the repository at this point in the history
Created using spr 1.3.4
  • Loading branch information
jroelofs committed Nov 29, 2023
1 parent ee558d7 commit 603983e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions compiler-rt/lib/builtins/cpu_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,14 @@ static bool isKnownAndSupported(const char *name) {
}

void __init_cpu_features_resolver(void) {
// On Darwin platforms, this may be called concurrently by multiple threads
// because the resolvers that use it are called lazily at runtime (unlike on
// ELF platforms, where IFuncs are resolved serially at load time). This
// function's effect on __aarch64_cpu_features should be idempotent, but even
// so we need dispatch_once to resolve the race condition. Dispatch is
// available through libSystem, which we need anyway for the sysctl, so this
// does not add a new dependency.

static dispatch_once_t onceToken = 0;
dispatch_once(&onceToken, ^{
// https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics
Expand Down

0 comments on commit 603983e

Please sign in to comment.