Inherits DD::Image::Lock.
Public Member Functions | |
void | signal () |
void | signal_one () |
bool | wait (unsigned long timeoutms=0) |
void | spinsignal () |
void | spinwait () |
This class combines a lock with a pthreads condition. This allows one thread to wait until another thread has modified the data that is protected by the lock.
DD::Image::SignalLock::signal | ( | ) | [inline] |
You must lock() the SignalLock before calling this! This will send a signal to any other threads that are currently inside of wait(). Note that those threads will not get out of wait() until this thread does unlock().
Referenced by DD::Image::FileReader::unlock().
DD::Image::SignalLock::signal_one | ( | ) | [inline] |
DD::Image::SignalLock::wait | ( | unsigned long | timeoutms = 0 | ) | [inline] |
You must lock() the SignalLock exactly once before calling this! This unlocks the lock, then waits for another thread to call signal(). This then calls lock() and returns.
If timeoutms is specified it will wait up to timeoutms milliseconds before returning. It will return true if the thread is signalled and return false if the timeout occurred. A timeoutms of 0 ( the default ) means wait indefinitely.
Note: On windows this may also return even if signal() is not called. You should always check the data protected by the lock to make sure it is correct, if not you should run wait() again.
Referenced by DD::Image::FileReader::lock().
DD::Image::SignalLock::spinsignal | ( | ) | [inline] |
Same as signal(), this can be used if you know the other thread is doing spinwait(). On all platforms currently this is a no-op.
Reimplemented from DD::Image::Lock.
DD::Image::SignalLock::spinwait | ( | ) | [inline] |
Same as wait() but it executes by spinning in a loop in this thread. This is faster if you expect the other thread to signal very soon and for it to then quickly unlock().
Reimplemented from DD::Image::Lock.