org.jikesrvm.scheduler
Class Latch

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

public class Latch
extends Object

An implementation of a latch using the HeavyCondLock in "nice" mode. 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.


Field Summary
private  boolean open
           
private  Monitor schedLock
           
 
Constructor Summary
Latch(boolean open)
          Create a new latch, with the given open/closed state.
 
Method Summary
 void closeWithHandshake()
          Close the latch, causing future calls to wait() or waitAndClose() to block.
 void openNoHandshake()
          Like open(), but does it without letting the system know that we could potentially block.
 void openWithHandshake()
          Open the latch and let all of the thread(s) waiting on it through.
 void waitAndCloseWithHandshake()
          Wait for the latch to become open, and then close it and return.
 void waitWithHandshake()
          Wait for the latch to become open.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

schedLock

private final Monitor schedLock

open

private boolean open
Constructor Detail

Latch

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

Method Detail

openWithHandshake

public void openWithHandshake()
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.


openNoHandshake

public void openNoHandshake()
Like open(), but does it without letting the system know that we could potentially block. This is faster, and better for use in interrupt handlers.


closeWithHandshake

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


waitWithHandshake

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


waitAndCloseWithHandshake

public void waitAndCloseWithHandshake()
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.