01: package dalma.impl;
02:
03: import java.io.Serializable;
04:
05: /**
06: * Thread-safe counter.
07: *
08: * @author Kohsuke Kawaguchi
09: */
10: final class Counter implements Serializable {
11: private int value;
12:
13: public synchronized int inc() {
14: return value++;
15: }
16:
17: public synchronized int dec() {
18: return --value;
19: }
20:
21: public synchronized int get() {
22: return value;
23: }
24:
25: public synchronized void waitForZero() throws InterruptedException {
26: while (value != 0)
27: wait();
28: }
29:
30: private static final long serialVersionUID = 1L;
31: }
|