70 lines
1.3 KiB
Java
70 lines
1.3 KiB
Java
package org.warp.commonutils.locks;
|
|
|
|
public class TransitReadWriteLock {
|
|
|
|
private final TransitLock writeLock;
|
|
private final TransitLock readLock;
|
|
private final Object synchronization = new Object();
|
|
|
|
public TransitReadWriteLock() {
|
|
this.writeLock = new TransitLock();
|
|
this.readLock = new TransitLock();
|
|
}
|
|
|
|
public void reAllowTransit() {
|
|
this.readLock.allowTransit();
|
|
this.writeLock.allowTransit();
|
|
}
|
|
|
|
public void disallowTransit() {
|
|
synchronized (synchronization) {
|
|
this.writeLock.disallowTransit();
|
|
this.readLock.disallowTransit();
|
|
}
|
|
}
|
|
|
|
public void reAllowTransitRead() {
|
|
this.readLock.allowTransit();
|
|
}
|
|
|
|
public void disallowTransitRead() {
|
|
this.readLock.disallowTransit();
|
|
}
|
|
|
|
public void reAllowTransitWrite() {
|
|
this.writeLock.allowTransit();
|
|
}
|
|
|
|
public void disallowTransitWrite() {
|
|
this.writeLock.disallowTransit();
|
|
}
|
|
|
|
public void transitWrite() {
|
|
this.writeLock.transit();
|
|
}
|
|
|
|
public void transitRead() {
|
|
this.readLock.transit();
|
|
}
|
|
|
|
public void startTransitWrite() {
|
|
synchronized (synchronization) {
|
|
this.writeLock.startTransit();
|
|
}
|
|
}
|
|
|
|
public void startTransitRead() {
|
|
synchronized (synchronization) {
|
|
this.readLock.startTransit();
|
|
}
|
|
}
|
|
|
|
public void endTransitWrite() {
|
|
writeLock.endTransit();
|
|
}
|
|
|
|
public void endTransitRead() {
|
|
readLock.endTransit();
|
|
}
|
|
}
|