class CountingSemaphore extends Semaphore
A counting semaphore implemented with a nonblocking queue. In principle the semaphore manages a finite collection of (identical) tokens.
The object parent
(by default the semaphore itself) is
used by the debugger when reporting the state of waiting
processes.
The value of available
may be negative, in which case it represents a deficit of tokens.
The value spin
is the number of attempts the semaphore's local spinlock will make to acquire a token
before a call to acquire
or acquireFast
causes the caller to be descheduled. The point of
trying with a spinlock first is that the performance-hit of descheduling can be very high. We assume here
that more than one processor is available: set spin
to 0
or 1
otherwise.
The fair
parameter is ignored.
- To do
Make the internal spinlock adaptive
- Alphabetic
- By Inheritance
- CountingSemaphore
- Semaphore
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new CountingSemaphore(available: Int, name: String, fair: Boolean, parent: AnyRef, spin: Int = 5)
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
acquire(): Unit
Wait until a token is (or becomes) available.
Wait until a token is (or becomes) available. If the acquiring thread is cancelled during the wait or the semaphore's
cancel()
method has been called, then rethrow the cancel.- Definition Classes
- CountingSemaphore → Semaphore
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
- val available: Int
-
def
cancel(): Unit
Interrupt each thread waiting to acquire this semaphore, and cause it to throw an
InterruptedException
.Interrupt each thread waiting to acquire this semaphore, and cause it to throw an
InterruptedException
. Mark the semaphore itself cancelled- Definition Classes
- CountingSemaphore → Semaphore
-
def
cancelled(): Boolean
Returns true if the semaphore was cancelled
Returns true if the semaphore was cancelled
- Definition Classes
- CountingSemaphore → Semaphore
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
down(): Unit
same as acquire
same as acquire
- Definition Classes
- Semaphore
- Annotations
- @inline()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- val fair: Boolean
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
getWaiting: Seq[Thread]
Return an (approximate) list of the threads waiting to acquire a token from this semaphore.
Return an (approximate) list of the threads waiting to acquire a token from this semaphore. Intended for use only by diagnostic components.
- Definition Classes
- CountingSemaphore → Semaphore
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- var name: String
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- val parent: AnyRef
-
def
reInitialize(): Unit
Reinitialize the semaphore to its as-new state.
-
def
release(): Unit
Add a token to the collection, then permit an
acquire
ing process to proceed if there is at least one token available.Add a token to the collection, then permit an
acquire
ing process to proceed if there is at least one token available.- Definition Classes
- CountingSemaphore → Semaphore
-
def
remaining(): Int
Approximation to the number of acquires that could now succeed without having to wait.
Approximation to the number of acquires that could now succeed without having to wait. Intended for use only by diagnostic components.
- Definition Classes
- CountingSemaphore → Semaphore
- val spin: Int
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- CountingSemaphore → AnyRef → Any
-
def
tryAcquire(timeoutNS: Long): Boolean
Wait until a token becomes available (returning true) or until the specified timeout has elapsed (returning false).
Wait until a token becomes available (returning true) or until the specified timeout has elapsed (returning false). Unlike
java.util.concurrent.Semaphore
an invoking thread that needs to wait joins the queue of waiting threads -- threads with shorter timeouts are not prioritised over those with longer deadlines or no deadline. If the acquiring thread is cancelled during the wait or the semaphore'scancel()
method has been called, then mark the semaphore as having been cancelled- Definition Classes
- CountingSemaphore → Semaphore
-
def
up(): Unit
same as release
same as release
- Definition Classes
- Semaphore
- Annotations
- @inline()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )