diff --git a/src/ConcurrentUtils.jl b/src/ConcurrentUtils.jl index f5db634..038e55d 100644 --- a/src/ConcurrentUtils.jl +++ b/src/ConcurrentUtils.jl @@ -45,11 +45,10 @@ InternalPrelude.@exported_function isacquirable InternalPrelude.@exported_function isacquirable_read =# -InternalPrelude.@exported_function acquire_read -InternalPrelude.@exported_function acquire_read_then InternalPrelude.@exported_function read_write_lock -InternalPrelude.@exported_function release_read -InternalPrelude.@exported_function try_race_acquire_read +InternalPrelude.@exported_function trylock_read +InternalPrelude.@exported_function lock_read +InternalPrelude.@exported_function unlock_read abstract type AbstractGuard end abstract type AbstractReadWriteGuard end @@ -109,13 +108,13 @@ using ..ConcurrentUtils: NotSetError, OccupiedError, TooManyTries, - acquire_read, - acquire_read_then, + lock_read, + lock_read, race_fetch_or!, - release_read, + unlock_read, spinfor, spinloop, - try_race_acquire_read, + trylock_read, try_race_fetch, try_race_fetch_or!, try_race_put! diff --git a/src/guards.jl b/src/guards.jl index af105cd..ec8731d 100644 --- a/src/guards.jl +++ b/src/guards.jl @@ -33,7 +33,7 @@ end function ConcurrentUtils.guarding_read(f::F, g::GenericReadWriteGuard) where {F} data = g.data criticalsection() = f(data) - acquire_read_then(criticalsection, g.lock) + lock_read(criticalsection, g.lock) end # Maybe this is a bad idea since it's hard to remember that `guarding(_, ::ReadGuard)` diff --git a/src/lock_interface.jl b/src/lock_interface.jl index f8b643d..d65eb59 100644 --- a/src/lock_interface.jl +++ b/src/lock_interface.jl @@ -4,12 +4,12 @@ abstract type AbstractReadWriteLock <: Base.AbstractLock end -function ConcurrentUtils.acquire_read_then(f, lock::AbstractReadWriteLock) - acquire_read(lock) +function ConcurrentUtils.lock_read(f, lock::AbstractReadWriteLock) + lock_read(lock) try return f() finally - release_read(lock) + unlock_read(lock) end end @@ -17,9 +17,9 @@ struct ReadLockHandle{RWLock} <: Base.AbstractLock rwlock::RWLock end -Base.trylock(lck::ReadLockHandle) = Try.iok(try_race_acquire_read(lck.rwlock)) -Base.lock(lck::ReadLockHandle) = acquire_read(lck.rwlock) -Base.unlock(lck::ReadLockHandle) = release_read(lck.rwlock) +Base.trylock(lck::ReadLockHandle) = trylock_read(lck.rwlock) +Base.lock(lck::ReadLockHandle) = lock_read(lck.rwlock) +Base.unlock(lck::ReadLockHandle) = unlock_read(lck.rwlock) ConcurrentUtils.read_write_lock(lock::AbstractReadWriteLock = ReadWriteLock()) = (ReadLockHandle(lock), lock) diff --git a/src/read_write_lock.jl b/src/read_write_lock.jl index 4988da3..b30fa23 100644 --- a/src/read_write_lock.jl +++ b/src/read_write_lock.jl @@ -23,11 +23,7 @@ function ReadWriteLock() end # Not very efficient but lock-free -function ConcurrentUtils.try_race_acquire_read( - rwlock::ReadWriteLock; - nspins = -∞, - ntries = -∞, -) +function ConcurrentUtils.trylock_read(rwlock::ReadWriteLock; nspins = -∞, ntries = -∞) local ns::Int = 0 local nt::Int = 0 while true @@ -41,16 +37,16 @@ function ConcurrentUtils.try_race_acquire_read( rwlock.nreaders_and_writelock, old => old + NREADERS_INC, ) - success && return Ok(nothing) + success && return true nt += 1 - nt < ntries || return Err(TooManyTries(ns, nt)) + nt < ntries || return false end ns += 1 - ns < nspins || return Err(TooManyTries(ns, nt)) + ns < nspins || return false end end -function ConcurrentUtils.acquire_read(rwlock::ReadWriteLock) +function ConcurrentUtils.lock_read(rwlock::ReadWriteLock) # Using hardware FAA ptr = Ptr{NReadersAndWritelock}( @@ -76,7 +72,7 @@ function ConcurrentUtils.acquire_read(rwlock::ReadWriteLock) end end -function ConcurrentUtils.release_read(rwlock::ReadWriteLock) +function ConcurrentUtils.unlock_read(rwlock::ReadWriteLock) # Using hardware FAA ptr = Ptr{NReadersAndWritelock}(