29 lines
472 B
Java
29 lines
472 B
Java
|
package org.warp.commonutils.locks;
|
||
|
|
||
|
import java.util.concurrent.Phaser;
|
||
|
|
||
|
public class FlexibleCountDownLatch {
|
||
|
|
||
|
private final Phaser phaser;
|
||
|
|
||
|
public FlexibleCountDownLatch(int initialSize) {
|
||
|
this.phaser = new Phaser(initialSize + 1);
|
||
|
}
|
||
|
|
||
|
public void await() {
|
||
|
phaser.arriveAndAwaitAdvance();
|
||
|
}
|
||
|
|
||
|
public void grow() {
|
||
|
phaser.register();
|
||
|
}
|
||
|
|
||
|
public void grow(int n) {
|
||
|
phaser.bulkRegister(n);
|
||
|
}
|
||
|
|
||
|
public void countDown() {
|
||
|
phaser.arriveAndDeregister();
|
||
|
}
|
||
|
}
|