Files
swift-mirror/stdlib/public/stubs/Exclusivity/SingleThreaded.cpp
Doug Gregor b12ad088ce [Embeddded] Make _swift_(get|set)ExclusivityTLS platform-provided
Swift's dynamic exclusivity checking relies on two functions,
_swift_getExclusivityTLS and _swift_setExclusivityTLS, to properly
deal with multi-threaded contexts. In the non-Embedded standard
library, these are provided by the Swift runtime.

For Embedded Swift, we cannot rely on having thread-local storage.
Instead, require the platform to provide these two entrypoints. To
make things simpler, we offer two implementations one can link in:

- libswiftExclusivitySingleThreaded.a: single-threaded implementation
- libswiftExclusivityC11ThreadLocal.a: multi-threaded implementation that
uses C11 thread-locals

Embedded Swift programs using dynamic exclusivity can link in one of
these libraries, or can implement its own versions of these two
functions. A platform can choose to provide them if it has different
mechanisms for thread-local storage.

This makes dynamic exclusivity checking generally usable in Embedded
Swift, rdar://159115910.
2026-01-20 20:07:42 -08:00

32 lines
1.1 KiB
C++

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// Single-threaded implementation of dynamic exclusivity checking. This file
// should be linked in to single-threaded Embedded Swift applications that
// require dynamic exclusivity checking.
//===----------------------------------------------------------------------===//
#include "swift/shims/Visibility.h"
extern "C" {
void * _Nullable _swift_exclusivity_single_threaded;
SWIFT_RUNTIME_STDLIB_INTERNAL
void * _Nullable _swift_getExclusivityTLS() {
return _swift_exclusivity_single_threaded;
}
SWIFT_RUNTIME_STDLIB_INTERNAL
void _swift_setExclusivityTLS(void * _Nullable newValue) {
_swift_exclusivity_single_threaded = newValue;
}
}