tron
Class VirtualLock

java.lang.Object
  extended by tron.VirtualLock
All Implemented Interfaces:
Lock

public class VirtualLock
extends Object
implements Lock

VirtualLock replaces the Lock when running within virtual time framework. If the VirtualThread is configured to run without virtual clock, then internal ReentrantLock (and its Conditions) is created. Only threads originating from VirtualThread object can create and manipulate instances of VirtualLock.

See Also:
VirtualThread, VirtualCondition, Lock, Condition

Field Summary
protected  int id
          The id of this lock in a remote virtual clock process.
protected  VirtualThread owner
          Current owner thread of this lock, null if not owned.
 
Constructor Summary
VirtualLock()
          Creates a virtual lock which is located at virtual clock process.
VirtualLock(String name)
          Creates a virtual lock which is located at virtual clock process.
 
Method Summary
 String getName()
          Returns the name of this lock.
 VirtualThread getOwner()
          Returns the owner thread of the lock if lock is acquired, returns null if lock is not owned/acquired.
 boolean isLocked()
          Checks whether this lock is acquired/owned/locked.
 void lock()
          Acquires the oqnership of this lock.
 void lockInterruptibly()
          Not implemented in virtual time framework.
 Condition newCondition()
          Creates a condition variable associated with this lock.
 Condition newCondition(String name)
          Creates a named condition variable associated with this lock.
 void setOwner(VirtualThread t)
          Sets the owner of this lock.
 boolean tryLock()
          Not implemented in virtual time framework.
 boolean tryLock(long time, TimeUnit unit)
          Not implemented in virtual time framework.
 void unlock()
          Releases this lock and lets any waiting thread to acquire it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

protected final int id
The id of this lock in a remote virtual clock process.


owner

protected VirtualThread owner
Current owner thread of this lock, null if not owned.

Constructor Detail

VirtualLock

public VirtualLock(String name)
Creates a virtual lock which is located at virtual clock process.

Parameters:
name - specify your friendly name to identify it in debug logs.
See Also:
VirtualThread.DBG

VirtualLock

public VirtualLock()
Creates a virtual lock which is located at virtual clock process. The name will be inherited from the creating VirtualThread with "-lock" appended.

See Also:
VirtualThread.DBG
Method Detail

getName

public String getName()
Returns the name of this lock.


getOwner

public VirtualThread getOwner()
Returns the owner thread of the lock if lock is acquired, returns null if lock is not owned/acquired.


setOwner

public void setOwner(VirtualThread t)
Sets the owner of this lock. This method should be used with caution, currently only VirtualCondition has reasonable use of this method.


isLocked

public boolean isLocked()
Checks whether this lock is acquired/owned/locked.


lock

public void lock()
Acquires the oqnership of this lock. The thread blocks until the lock is released.

Specified by:
lock in interface Lock

lockInterruptibly

public void lockInterruptibly()
Not implemented in virtual time framework.

Specified by:
lockInterruptibly in interface Lock

tryLock

public boolean tryLock()
Not implemented in virtual time framework.

Specified by:
tryLock in interface Lock

tryLock

public boolean tryLock(long time,
                       TimeUnit unit)
Not implemented in virtual time framework.

Specified by:
tryLock in interface Lock

newCondition

public Condition newCondition()
Creates a condition variable associated with this lock.

Specified by:
newCondition in interface Lock

newCondition

public Condition newCondition(String name)
Creates a named condition variable associated with this lock. The name of condition will appear in virtual thread debug logs.

See Also:
VirtualThread.DBG

unlock

public void unlock()
Releases this lock and lets any waiting thread to acquire it.

Specified by:
unlock in interface Lock