QSemaphore Class Reference

List of all members.


Detailed Description

implementation of semaphores

Author:
Sergio Di Domizio This class handles a single semaphore that can be only in two states: Locked or Unlocked.

Public Member Functions

 QSemaphore ()
 default ctor
 QSemaphore (bool owner, int semId)
 ctor with semaphore initialization
virtual ~QSemaphore ()
 dtor
bool Init (bool owner, int semId)
 initialize semaphore
bool Lock (bool lock)
 lock semaphore
bool IsLocked (bool &result)
 check whether semaphore is currently locked
bool CanLock (bool &result)
 inverse of IsLocked()
bool SetTimeout (long timeoutMs)
 set timeout to use when trying to lock semaphore
long GetTimeout () const
 get timeout in ms
const QErrorGetError ()
 get error associated to the last operation

Private Attributes

int fSemHandle
int fSemId
long fTimeoutMs
bool fOwner
QError fError

Classes

union  semun
 this union is needed by semctl() (see man semctl) More...

Constructor & Destructor Documentation

QSemaphore::QSemaphore (  ) 

default ctor

When using this ctor the created object must be initialized using the Init() method before it can be used.

QSemaphore::QSemaphore ( bool  owner,
int  semId 
)

ctor with semaphore initialization

Parameters:
owner whether this instance is the owner of the semaphore
semId semaphore id
This ctor calls the Init() method within its body and throws a QError if it fails.

References Init().


Member Function Documentation

bool QSemaphore::Init ( bool  owner,
int  semId 
)

initialize semaphore

Returns:
true on success
In case of failure the associated error can be obtained by calling GetError(). Possible ownership for the semaphore is set only if this method executes succesfully. When trying to initialize an already initialized semaphore, this method will return true without executing if owner and semId correspond to the previous initialization, false otherwise.

References fOwner, fSemHandle, fSemId, QError::Set(), and QSemaphore::semun::val.

Referenced by QGuiSharedMemory::QGuiSharedMemory(), and QSemaphore().

bool QSemaphore::Lock ( bool  lock  ) 

lock semaphore

Returns:
true on success
Semaphore can be locked only if it is unlocked. Trying to unlock an already unlocked semaphore will return true without actually modifying the semaphore status.

References fSemHandle, fTimeoutMs, IsLocked(), and QError::Set().

Referenced by QTimerDispatcher::ExecuteThread(), QGuiSharedMemory::GetValue(), and QGuiSharedMemory::SetValue().

bool QSemaphore::IsLocked ( bool &  result  ) 

check whether semaphore is currently locked

Parameters:
result filled with current semaphore status (locked or not)
Returns:
true on success

References fSemHandle, and QError::Set().

Referenced by CanLock(), and Lock().

bool QSemaphore::SetTimeout ( long  timeoutMs  ) 

set timeout to use when trying to lock semaphore

Parameters:
timeoutMs timeout in ms in range 0..1000 (0 means no wait).
Returns:
true unless requested value is out of range;

References fTimeoutMs.


Member Data Documentation

int QSemaphore::fSemHandle [private]

semaphore handler

Referenced by Init(), IsLocked(), Lock(), and ~QSemaphore().

int QSemaphore::fSemId [private]

semaphore id

Referenced by Init(), and ~QSemaphore().

long QSemaphore::fTimeoutMs [private]

semaphore lock timeout in ms: 0 means no wait, -1 means wait forever

Referenced by GetTimeout(), Lock(), and SetTimeout().

bool QSemaphore::fOwner [private]

whether this objet is the owner of the semaphore

Referenced by Init(), and ~QSemaphore().


The documentation for this class was generated from the following files:

Generated on Tue Nov 16 10:50:08 2010 for CUORE Software by  doxygen 1.5.6