Skip to content

Commit fcfbf06

Browse files
committed
Add a special file for mutex on unavailable platforms
1 parent bc0e6ab commit fcfbf06

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

stdlib/public/Synchronization/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ add_swift_target_library(swiftSynchronization ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES
9292
${SWIFT_SYNCHRONIZATION_WASM_SOURCES}
9393
SWIFT_SOURCES_DEPENDS_WINDOWS
9494
${SWIFT_SYNCHRONIZATION_WINDOWS_SOURCES}
95+
SWIFT_SOURCES_DEPENDS_FREESTANDING
96+
Mutex/MutexUnavailable.swift
9597

9698
SWIFT_MODULE_DEPENDS_OSX
9799
Darwin
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift Atomics open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
/// A synchronization primitive that protects shared mutable state via
14+
/// mutual exclusion.
15+
///
16+
/// The `Mutex` type offers non-recursive exclusive access to the state
17+
/// it is protecting by blocking threads attempting to acquire the lock.
18+
/// Only one execution context at a time has access to the value stored
19+
/// within the `Mutex` allowing for exclusive access.
20+
///
21+
/// An example use of `Mutex` in a class used simultaneously by many
22+
/// threads protecting a `Dictionary` value:
23+
///
24+
/// class Manager {
25+
/// let cache = Mutex<[Key: Resource]>([:])
26+
///
27+
/// func saveResouce(_ resource: Resouce, as key: Key) {
28+
/// cache.withLock {
29+
/// $0[key] = resource
30+
/// }
31+
/// }
32+
/// }
33+
///
34+
@available(unavailable, *, message: "Mutex is not available on this platform")
35+
@frozen
36+
@_staticExclusiveOnly
37+
public struct Mutex<Value: ~Copyable>: ~Copyable {}

0 commit comments

Comments
 (0)