final class TReentrantLock extends AnyRef
A TReentrantLock
is a reentrant read/write lock. Multiple readers may all
concurrently acquire read locks. Only one writer is allowed to acquire a
write lock at any given time. Read locks may be upgraded into write locks. A
fiber that has a write lock may acquire other write locks or read locks.
The two primary methods of this structure are readLock
, which acquires a
read lock in a scoped context, and writeLock
, which acquires a write lock
in a scoped context.
Although located in the STM package, there is no need for locks within STM transactions. However, this lock can be quite useful in effectful code, to provide consistent read/write access to mutable state; and being in STM allows this structure to be composed into more complicated concurrent structures that are consumed from effectful code.
- Alphabetic
- By Inheritance
- TReentrantLock
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
lazy val
acquireRead: USTM[Int]
Acquires a read lock.
Acquires a read lock. The transaction will suspend until no other fiber is holding a write lock. Succeeds with the number of read locks held by this fiber.
-
lazy val
acquireWrite: USTM[Int]
Acquires a write lock.
Acquires a write lock. The transaction will suspend until no other fibers are holding read or write locks. Succeeds with the number of write locks held by this fiber.
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
fiberReadLocks: USTM[Int]
Retrieves the number of acquired read locks for this fiber.
-
def
fiberWriteLocks: USTM[Int]
Retrieves the number of acquired write locks for this fiber.
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
lock(implicit trace: Trace): ZIO[Scope, Nothing, Int]
Just a convenience method for applications that only need reentrant locks, without needing a distinction between readers / writers.
Just a convenience method for applications that only need reentrant locks, without needing a distinction between readers / writers.
See writeLock.
-
def
locked: USTM[Boolean]
Determines if any fiber has a read or write lock.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
readLock(implicit trace: Trace): ZIO[Scope, Nothing, Int]
Obtains a read lock in a scoped context.
-
def
readLocked: USTM[Boolean]
Determines if any fiber has a read lock.
-
def
readLocks: USTM[Int]
Retrieves the total number of acquired read locks.
-
lazy val
releaseRead: USTM[Int]
Releases a read lock held by this fiber.
Releases a read lock held by this fiber. Succeeds with the outstanding number of read locks held by this fiber.
-
lazy val
releaseWrite: USTM[Int]
Releases a write lock held by this fiber.
Releases a write lock held by this fiber. Succeeds with the outstanding number of write locks held by this fiber.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
withLock[R, E, A](zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A]
Runs the specified workflow with a lock.
-
def
withReadLock[R, E, A](zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A]
Runs the specified workflow with a read lock.
-
def
withWriteLock[R, E, A](zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A]
Runs the specified workflow with a write lock.
-
def
writeLock(implicit trace: Trace): ZIO[Scope, Nothing, Int]
Obtains a write lock in a scoped context.
-
def
writeLocked: USTM[Boolean]
Determines if a write lock is held by some fiber.
-
def
writeLocks: USTM[Int]
Computes the number of write locks held by fibers.