Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Lock Class Reference

The following 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). More...

#include <synch.h>

List of all members.

Public Methods

 Lock (char *debugName)
 initialize lock to be FREE. More...

 ~Lock ()
 deallocate lock. More...

char* getName ()
 debugging assist. More...

void Acquire ()
 these are the only operations on a lock. More...

void Release ()
 they are both *atomic*. More...

bool IsHeldByCurrentThread ()
 return true if the current thread holds this lock. More...


Private Attributes

char* name
 debugging assist. More...

ThreadlockHolder
 thread currently holding lock. More...

Semaphoresemaphore
 we use a semaphore to implement lock. More...


Detailed Description

The following 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).

Definition at line 69 of file synch.h.


Constructor & Destructor Documentation

Lock::Lock ( char * debugName )
 

initialize lock to be FREE.

Lock::Lock Initialize a lock, so that it can be used for synchronization. Initially, unlocked.

"debugName" is an arbitrary name, useful for debugging.

Definition at line 158 of file synch.cc.

Lock::~Lock ( )
 

deallocate lock.

Lock::~Lock Deallocate a lock

Definition at line 169 of file synch.cc.


Member Function Documentation

void Lock::Acquire ( )
 

these are the only operations on a lock.

Lock::Acquire Atomically wait until the lock is free, then set it to busy. Equivalent to Semaphore::P(), with the semaphore value of 0 equal to busy, and semaphore value of 1 equal to free.

Definition at line 181 of file synch.cc.

Referenced by SynchList::Append(), SynchConsoleInput::GetChar(), SynchConsoleOutput::PutChar(), SynchDisk::ReadSector(), SynchList::RemoveFront(), PostOfficeOutput::Send(), Condition::Wait(), and SynchDisk::WriteSector().

bool Lock::IsHeldByCurrentThread ( ) [inline]
 

return true if the current thread holds this lock.

Definition at line 78 of file synch.h.

Referenced by Release(), Condition::Signal(), and Condition::Wait().

void Lock::Release ( )
 

they are both *atomic*.

Lock::Release Atomically set lock to be free, waking up a thread waiting for the lock, if any. Equivalent to Semaphore::V(), with the semaphore value of 0 equal to busy, and semaphore value of 1 equal to free.

By convention, only the thread that acquired the lock may release it.

Definition at line 198 of file synch.cc.

Referenced by SynchList::Append(), SynchConsoleInput::GetChar(), SynchConsoleOutput::PutChar(), SynchDisk::ReadSector(), SynchList::RemoveFront(), PostOfficeOutput::Send(), Condition::Wait(), and SynchDisk::WriteSector().

char * Lock::getName ( ) [inline]
 

debugging assist.

Definition at line 73 of file synch.h.


Member Data Documentation

Thread * Lock::lockHolder [private]
 

thread currently holding lock.

Definition at line 87 of file synch.h.

char * Lock::name [private]
 

debugging assist.

Definition at line 86 of file synch.h.

Semaphore * Lock::semaphore [private]
 

we use a semaphore to implement lock.

Definition at line 88 of file synch.h.


The documentation for this class was generated from the following files:
Generated at Wed Jul 4 11:32:23 2001 for Nachos by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001