Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

Semaphore Class Reference

This is your classic semaphore, used to implement synchronization between tasks. More...

#include <semaphore.h>

Collaboration diagram for Semaphore:

Collaboration graph
[legend]
List of all members.

Public Member Functions

void init (unsigned start_value=1)
bool acquire (unsigned timeout=0)
bool try_acquire ()
bool release ()
void remove_task (Task *task)
void print ()

Protected Attributes

List< Taskwaiting_tasks
unsigned value

Detailed Description

This is your classic semaphore, used to implement synchronization between tasks.

Acquiring a semaphore that is already acquired causes the call to block until the semaphore becomes released.


Member Function Documentation

bool Semaphore::acquire unsigned  timeout = 0  ) 
 

Lock this semaphore.

If it's already locked, first block until it becomes unlocked and return true. An optional timeout in milliseconds can be given. If a timeout occurs before the lock is successful, return false.

void Semaphore::init unsigned  start_value = 1  ) 
 

Initialize this semaphore's default value.

Setting a default value higher than 1 means that the semaphore can be acquire()d multiple times before subsequent acquire() invocations block. Setting a default value of 0 means that every acquire() call to this semaphore will block.

void Semaphore::print  ) 
 

Print basic information about this semaphore.

bool Semaphore::release  ) 
 

Unlock this semaphore and wake up one thread that is waiting to acquire it.

Return true if there was a thread to wake up.

void Semaphore::remove_task Task task  ) 
 

Remove a task from this semaphore's waiting task list.

bool Semaphore::try_acquire  ) 
 

Attempt to lock this semaphore without blocking.

Return true on success or false if it is already locked.


Member Data Documentation

unsigned Semaphore::value [protected]
 

current value of this semaphore

List<Task> Semaphore::waiting_tasks [protected]
 

tasks waiting for this semaphore


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

Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman