Class ReentrantMutex

  • All Implemented Interfaces:

    
    public final class ReentrantMutex
    
                        

    A reentrant mutex that allows a coroutine to lock and unlock the mutex multiple times. This is useful when a coroutine needs to acquire the same lock multiple times.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      ReentrantMutex()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final <T extends Any> T withLock(SuspendFunction0<T> block) Executes the given block while holding the lock.
      final Boolean isLocked() Checks if the mutex is locked.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ReentrantMutex

        ReentrantMutex()
    • Method Detail

      • withLock

         final <T extends Any> T withLock(SuspendFunction0<T> block)

        Executes the given block while holding the lock.

        Parameters:
        block - The block of code to execute while holding the lock.
        Returns:

        The result of the block of code.

      • isLocked

         final Boolean isLocked()

        Checks if the mutex is locked.

        Returns:

        true if the mutex is locked, false otherwise.