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
26
26
${SWIFT_SYNCHRONIZATION_ATOMIC_SOURCES}
27
27
28
28
Cell.swift
29
- Mutex/Mutex.swift
30
29
)
31
30
32
31
set (SWIFT_SYNCHRONIZATION_GYB_SOURCES
@@ -38,24 +37,28 @@ set(SWIFT_SYNCHRONIZATION_GYB_SOURCES
38
37
39
38
set (SWIFT_SYNCHRONIZATION_DARWIN_SOURCES
40
39
Mutex/DarwinImpl.swift
40
+ Mutex/Mutex.swift
41
41
)
42
42
43
43
# Linux and Android sources
44
44
45
45
set (SWIFT_SYNCHRONIZATION_LINUX_SOURCES
46
46
Mutex/LinuxImpl.swift
47
+ Mutex/Mutex.swift
47
48
Mutex/SpinLoopHint.swift
48
49
)
49
50
50
51
# Wasm sources
51
52
52
53
set (SWIFT_SYNCHRONIZATION_WASM_SOURCES
54
+ Mutex/Mutex.swift
53
55
Mutex/WasmImpl.swift
54
56
)
55
57
56
58
# Windows sources
57
59
58
60
set (SWIFT_SYNCHRONIZATION_WINDOWS_SOURCES
61
+ Mutex/Mutex.swift
59
62
Mutex/WindowsImpl.swift
60
63
)
61
64
@@ -89,6 +92,8 @@ add_swift_target_library(swiftSynchronization ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES
89
92
${SWIFT_SYNCHRONIZATION_WASM_SOURCES}
90
93
SWIFT_SOURCES_DEPENDS_WINDOWS
91
94
${SWIFT_SYNCHRONIZATION_WINDOWS_SOURCES}
95
+ SWIFT_SOURCES_DEPENDS_FREESTANDING
96
+ Mutex/MutexUnavailable.swift
92
97
93
98
SWIFT_MODULE_DEPENDS_OSX
94
99
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