Skip to content

Commit d753b64

Browse files
committed
implement syncscopes everywhere
1 parent 939f237 commit d753b64

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/UnsafeAtomics.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
baremodule UnsafeAtomics
22

33
abstract type Ordering end
4+
abstract type SyncScope end
45

56
function load end
67
function store! end
@@ -30,6 +31,7 @@ using ..UnsafeAtomics: UnsafeAtomics, Ordering, right
3031

3132
include("utils.jl")
3233
include("orderings.jl")
34+
include("syncscopes.jl")
3335
include("core.jl")
3436

3537
end # module Internal
@@ -45,4 +47,8 @@ const seq_cst = Internal.seq_cst
4547
const acquire_release = acq_rel
4648
const sequentially_consistent = seq_cst
4749

50+
# SyncScope
51+
const none = Internal.none
52+
const singlethread = Internal.singlethread
53+
4854
end # baremodule UnsafeAtomics

src/core.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
@inline UnsafeAtomics.modify!(ptr, op, x) = UnsafeAtomics.modify!(ptr, op, x, seq_cst)
55
@inline UnsafeAtomics.fence() = UnsafeAtomics.fence(seq_cst)
66

7+
@inline UnsafeAtomics.load(x, ord) = UnsafeAtomics.load(x, ord, none)
8+
@inline UnsafeAtomics.store!(x, v, ord) = UnsafeAtomics.store!(x, v, ord, none)
9+
@inline UnsafeAtomics.cas!(x, cmp, new, ord) = UnsafeAtomics.cas!(x, cmp, new, ord, ord, none)
10+
@inline UnsafeAtomics.modify!(ptr, op, x, ord) = UnsafeAtomics.modify!(ptr, op, x, ord, none)
11+
@inline UnsafeAtomics.fence(ord) = UnsafeAtomics.fence(ord., none)
12+
713
#! format: off
814
# https://github.com/JuliaLang/julia/blob/v1.6.3/base/atomics.jl#L23-L30
915
if Sys.ARCH == :i686 || startswith(string(Sys.ARCH), "arm") ||
@@ -45,8 +51,9 @@ const OP_RMW_TABLE = [
4551
for (op, rmwop) in OP_RMW_TABLE
4652
fn = Symbol(rmwop, "!")
4753
@eval @inline UnsafeAtomics.$fn(x, v) = UnsafeAtomics.$fn(x, v, seq_cst)
48-
@eval @inline UnsafeAtomics.$fn(ptr, x, ord) =
49-
first(UnsafeAtomics.modify!(ptr, $op, x, ord))
54+
@eval @inline UnsafeAtomics.$fn(x, v, ord) = UnsafeAtomics.$fn(x, v, ord, none)
55+
@eval @inline UnsafeAtomics.$fn(ptr, x, ord, scope) =
56+
first(UnsafeAtomics.modify!(ptr, $op, x, ord, scope))
5057
end
5158

5259
const ATOMIC_INTRINSICS = isdefined(Core.Intrinsics, :atomic_pointerref)

src/syncscopes.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
struct LLVMSyncScope{name} <: SyncScope end
2+
3+
const none = LLVMSyncScope{Symbol("")}()
4+
const singlethread = LLVMSyncScope{:singlethread}()
5+
6+
llvm_syncscope(::LLVMSyncScope{name}) where {name} = name
7+
8+
Base.string(s::LLVMSyncScope) = String(llvm_syncscope(s))
9+
Base.print(io::IO, s::LLVMSyncScope) = print(io, string(s))

0 commit comments

Comments
 (0)