01: package com.xoetrope.svg;
02:
03: /**
04: *
05: *
06: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
07: * the GNU Public License (GPL), please see license.txt for more details. If
08: * you make commercial use of this software you must purchase a commercial
09: * license from Xoetrope.</p>
10: * <p> $Revision: 1.2 $</p>
11: */
12: public class XRenderingSemaphore {
13: private int value;
14:
15: /**
16: * Creates a new instance of XRenderingSemaphore
17: * @param value <CODE>int</CODE> specifying the initial value of the semaphore
18: */
19: public XRenderingSemaphore(int value) {
20: this .value = value;
21: }
22:
23: /**
24: * Decrements the semaphore value and instructs all other threads using the resource to wait.
25: */
26: public synchronized void acquire() {
27: value -= 1;
28: if (value < 0) {
29: try {
30: wait();
31: } catch (Exception e) {
32: }
33: }
34: }
35:
36: /**
37: * Increments the semaphore value and notifies all threads waiting on the resource that it is now free.
38: */
39: public synchronized void release() {
40: value += 1;
41: notify();
42: }
43: }
|