public class Monitor extends Object
It is perfectly safe to use this throughout the VM for locking. It is meant to provide roughly the same functionality as Java monitors, except:
unlock()
and broadcast()
)
or will block without letting anyone know (like lockNoHandshake()
and waitNoHandshake()
). Not letting the threading
system know that you are blocked may cause things like GC to stall
until you unblock.Modifier and Type | Field and Description |
---|---|
int |
acquireCount |
(package private) int |
holderSlot |
(package private) Word |
monitor |
(package private) int |
recCount |
Constructor and Description |
---|
Monitor()
Allocate a heavy condition variable and lock.
|
Modifier and Type | Method and Description |
---|---|
void |
broadcast()
Send a broadcast, which should awaken anyone who is currently blocked
in any of the wait methods.
|
protected void |
finalize()
Frees the data structures that were allocated in C code
when the object was created.
|
void |
lockedBroadcastNoHandshake()
Send a broadcast after first acquiring the lock.
|
void |
lockNoHandshake()
Wait until it is possible to acquire the lock and then acquire it.
|
static boolean |
lockNoHandshake(Monitor l) |
void |
lockWithHandshake()
Wait until it is possible to acquire the lock and then acquire it.
|
static void |
lockWithHandshake(Monitor m1,
Word priority1,
Monitor m2,
Word priority2) |
private void |
lockWithHandshakeNoRec() |
private void |
lockWithHandshakeNoRecImpl() |
void |
relockNoHandshake(int recCount)
Relocks the mutex after using
unlockCompletely() . |
void |
relockWithHandshake(int recCount)
Relocks the mutex after using
unlockCompletely() and notify
the threading subsystem. |
private void |
relockWithHandshakeImpl(int recCount) |
void |
timedWaitAbsoluteNoHandshake(long whenWakeupNanos)
Wait until someone calls
broadcast() , or until the clock
reaches the given time. |
void |
timedWaitAbsoluteWithHandshake(long whenWakeupNanos)
Wait until someone calls
broadcast() , or until the clock
reaches the given time. |
private void |
timedWaitAbsoluteWithHandshakeImpl(long whenWakeupNanos) |
void |
timedWaitRelativeNoHandshake(long delayNanos)
Wait until someone calls
broadcast() , or until at least
the given number of nanoseconds pass. |
void |
timedWaitRelativeWithHandshake(long delayNanos)
Wait until someone calls
broadcast() , or until at least the given
number of nanoseconds pass. |
private void |
timedWaitRelativeWithHandshakeImpl(long delayNanos) |
void |
unlock()
Release the lock.
|
static void |
unlock(boolean b,
Monitor l) |
int |
unlockCompletely()
Completely releases the lock, ignoring recursion.
|
void |
waitNoHandshake()
Wait until someone calls
broadcast() . |
void |
waitWithHandshake()
Wait until someone calls
broadcast() . |
private void |
waitWithHandshakeImpl() |
int holderSlot
int recCount
public int acquireCount
public Monitor()
protected void finalize() throws Throwable
public void lockNoHandshake()
This blocking method method does not notify the threading subsystem
that it is blocking. Thus, if someone (like, say, the GC) requests
that the thread is blocked then their request will block until this
method unblocks. If this sounds like it might be undesirable, call
lockWithHandshake()
instead.
public void relockNoHandshake(int recCount)
unlockCompletely()
.recCount
- the recursion countpublic void lockWithHandshake()
This blocking method method notifies the threading subsystem that it is blocking. Thus, it may be safer than calling lock. But, its reliance on threading subsystem accounting methods may mean that it cannot be used in certain contexts (say, the threading subsystem itself).
This method will ensure that if it blocks, it does so with the mutex not held. This is useful for cases where the subsystem that requested you to block needs to acquire the lock you were trying to acquire when the blocking request came.
It is usually not necessary to call this method instead of
lockNoHandshake()
since most VM locks are held for short
periods of time.
private void lockWithHandshakeNoRec()
private void lockWithHandshakeNoRecImpl()
public void relockWithHandshake(int recCount)
unlockCompletely()
and notify
the threading subsystem.recCount
- the recursion countprivate void relockWithHandshakeImpl(int recCount)
public void unlock()
public int unlockCompletely()
public void waitNoHandshake()
broadcast()
.
This blocking method method does not notify the threading subsystem
that it is blocking. Thus, if someone (like, say, the GC) requests
that the thread is blocked then their request will block until this
method unblocks. If this sounds like it might be undesirable, call
waitWithHandshake()
instead.
public void timedWaitAbsoluteNoHandshake(long whenWakeupNanos)
broadcast()
, or until the clock
reaches the given time.
This blocking method method does not notify the threading subsystem
that it is blocking. Thus, if someone (like, say, the GC) requests
that the thread is blocked then their request will block until this
method unblocks. If this sounds like it might be undesirable, call
timedWaitAbsoluteWithHandshake(long)
instead.
whenWakeupNanos
- the absolute time point that must be reached
before the wait is over when no call to broadcast()
occurs
in the meantimepublic void timedWaitRelativeNoHandshake(long delayNanos)
broadcast()
, or until at least
the given number of nanoseconds pass.
This blocking method method does not notify the threading subsystem
that it is blocking. Thus, if someone (like, say, the GC) requests
that the thread is blocked then their request will block until this
method unblocks. If this sounds like it might be undesirable, call
timedWaitRelativeWithHandshake(long)
instead.
delayNanos
- the number of nanoseconds that need to pass
from the call of this method until the wait is over when no call
to broadcast()
occurs in the meantimepublic void waitWithHandshake()
broadcast()
.
This blocking method notifies the threading subsystem that it
is blocking. Thus, it is generally safer than calling
waitNoHandshake()
. But, its reliance on threading subsystem
accounting methods may mean that it cannot be used in certain contexts
(say, the threading subsystem itself).
This method will ensure that if it blocks, it does so with the mutex not held. This is useful for cases where the subsystem that requested you to block needs to acquire the lock you were trying to acquire when the blocking request came.
private void waitWithHandshakeImpl()
public void timedWaitAbsoluteWithHandshake(long whenWakeupNanos)
broadcast()
, or until the clock
reaches the given time.
This blocking method method notifies the threading subsystem that it
is blocking. Thus, it is generally safer than calling
timedWaitAbsoluteNoHandshake(long)
. But, its reliance on
threading subsystem accounting methods may mean that it cannot be
used in certain contexts (say, the threading subsystem itself).
This method will ensure that if it blocks, it does so with the mutex not held. This is useful for cases where the subsystem that requested you to block needs to acquire the lock you were trying to acquire when the blocking request came.
whenWakeupNanos
- the absolute time point that must be reached
before the wait is over when no call to broadcast()
occurs
in the meantimeprivate void timedWaitAbsoluteWithHandshakeImpl(long whenWakeupNanos)
public void timedWaitRelativeWithHandshake(long delayNanos)
broadcast()
, or until at least the given
number of nanoseconds pass.
This blocking method method notifies the threading subsystem that it
is blocking. Thus, it is generally safer than calling
timedWaitRelativeWithHandshake(long)
. But, its reliance on
threading subsystem accounting methods may mean that it cannot be used
in certain contexts (say, the threading subsystem itself).
This method will ensure that if it blocks, it does so with the mutex not held. This is useful for cases where the subsystem that requested you to block needs to acquire the lock you were trying to acquire when the blocking request came.
delayNanos
- the number of nanoseconds that need to pass
from the call of this method until the wait is over when no call
to broadcast()
occurs in the meantimeprivate void timedWaitRelativeWithHandshakeImpl(long delayNanos)
public void broadcast()
public void lockedBroadcastNoHandshake()
broadcast()
.public static boolean lockNoHandshake(Monitor l)
public static void lockWithHandshake(Monitor m1, Word priority1, Monitor m2, Word priority2)