#include <semaphore.h>
Inheritance diagram for semaphore:


Public Member Functions | |
| semaphore (int concurrent_locks, int initial_locks_available) | |
| constructs a semaphore allowing "concurrent_locks" on an object. | |
| virtual | ~semaphore () |
| NOTE: do not destroy the semaphore while it is still locked. | |
| IMPLEMENT_CLASS_NAME ("semaphore") | |
| void | wait () |
| clamps down on the semaphore, if possible. | |
| void | signal () |
| gives up the possession of the semaphore. | |
| void | P () |
| synonym for wait(); P stands for "proberen", meaning to test or probe. | |
| void | V () |
| virtual void | establish_lock () |
| virtual void | repeal_lock () |
Provides a simple semaphore object that allows locking of a limited number of resources between threads. It has a maximum number of locks that can be granted, and threads can grab these until the locks are used up. At that point, they block until a lock becomes available.
Definition at line 30 of file semaphore.h.
| semaphore::semaphore | ( | int | concurrent_locks, | |
| int | initial_locks_available | |||
| ) |
constructs a semaphore allowing "concurrent_locks" on an object.
the "concurrent_locks" parameter specifies how many times the semaphore can be locked before putting a thread on hold. the "initial_locks_available" is the number of users that the semaphore can initially support; it is commonly the same as the "concurrent_locks" parameter. note that nutty values are dismissed; "concurrent_locks" cannot be less than one and "initial_locks_available" must be between zero and "concurrent_locks" inclusively.
Definition at line 34 of file semaphore.cpp.
| semaphore::~semaphore | ( | ) | [virtual] |
NOTE: do not destroy the semaphore while it is still locked.
Definition at line 50 of file semaphore.cpp.
References NIL.
| semaphore::IMPLEMENT_CLASS_NAME | ( | "semaphore" | ) |
| void semaphore::wait | ( | ) |
clamps down on the semaphore, if possible.
otherwise the thread is blocked until the semaphore is signalled. the number of threads that can successfully wait on the semaphore depends on the number of concurrent locks that were allowed in the constructor, as well as on the number of threads that are currently using the semaphore.
Definition at line 62 of file semaphore.cpp.
References mutex_base::lock(), non_positive(), portable::sleep_ms(), and mutex_base::unlock().
Referenced by establish_lock(), and drawing_window::lock().
| void semaphore::signal | ( | ) |
gives up the possession of the semaphore.
potentially allows another thread to use the semaphore, if the thread was waiting.
Definition at line 73 of file semaphore.cpp.
References FUNCDEF, mutex_base::lock(), LOG, and mutex_base::unlock().
Referenced by repeal_lock(), and drawing_window::unlock().
| void semaphore::P | ( | ) | [inline] |
synonym for wait(); P stands for "proberen", meaning to test or probe.
Definition at line 61 of file semaphore.h.
| void semaphore::V | ( | ) | [inline] |
Definition at line 63 of file semaphore.h.
| void semaphore::establish_lock | ( | ) | [virtual] |
| void semaphore::repeal_lock | ( | ) | [virtual] |
1.5.1