Generic Locks
DataAxesFormats.GenericLocks
—
Module
Generic (enhanced) read-write locks, which arguably should belong in a more general-purpose package.
These add functionality on top of
ConcurrentUtils
; specifically, they allow querying the status of the lock.
This code relies on tasks staying on the same thread, so
always
specify
@threads :static
when using them, otherwise bad things
will
happen.
We do not re-export the types and functions defined here from the top-level
DataAxesFormats
namespace. That is, even if
using DataAxesFormats
, you will
not
have these generic names polluting your namespace. If you do want to reuse them in your code, explicitly write
using DataAxesFormats.GenericLocks
.
DataAxesFormats.GenericLocks.QueryReadWriteLock
—
Type
struct QueryReadWriteLock <: AbstractLock ... end
A read-write lock with queries.
Write Lock
DataAxesFormats.GenericLocks.write_lock
—
Function
write_lock(query_read_write_lock::QueryReadWriteLock, what::Any...)::Nothing
Obtain a write lock. Each call must be matched by
write_unlock
. It is possible to nest
write_lock
/
write_unlock
call pairs.
When a thread has a write lock, no other thread can have any lock.
The log messages includes
what
is being locked.
DataAxesFormats.GenericLocks.write_unlock
—
Function
write_unlock(query_read_write_lock::QueryReadWriteLock, what::Any)::Nothing
Release a write lock. Each call must matched a call to
write_lock
. It is possible to nest
write_lock
/
write_unlock
call pairs.
The log messages includes
what
is being unlocked.
DataAxesFormats.GenericLocks.with_write_lock
—
Function
with_write_lock(action::Function, query_read_write_lock::QueryReadWriteLock, what::Any...)::Any
Perform an
action
while holding a
write_lock
for the
query_read_write_lock
, return its result and
write_unlock
.
DataAxesFormats.GenericLocks.has_write_lock
—
Function
has_write_lock(query_read_write_lock::QueryReadWriteLock)::Bool
Return whether the current thread has the write lock.
Read Locks
DataAxesFormats.GenericLocks.read_lock
—
Function
read_lock(query_read_write_lock::QueryReadWriteLock, what::Any...)::Bool
Obtain a read lock. Each call must be matched by
read_unlock
. It is possible to nest
read_lock
/
read_unlock
call pairs, even inside
write_lock
/
write_unlock
pair(s); however, you can't nest
write_lock
/
write_unlock
inside a
read_lock
/
read_unlock
pair.
When a thread has a read lock, no other thread can have a write lock, but other threads may also have a read lock.
The log messages includes
what
is being locked.
Returns whether this is the top-level read lock (as opposed to a nested one).
DataAxesFormats.GenericLocks.read_unlock
—
Function
read_unlock(query_read_write_lock::QueryReadWriteLock, what::Any...)::Nothing
Release a read lock. Each call must matched a call to
read_lock
. It is possible to nest
read_lock
/
read_unlock
call pairs.
The log messages includes
what
is being unlocked.
DataAxesFormats.GenericLocks.with_read_lock
—
Function
with_read_lock(action::Function, query_read_write_lock::QueryReadWriteLock, what::Any...)::Any
Perform an
action
while holding a
read_lock
for the
query_read_write_lock
, return its result and
read_unlock
.
DataAxesFormats.GenericLocks.has_read_lock
—
Function
has_read_lock(query_read_write_lock::QueryReadWriteLock; read_only::Bool = false)::Bool
Return whether the current thread has a read lock or the write lock. If
read_only
is set, then this will only return whether the current thread as a read lock.
Index
-
DataAxesFormats.GenericLocks -
DataAxesFormats.GenericLocks.QueryReadWriteLock -
DataAxesFormats.GenericLocks.has_read_lock -
DataAxesFormats.GenericLocks.has_write_lock -
DataAxesFormats.GenericLocks.read_lock -
DataAxesFormats.GenericLocks.read_unlock -
DataAxesFormats.GenericLocks.with_read_lock -
DataAxesFormats.GenericLocks.with_write_lock -
DataAxesFormats.GenericLocks.write_lock -
DataAxesFormats.GenericLocks.write_unlock