arlut.csd.Util
Class booleanSemaphore

java.lang.Object
  |
  +--arlut.csd.Util.booleanSemaphore

public class booleanSemaphore
extends java.lang.Object

Simple, synchronized boolean flag class.

This class is useful for providing a reliable boolean flag that can be examined by separate threads without worry over funky memory model behavior on multiprocessor systems, etc.


Field Summary
private  boolean state
           
 
Constructor Summary
booleanSemaphore(boolean initialState)
           
 
Method Summary
 boolean isSet()
           
 boolean set(boolean b)
          Simple bidirectional test and set.
 void waitForCleared()
          Safe, simple method to wait until this boolean semaphore has been cleared.
 boolean waitForCleared(long millis)
          Safe, simple method to wait until this boolean semaphore has been cleared, or until at least millis milliseconds have passed.
 void waitForSet()
          Safe, simple method to wait until this boolean semaphore has been set.
 boolean waitForSet(long millis)
          Safe, simple method to wait until this boolean semaphore has been cleared, or until at least millis milliseconds have passed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

state

private boolean state
Constructor Detail

booleanSemaphore

public booleanSemaphore(boolean initialState)
Method Detail

isSet

public boolean isSet()

set

public boolean set(boolean b)

Simple bidirectional test and set.

Returns:
The value that the booleanSemaphore had before set() was called.

waitForCleared

public void waitForCleared()

Safe, simple method to wait until this boolean semaphore has been cleared. If the semaphore is already cleared at the time this method is called, this method will return immediately.

Note that this method will not time out.


waitForCleared

public boolean waitForCleared(long millis)

Safe, simple method to wait until this boolean semaphore has been cleared, or until at least millis milliseconds have passed. If the semaphore is already cleared at the time this method is called, this method will return immediately.


waitForSet

public void waitForSet()

Safe, simple method to wait until this boolean semaphore has been set. If the semaphore is already set at the time this method is called, this method will return immediately.

Note that this method will not time out.


waitForSet

public boolean waitForSet(long millis)

Safe, simple method to wait until this boolean semaphore has been cleared, or until at least millis milliseconds have passed. If the semaphore is already set at the time this method is called, this method will return immediately.