psimjava
Class Bsemaphore

java.lang.Object
  extended by psimjava.Bsemaphore

public class Bsemaphore
extends java.lang.Object

PsimJ Java package for OO simulation

Object-oriented simulation package, process interaction approach.

(C) J. M. Garrido. June 2000 Rev.2003, 2004, Oct. 2007 Binary semaphore class.

File: Bsemaphore.java


Constructor Summary
Bsemaphore(java.lang.String name, int initval)
          Constructor for the binary semaphore object
 
Method Summary
 boolean available()
          This method checks if the semaphore object is available.
 void bsignal()
          This method releases the semaphore object, and makes it available to other processes.
 void bwait()
          This method allows the requesting process to acquire the semaphore if it has not been acquired by another process.
 java.lang.String get_name()
          This method returns the name of the semaphore object
 int length()
          This method gets the number of waiting processes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Bsemaphore

public Bsemaphore(java.lang.String name,
                  int initval)
Constructor for the binary semaphore object

Parameters:
name - the title for the semaphore object
initval - the initial value of bsem attribute
Method Detail

get_name

public java.lang.String get_name()
This method returns the name of the semaphore object


bwait

public void bwait()
This method allows the requesting process to acquire the semaphore if it has not been acquired by another process. The requesting process is suspended and placed in the semaphore queue, if it cannot immediately acquire the semaphore.


length

public int length()
This method gets the number of waiting processes.

Returns:
int Number of Waiting processes

bsignal

public void bsignal()
This method releases the semaphore object, and makes it available to other processes. Then the method reactivates and removes from the semaphore queue any waiting processes.

Parameters:
num - int, the number of resource items released by the calling process.

available

public boolean available()
This method checks if the semaphore object is available.

Returns:
true if the semaphore is available (not busy)