MDAT  1.0
 All Classes Files Functions Variables Typedefs Pages
SemaphoreManager Class Reference

Semaphore manager. More...

Public Member Functions

void addSemaphore (const char *name, sem_t *sem, int value)
 Registers a new semaphore. More...
 
void waitSemaphore (int id, sem_t *sem)
 Implements the wait operation for a semaphore. More...
 
void signalSemaphore (int id, sem_t *sem)
 Implements the signal (post) operation for a semaphore. More...
 
string getSemaphoreTable () const
 Returns the semaphore table in a string. More...
 

Detailed Description

The semaphore manager is responsible for managing the semaphores used during the concurrent sections of the program. Each semaphore must first be registered using addSemaphore. The state of semaphores are adjusted via the waitSemaphore and signalSemaphore methods.

Member Function Documentation

void SemaphoreManager::addSemaphore ( const char *  name,
sem_t *  sem,
int  value 
)

Registers a new semaphore.

Parameters
[in]namename of semaphore
[in]semsemaphore variable
[in]valueinitial value of semaphore
void SemaphoreManager::waitSemaphore ( int  id,
sem_t *  sem 
)

Decrement the semaphore. If the value is negative, the thread must wait until woken up by a subsequent post operation.

Parameters
[in]idid of thread performing wait
[in]semsemaphore variable
void SemaphoreManager::signalSemaphore ( int  id,
sem_t *  sem 
)

Increment the semaphore. If one or more threads are waiting, one thread will be woken up.

Parameters
[in]idid of thread performing signal (post)
[in]semsemaphore variable
string SemaphoreManager::getSemaphoreTable ( ) const

Returns the semaphore table in a string in a trace-friendly format.

This is a personal WEB site developed and maintained by an individual and not by Seattle University. The content and link(s) provided on this site do not represent or reflect the view(s) of Seattle University. The individual who authored this site is solely responsible for the site's content. This site and its author are subject to applicable University policies including the Computer Acceptable Use Policy (www.seattleu.edu/policies).