-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SIL: allow atomic operations in
@_noLocks
functions
- Loading branch information
Showing
2 changed files
with
32 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// RUN: %target-swift-frontend -parse-as-library -disable-availability-checking -emit-sil %s -o /dev/null | ||
|
||
// REQUIRES: synchronization | ||
|
||
import Synchronization | ||
|
||
// Check that atomics work in no-locks mode. | ||
|
||
@_noLocks | ||
func testFence() { | ||
atomicMemoryFence(ordering: .acquiring) | ||
atomicMemoryFence(ordering: .releasing) | ||
atomicMemoryFence(ordering: .acquiringAndReleasing) | ||
atomicMemoryFence(ordering: .sequentiallyConsistent) | ||
} | ||
|
||
@_noLocks | ||
func testLoadStore() -> Int { | ||
let x = Atomic(0) | ||
x.store(27, ordering: .relaxed) | ||
x.compareExchange(expected: 27, desired: 42, successOrdering: .relaxed, failureOrdering: .relaxed) | ||
return x.load(ordering: .acquiring) | ||
} | ||
|
||
@_noLocks | ||
func testRMW(_ b: Bool) -> (Bool, Bool) { | ||
let x = Atomic(false) | ||
return x.logicalOr(true, ordering: .relaxed) | ||
} | ||
|