nachos.kernel.threads
Class Lock

java.lang.Object
  extended by nachos.kernel.threads.Lock

public class Lock
extends java.lang.Object

This class defines a "lock". A lock can be BUSY or FREE. There are only two operations allowed on a lock: Acquire -- wait until the lock is FREE, then set it to BUSY. Release -- set lock to be FREE, waking up a thread waiting in Acquire if necessary. In addition, by convention, only the thread that acquired the lock may release it. As with semaphores, you can't read the lock value (because the value might change immediately after you read it).


Field Summary
 java.lang.String name
          Printable name useful for debugging.
private  nachos.machine.NachosThread owner
          Which thread currently holds this lock?
private  Semaphore sem
          semaphore used for implementation of lock.
 
Constructor Summary
Lock(java.lang.String debugName)
          Initialize a lock.
 
Method Summary
 void acquire()
          Wait until the lock is "free", then set the lock to "busy".
 boolean isHeldByCurrentThread()
          A predicate that determines whether or not the lock is held by the current thread.
 void release()
          Release the lock that was previously acquired, waking up a waiting thread if necessary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

public final java.lang.String name
Printable name useful for debugging.


sem

private Semaphore sem
semaphore used for implementation of lock.


owner

private nachos.machine.NachosThread owner
Which thread currently holds this lock?

Constructor Detail

Lock

public Lock(java.lang.String debugName)
Initialize a lock.

Parameters:
debugName - An arbitrary name, useful for debugging.
Method Detail

acquire

public void acquire()
Wait until the lock is "free", then set the lock to "busy".


release

public void release()
Release the lock that was previously acquired, waking up a waiting thread if necessary.


isHeldByCurrentThread

public boolean isHeldByCurrentThread()
A predicate that determines whether or not the lock is held by the current thread. Used for sanity checks in condition variables.