Class ReadWriteLocked

java.lang.Object
com.helixframework.concurrency.rwlock.ReadWriteLocked

public final class ReadWriteLocked extends Object
Executes operations with read and write locks.

Non-reentrant read operations are not allowed until all write operations have been finished. Additionally, a write operation can acquire the read lock, but not vice-versa.

  • Constructor Details

    • ReadWriteLocked

      public ReadWriteLocked()
      Creates a lock.
    • ReadWriteLocked

      public ReadWriteLocked(String name)
      Creates a named lock.
      Parameters:
      name - lock name
  • Method Details

    • read

      public <T> T read(ValueOperation<T> op)
      Executes the read operation with a lock.
      Type Parameters:
      T - operation return type
      Parameters:
      op - operation
      Returns:
      read operation result
    • read

      public void read(VoidOperation op)
      Executes the read operation with a lock.
      Parameters:
      op - operation
    • write

      public <T> T write(ValueOperation<T> op)
      Executes the write operation with a lock.
      Type Parameters:
      T - operation return type
      Parameters:
      op - operation
      Returns:
      write operation result
    • write

      public void write(VoidOperation op)
      Executes the write operation with a lock.
      Parameters:
      op - operation
    • getName

      public String getName()
      Gets the name of the lock.
      Returns:
      name of the lock or null if it is not named