diff --git a/Project.toml b/Project.toml index 64663c6..d89ad23 100644 --- a/Project.toml +++ b/Project.toml @@ -4,8 +4,10 @@ authors = ["Takafumi Arakaki and contributors"] version = "0.1.0-DEV" [deps] +ConcurrentUtils = "3df5f688-6c4c-4767-8685-17f5ad261477" UnsafeAtomics = "013be700-e6cd-48c3-b4a1-df204f14c38f" [compat] +ConcurrentUtils = "0.1" UnsafeAtomics = "0.1" julia = "1.7" diff --git a/src/LeftRight.jl b/src/LeftRight.jl index d757d5b..fff972e 100644 --- a/src/LeftRight.jl +++ b/src/LeftRight.jl @@ -2,13 +2,10 @@ baremodule LeftRight export guarding_read, guarding -# TODO: Move them to ConcurrentUtils -function guarding_read end -function guarding end - module Internal using UnsafeAtomics: UnsafeAtomics, acq_rel, seq_cst +using ConcurrentUtils: ConcurrentUtils, guarding_read, guarding, spinloop using ..LeftRight: LeftRight @@ -17,6 +14,8 @@ include("core.jl") end # module Internal +const guarding = Internal.guarding +const guarding_read = Internal.guarding_read const Guard = Internal.Guard # const SimpleGuard = Internal.SimpleGuard diff --git a/src/core.jl b/src/core.jl index 4d051c9..1ac7137 100644 --- a/src/core.jl +++ b/src/core.jl @@ -180,7 +180,7 @@ function release_read(::GenericGuard, token) return end -function LeftRight.guarding_read(f, g::GenericGuard) +function ConcurrentUtils.guarding_read(f, g::GenericGuard) token, data = acquire_read(g) try return f(data) @@ -189,7 +189,7 @@ function LeftRight.guarding_read(f, g::GenericGuard) end end -function LeftRight.guarding(f!, g::GenericGuard) +function ConcurrentUtils.guarding(f!, g::GenericGuard) lock(g.lock) try # No need to use `:acquire` since the lock already has ordered the access: diff --git a/src/utils.jl b/src/utils.jl index c01a219..6c0328c 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -10,8 +10,3 @@ end const var"@const" = var"@_const" pad7() = ntuple(_ -> 0, Val(7)) - -function spinloop() - GC.safepoint() - ccall(:jl_cpu_pause, Cvoid, ()) -end