semaphore which can be used for asynchronous thread communication. By using this class it is possible to realize timeouts.
More...
|
| ItomSharedSemaphore (int numberOfListeners=1) |
| constructor
|
|
| ~ItomSharedSemaphore () |
| destructor (do not call directly, instead free the semaphore by ItomSharedSemaphore::deleteSemaphore
|
|
bool | wait (int timeout) |
| The call of this method returns if a certain timeout has been expired or every listener released the semaphore.
|
|
bool | waitAndProcessEvents (int timeout, QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents) |
| The call of this method returns if a certain timeout has been expired or every listener released the semaphore.
|
|
void | release () |
| decreases the number of locks by one
|
|
int | available () const |
| checks whether the semaphore is still locked or not
|
|
bool | isCallerStillWaiting () |
| indicates whether caller-method is still waiting that the lock is released by the listener(s).
|
|
void | deleteSemaphore (void) |
| static method to decrease the reference counter of any ItomSharedSemaphore or delete it if the reference counter drops to zero
|
|
semaphore which can be used for asynchronous thread communication. By using this class it is possible to realize timeouts.
This semaphore is usually applied if any method invokes another method in another thread and should wait for the called method being terminated or the waiting routine drops into a possible timeout. Therefore, the calling method must create an instance of ItomSharedSemaphore with a number of listeners equal to one. Then, the pointer to ItomSharedSemaphore is transmitted to the called method (usually as last argument). If the called method is done or wants the caller to continue the release-method of ItomSharedSemaphore is called. The calling method calls the wait-method of the semaphore which blocks the method until the semaphore is released. Finally, both the caller and the calling method must call ItomSharedSemaphore::deleteSemaphore in order to decrease the reference counter from two to zero, which allows the system to delete the semaphore.
Consider to guard an instance of ItomSharedSemaphore by the capsule-class ItomSharedSemaphoreLocker both in the caller and calling method, such that the decrease of the reference counter is executed if the ItomSharedSemaphoreLocker-variables are deleted, e.g. if they run out of scope, which is even after the return-command of any method.