|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnachos.kernel.threads.Lock
public class Lock
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 |
---|
public final java.lang.String name
private Semaphore sem
private nachos.machine.NachosThread owner
Constructor Detail |
---|
public Lock(java.lang.String debugName)
debugName
- An arbitrary name, useful for debugging.Method Detail |
---|
public void acquire()
public void release()
public boolean isHeldByCurrentThread()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |