GitHub

TxReentrantLock

API reference for TxReentrantLock.

TxReentrantLock(ref) wraps an existing TxRef (Effect's makeUnsafe); make is the effect.

Attributes

AttributeTypeDescription
refTxRef[LockState]

Functions

__init__

__init__(state) -> None
ParameterTypeDescription
stateTxRef[LockState]
def __init__(self, state: TxRef[LockState]) -> None:
    self._state = state

make

make() -> Effect[TxReentrantLock]

Returns Effect[TxReentrantLock]

@staticmethod
def make() -> Effect[TxReentrantLock]:
    return TxRef.make(LockState()).map(TxReentrantLock)

acquire_read

acquire_read() -> Effect[int]

Take a read lock, waiting while another fiber holds the write lock; succeeds with this fiber's read-lock count.

Returns Effect[int]

def acquire_read(self) -> Effect[int]:
    """Take a read lock, waiting while another fiber holds the write
    lock; succeeds with this fiber's read-lock count."""
    return self._as_fiber(self._acquire_read)

acquire_write

acquire_write() -> Effect[int]

Take the write lock, waiting while another fiber holds any lock; succeeds with this fiber's write-lock count.

Returns Effect[int]

def acquire_write(self) -> Effect[int]:
    """Take the write lock, waiting while another fiber holds any lock;
    succeeds with this fiber's write-lock count."""
    return self._as_fiber(self._acquire_write)

release_read

release_read() -> Effect[int]

Give back one of this fiber's read locks; succeeds with how many it still holds (0 if it held none).

Returns Effect[int]

def release_read(self) -> Effect[int]:
    """Give back one of this fiber's read locks; succeeds with how many it
    still holds (0 if it held none)."""
    return self._as_fiber(self._release_read)

release_write

release_write() -> Effect[int]

Give back one take of the write lock if this fiber holds it; succeeds with how many it still holds (0 if it held none).

Returns Effect[int]

def release_write(self) -> Effect[int]:
    """Give back one take of the write lock if this fiber holds it;
    succeeds with how many it still holds (0 if it held none)."""
    return self._as_fiber(self._release_write)

read_lock

read_lock() -> Effect[int, Never, Scope]

Take a read lock until the current scope closes. Only the wait is interruptible; whoever closes the scope releases this fiber's lock.

Returns Effect[int, Never, Scope]

def read_lock(self) -> Effect[int, Never, Scope]:
    """Take a read lock until the current scope closes. Only the wait is
    interruptible; whoever closes the scope releases this fiber's lock."""
    return self._scoped(self._acquire_read, self._release_read)

write_lock

write_lock() -> Effect[int, Never, Scope]

Take the write lock until the current scope closes.

Returns Effect[int, Never, Scope]

def write_lock(self) -> Effect[int, Never, Scope]:
    """Take the write lock until the current scope closes."""
    return self._scoped(self._acquire_write, self._release_write)

with_read_lock

with_read_lock[A, E, R](eff) -> Effect[A, E, R]

Run eff holding a read lock, releasing it however it ends. Only the wait for the lock is interruptible.

ParameterTypeDescription
effEffect[A, E, R]

Returns Effect[A, E, R]

def with_read_lock[A, E, R](self, eff: Effect[A, E, R]) -> Effect[A, E, R]:
    """Run ``eff`` holding a read lock, releasing it however it ends.
    Only the wait for the lock is interruptible."""
    require_effect(eff, "eff")
    return self._with_acquired(self._acquire_read, eff, self._release_read)

with_write_lock

with_write_lock[A, E, R](eff) -> Effect[A, E, R]

Run eff holding the write lock, releasing it however it ends.

ParameterTypeDescription
effEffect[A, E, R]

Returns Effect[A, E, R]

def with_write_lock[A, E, R](self, eff: Effect[A, E, R]) -> Effect[A, E, R]:
    """Run ``eff`` holding the write lock, releasing it however it ends."""
    require_effect(eff, "eff")
    return self._with_acquired(self._acquire_write, eff, self._release_write)

with_lock

with_lock[A, E, R](eff) -> Effect[A, E, R]

with_write_lock.

ParameterTypeDescription
effEffect[A, E, R]

Returns Effect[A, E, R]

def with_lock[A, E, R](self, eff: Effect[A, E, R]) -> Effect[A, E, R]:
    """``with_write_lock``."""
    require_effect(eff, "eff")
    return self.with_write_lock(eff)

read_locks

read_locks() -> Effect[int]

Read locks held, summed over fibers.

Returns Effect[int]

def read_locks(self) -> Effect[int]:
    """Read locks held, summed over fibers."""
    return _tx_ops.read(self._state, lambda state: sum(state.readers.values()))

write_locks

write_locks() -> Effect[int]

How many times the write lock is held.

Returns Effect[int]

def write_locks(self) -> Effect[int]:
    """How many times the write lock is held."""
    return _tx_ops.read(self._state, lambda state: state.writer[1] if state.writer else 0)

locked

locked() -> Effect[bool]

Returns Effect[bool]

def locked(self) -> Effect[bool]:
    return _tx_ops.read(self._state, lambda state: bool(state.readers) or bool(state.writer))

read_locked

read_locked() -> Effect[bool]

Returns Effect[bool]

def read_locked(self) -> Effect[bool]:
    return _tx_ops.read(self._state, lambda state: bool(state.readers))

write_locked

write_locked() -> Effect[bool]

Returns Effect[bool]

def write_locked(self) -> Effect[bool]:
    return _tx_ops.read(self._state, lambda state: state.writer is not None)