Package net.morimekta.util.concurrent
Class ReentrantReadWriteMutex
- java.lang.Object
-
- net.morimekta.util.concurrent.ReentrantReadWriteMutex
-
- All Implemented Interfaces:
ReadWriteMutex
public class ReentrantReadWriteMutex extends java.lang.Object implements ReadWriteMutex
A re-entrant read-write mutex wrapper.
-
-
Constructor Summary
Constructors Constructor Description ReentrantReadWriteMutex()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
lockForReading(java.lang.Runnable callable)
Lock the config for a read operation that must be read atomic.<V> V
lockForReading(java.util.function.Supplier<V> callable)
Lock the config for a read operation that must be read atomic.void
lockForWriting(java.lang.Runnable callable)
Lock the config for a write operation that must be write atomic, and could interfere with read operations.<V> V
lockForWriting(java.util.function.Supplier<V> callable)
Lock the config for a write operation that must be write atomic, and could interfere with read operations.
-
-
-
Method Detail
-
lockForReading
public void lockForReading(java.lang.Runnable callable)
Description copied from interface:ReadWriteMutex
Lock the config for a read operation that must be read atomic.- Specified by:
lockForReading
in interfaceReadWriteMutex
- Parameters:
callable
- The callable operation.
-
lockForReading
public <V> V lockForReading(java.util.function.Supplier<V> callable)
Description copied from interface:ReadWriteMutex
Lock the config for a read operation that must be read atomic.- Specified by:
lockForReading
in interfaceReadWriteMutex
- Type Parameters:
V
- The read return value type.- Parameters:
callable
- The enclosed callable to be run inside read lock.- Returns:
- The supplied value.
-
lockForWriting
public void lockForWriting(java.lang.Runnable callable)
Description copied from interface:ReadWriteMutex
Lock the config for a write operation that must be write atomic, and could interfere with read operations.- Specified by:
lockForWriting
in interfaceReadWriteMutex
- Parameters:
callable
- The callable operation.
-
lockForWriting
public <V> V lockForWriting(java.util.function.Supplier<V> callable)
Description copied from interface:ReadWriteMutex
Lock the config for a write operation that must be write atomic, and could interfere with read operations.- Specified by:
lockForWriting
in interfaceReadWriteMutex
- Type Parameters:
V
- The write return value type.- Parameters:
callable
- The callable operation.- Returns:
- The supplied value.
-
-