Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itk::Semaphore Class Reference

#include <itkSemaphore.h>

Inheritance diagram for itk::Semaphore:

Inheritance graph
[legend]
Collaboration diagram for itk::Semaphore:

Collaboration graph
[legend]
List of all members.

Detailed Description

The semaphore class is used to synchronize execution between threads.

Semaphore objects maintain a counter value that can be incremented and decremented by atomic calls to Up() and Down(). Semaphores are commonly used to manage the use of a limited pool of system resources among several threads. If Down() is called when the value of the semaphore is zero, the calling thread will block until the semaphore value goes above zero again. When a blocked thread is released, it decrements the Semaphore counter before continuing to execute.

The Up() and Down() operations are standard as defined by E.W. Dijkstra. The Initialize( num ) operation creates the system semaphore object with an initial counter value of num. Initialize must be called before the Semaphore can be used. The Remove() method destroys the system semaphore object. It is not necessary to call Remove() unless you want to re-Initialize() the object.

This class supports 3 types of semaphores on Unix systems, POSIX semaphores, IPC semaphores, and IRIX semaphores from the SGI Sproc library. On Windows systems, POSIX semaphores and WIN32 thread library semaphores are supported.

Definition at line 112 of file itkSemaphore.h.

Public Types

typedef SmartPointer< const
Self
ConstPointer
typedef SmartPointer< SelfPointer
typedef Semaphore Self
typedef LightObject Superclass

Public Member Functions

virtual Pointer CreateAnother () const
virtual void Delete ()
void Down ()
virtual const char * GetNameOfClass () const
virtual int GetReferenceCount () const
void Initialize (unsigned int value)
void Print (std::ostream &os, Indent indent=0) const
virtual void Register () const
void Remove ()
virtual void SetReferenceCount (int)
virtual void UnRegister () const
void Up ()

Static Public Member Functions

static void BreakOnError ()
static Pointer New ()

Protected Member Functions

virtual void PrintTrailer (std::ostream &os, Indent indent) const
 Semaphore ()
 ~Semaphore ()

Protected Attributes

int m_ReferenceCount
SimpleFastMutexLock m_ReferenceCountLock
Methods invoked by virtual
Print() to print information
about the object *including
superclasses.Typically not
called by the user(use Print()*instead) but used in the
hierarchical print process
to combine the *output of
several classes.*/virtual
void PrintSelf(std voi 
PrintHeader )(std::ostream &os, Indent indent) const


Member Typedef Documentation

typedef SmartPointer<const Self> itk::Semaphore::ConstPointer
 

Reimplemented from itk::LightObject.

Definition at line 119 of file itkSemaphore.h.

typedef SmartPointer<Self> itk::Semaphore::Pointer
 

Reimplemented from itk::LightObject.

Definition at line 118 of file itkSemaphore.h.

typedef Semaphore itk::Semaphore::Self
 

Standard class typedefs.

Reimplemented from itk::LightObject.

Definition at line 116 of file itkSemaphore.h.

typedef LightObject itk::Semaphore::Superclass
 

Definition at line 117 of file itkSemaphore.h.


Constructor & Destructor Documentation

itk::Semaphore::Semaphore  )  [protected]
 

itk::Semaphore::~Semaphore  )  [protected]
 


Member Function Documentation

static void itk::LightObject::BreakOnError  )  [static, inherited]
 

This method is called when itkExceptionMacro executes. It allows the debugger to break on error.

virtual Pointer itk::LightObject::CreateAnother  )  const [virtual, inherited]
 

Create an object from an instance, potentially deferring to a factory. This method allows you to create an instance of an object that is exactly the same type as the referring object. This is useful in cases where an object has been cast back to a base class.

Reimplemented in itk::Object.

virtual void itk::LightObject::Delete  )  [virtual, inherited]
 

Delete an itk object. This method should always be used to delete an object when the new operator was used to create it. Using the C delete method will not work with reference counting.

void itk::Semaphore::Down  ) 
 

Decrement the semaphore count. If the count is zero, this thread will be blocked until another thread calls the up() method. The order in which threads will be unblocked is not defined, but implementors should give preference to those threads that have waited the longest.

virtual const char* itk::Semaphore::GetNameOfClass  )  const [virtual]
 

Run-time type information (and related methods).

Reimplemented from itk::LightObject.

virtual int itk::LightObject::GetReferenceCount  )  const [inline, virtual, inherited]
 

Gets the reference count on this object.

Definition at line 98 of file itkLightObject.h.

void itk::Semaphore::Initialize unsigned int  value  ) 
 

Initialize the semaphore with a count of value.

static Pointer itk::Semaphore::New  )  [static]
 

Method for creation through the object factory.

Reimplemented from itk::LightObject.

void itk::LightObject::Print std::ostream &  os,
Indent  indent = 0
const [inherited]
 

Cause the object to print itself out.

virtual void itk::LightObject::PrintTrailer std::ostream &  os,
Indent  indent
const [protected, virtual, inherited]
 

virtual void itk::LightObject::Register  )  const [virtual, inherited]
 

Increase the reference count (mark as used by another object).

Reimplemented in itk::Object.

void itk::Semaphore::Remove  ) 
 

Remove the semaphore from the system.

virtual void itk::LightObject::SetReferenceCount int   )  [virtual, inherited]
 

Sets the reference count on this object. This is a dangerous method, use it with care.

Reimplemented in itk::Object.

virtual void itk::LightObject::UnRegister  )  const [virtual, inherited]
 

Decrease the reference count (release by another object).

Reimplemented in itk::Object.

void itk::Semaphore::Up  ) 
 

Increment the semaphore count, unblocking up to one thread that may be blocked in the down() method.


Member Data Documentation

int itk::LightObject::m_ReferenceCount [mutable, protected, inherited]
 

Number of uses of this object by other objects.

Definition at line 119 of file itkLightObject.h.

SimpleFastMutexLock itk::LightObject::m_ReferenceCountLock [mutable, protected, inherited]
 

Mutex lock to protect modification to the reference count

Definition at line 122 of file itkLightObject.h.

Methods invoked by virtual Print () to print information about the object * including superclasses. Typically not called by the user (use Print() * instead) but used in the hierarchical print process to combine the * output of several classes. */ virtual void PrintSelf(std voi itk::LightObject::PrintHeader)(std::ostream &os, Indent indent) const [protected, inherited]
 


The documentation for this class was generated from the following file:
Generated at Sun Jul 9 21:23:05 2006 for ITK by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2000