org.jikesrvm.scheduler
Class SoftLatch

java.lang.Object
  extended by org.jikesrvm.scheduler.SoftLatch

public class SoftLatch
extends Object

An implementation of a latch using monitors. This essentially gives you park/unpark functionality. It can also be used like the Win32-style AutoResetEvent or ManualResetEvent.

Park/unpark example: use open() to unpark and waitAndClose() to park.

AutoResetEvent example: use open() to set, close() to reset, and waitAndClose() to wait.

ManualResetEvent example: use open() to set, close() to reset, and wait() to wait.

Note: never synchronize on instances of this class.


Field Summary
private  boolean open
           
 
Constructor Summary
SoftLatch(boolean open)
          Create a new latch, with the given open/closed state.
 
Method Summary
 void await()
          Wait for the latch to become open.
 void close()
          Close the latch, causing future calls to wait() or waitAndClose() to block.
 void open()
          Open the latch and let all of the thread(s) waiting on it through.
 void waitAndClose()
          Wait for the latch to become open, and then close it and return.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

open

private boolean open
Constructor Detail

SoftLatch

public SoftLatch(boolean open)
Create a new latch, with the given open/closed state.

Method Detail

open

public void open()
Open the latch and let all of the thread(s) waiting on it through. But - if any of the threads is using waitAndClose(), then as soon as that thread awakes further threads will be blocked.


close

public void close()
Close the latch, causing future calls to wait() or waitAndClose() to block.


await

public void await()
Wait for the latch to become open. If it is already open, don't wait at all.


waitAndClose

public void waitAndClose()
Wait for the latch to become open, and then close it and return. If the latch is already open, don't wait at all, just close it immediately and return.