
package org.osgi.test.support.compatibility;

/**
 * A classic Semaphore class.
 */
public class Semaphore {

	int count = 0;

	/**
	 * Creates a new Semaphore with 0 as a start value.
	 */
	public Semaphore() {
		this(0);
	}

	/** 
	 * Creates a new Semaphore with a given start value.
	 * @param startValue sets the value to start with.
	 * @throws IllegalArgumentException if the startValue is negative
	 */
	public Semaphore(int startValue) throws IllegalArgumentException {
		if(startValue < 0) {
			throw new IllegalArgumentException("startValue can't be lower than 0");
		}
		synchronized (this) {
			count = startValue;
		}
	}
	
	/**
	 * Waits until a signal is (or has been) given.
	 */
	public void waitForSignal() throws InterruptedException {
		waitForSignal(0);
	}
	
	/**
	 * Waits until a signal is (or has been) given.
	 */
	public synchronized void waitForSignal(long timeout) throws InterruptedException {
		while (count == 0) {
			wait(timeout);
		}
		count--;
	}
	
	/**
	 * Give the signal.
	 */
	public synchronized void signal() {
        count++;
        notify();
    }
}


@@ -40,16 +40,17 @@
 ility;%0A%0A
+%0A
 /**%0A * A
@@ -769,25 +769,24 @@
 gnal(0);%0A%09%7D%0A
-%09
 %0A%09/**%0A%09 * Wa
@@ -820,32 +820,223 @@
 as been) given.%0A
+%09 * %0A%09 * @param timeout The maximum number of milliseconds to wait for a signal or%0A%09 *        0 to wait indefinitely.%0A%09 * @return true if the signal is received; false if the wait times out.%0A
 %09 */%0A%09public syn
@@ -1045,20 +1045,23 @@
 ronized 
-void
+boolean
  waitFor
@@ -1080,17 +1080,20 @@
 timeout)
- 
+%0A%09%09%09
 throws I
@@ -1161,19 +1161,98 @@
 ;%0A%09%09
-%7D%0A%09%09count--
+%09if ((count == 0) && (timeout != 0)) %7B%0A%09%09%09%09return false;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09count--;%0A%09%09return true
 ;%0A%09%7D

fix wait with timeout to actually timeout :-)