/*
 * Created on 14-mag-2004
 */
package a3.protocol;

/**
 * @author Lompa
 */
public class ControlQueue {
	
	private Queue queue = new Queue();
	
	public ControlQueue(){}
	
	public void takeControl() throws InterruptedException{
		queue.takeControl();
	}
	
	public void releaseControl(){
		queue.releaseControl();
	}

	private class Queue {
		
		private int value = 1;
		
		public synchronized void takeControl() throws InterruptedException{
			if (value == 0) this.wait();
			value--;
		}
		
		public synchronized void releaseControl(){
			value++;
			this.notifyAll();
		}
	}
	
}
