File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed
stdlib/public/Synchronization Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,6 @@ set(SWIFT_SYNCHRONIZATION_SOURCES
2626 ${SWIFT_SYNCHRONIZATION_ATOMIC_SOURCES}
2727
2828 Cell.swift
29- Mutex/Mutex.swift
3029)
3130
3231set (SWIFT_SYNCHRONIZATION_GYB_SOURCES
@@ -38,24 +37,28 @@ set(SWIFT_SYNCHRONIZATION_GYB_SOURCES
3837
3938set (SWIFT_SYNCHRONIZATION_DARWIN_SOURCES
4039 Mutex/DarwinImpl.swift
40+ Mutex/Mutex.swift
4141)
4242
4343# Linux and Android sources
4444
4545set (SWIFT_SYNCHRONIZATION_LINUX_SOURCES
4646 Mutex/LinuxImpl.swift
47+ Mutex/Mutex.swift
4748 Mutex/SpinLoopHint.swift
4849)
4950
5051# Wasm sources
5152
5253set (SWIFT_SYNCHRONIZATION_WASM_SOURCES
54+ Mutex/Mutex.swift
5355 Mutex/WasmImpl.swift
5456)
5557
5658# Windows sources
5759
5860set (SWIFT_SYNCHRONIZATION_WINDOWS_SOURCES
61+ Mutex/Mutex.swift
5962 Mutex/WindowsImpl.swift
6063)
6164
@@ -89,6 +92,8 @@ add_swift_target_library(swiftSynchronization ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES
8992 ${SWIFT_SYNCHRONIZATION_WASM_SOURCES}
9093 SWIFT_SOURCES_DEPENDS_WINDOWS
9194 ${SWIFT_SYNCHRONIZATION_WINDOWS_SOURCES}
95+ SWIFT_SOURCES_DEPENDS_FREESTANDING
96+ Mutex/MutexUnavailable.swift
9297
9398 SWIFT_MODULE_DEPENDS_OSX
9499 Darwin
Original file line number Diff line number Diff line change 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 { }
You can’t perform that action at this time.
0 commit comments