vdr
2.6.9
|
#include <thread.h>
Public Member Functions | |
cStateLock (const char *Name=NULL) | |
bool | Lock (cStateKey &StateKey, bool Write=false, int TimeoutMs=0) |
void | SetSyncStateKey (cStateKey &StateKey) |
void | SetExplicitModify (void) |
void | SetModified (void) |
Private Types | |
enum | { emDisabled = 0 , emArmed , emEnabled } |
Private Member Functions | |
void | Unlock (cStateKey &StateKey, bool IncState=true) |
Private Attributes | |
const char * | name |
tThreadId | threadId |
cRwLock | rwLock |
int | state |
int | explicitModify |
cStateKey * | syncStateKey |
Friends | |
class | cStateKey |
|
private |
cStateLock::cStateLock | ( | const char * | Name = NULL | ) |
Definition at line 713 of file thread.c.
References emDisabled, explicitModify, name, state, syncStateKey, and threadId.
bool cStateLock::Lock | ( | cStateKey & | StateKey, |
bool | Write = false , |
||
int | TimeoutMs = 0 |
||
) |
Tries to get a lock and returns true if successful.
If TimoutMs is not 0, it waits for the given number of milliseconds and returns false if no lock has been obtained within that time. Otherwise it waits indefinitely for the lock. The given StateKey will store which lock it has been used with, and will use that information when its Remove() function is called. There are two possible locks, one only for read access, and one for reading and writing:
If Write is false (i.e. a read-lock is requested), the lock's state is compared to the given StateKey's state, and true is returned if they differ. If true is returned, the read-lock is still in place and the protected data structures can be safely accessed (in read-only mode!). Once the necessary operations have been performed, the lock must be released by a call to the StateKey's Remove() function. If false is returned, the state has not changed since the last check, and the read-lock has been released. In that case the protected data structures have not changed since the last call, so no action is required. Note that if TimeoutMs is used with read-locks, Lock() might return false even if the states of lock and key differ, just because it was unable to obtain the lock within the given time. You can call cStateKey::TimedOut() to detect this.
If Write is true (i.e. a write-lock is requested), the states of the lock and the given StateKey don't matter, it will always try to obtain a write lock.
Definition at line 723 of file thread.c.
References ABORT, cBackTrace::BackTrace(), dbglocking, dbglockseq, dsyslog, esyslog, cRwLock::Lock(), name, rwLock, state, cStateKey::state, cStateKey::stateLock, cThread::ThreadId(), threadId, cStateKey::timedOut, cRwLock::Unlock(), and cStateKey::write.
Referenced by cListBase::Lock().
void cStateLock::SetExplicitModify | ( | void | ) |
If you have obtained a write lock on this lock, and you don't want its state to be automatically incremented when the lock is released, a call to this function will disable this, and you can explicitly call SetModified() to increment the state.
Definition at line 818 of file thread.c.
References ABORT, emArmed, emDisabled, esyslog, explicitModify, name, cThread::ThreadId(), and threadId.
Referenced by cListBase::SetExplicitModify().
void cStateLock::SetModified | ( | void | ) |
Sets this lock to have its state incremented when the current write lock state key is removed.
Must have called SetExplicitModify() before calling this function.
Definition at line 833 of file thread.c.
References ABORT, emEnabled, esyslog, explicitModify, name, cThread::ThreadId(), and threadId.
Referenced by cListBase::SetModified().
void cStateLock::SetSyncStateKey | ( | cStateKey & | StateKey | ) |
Sets the given StateKey to be synchronized to the state of this lock.
The caller must currently hold a write lock on this lock, with a cStateKey that is different from the given StateKey. If, when removing the key that is holding the write lock, the StateKey's current state is the same as that of the lock, it will be increased together with the lock's state.
Definition at line 797 of file thread.c.
References ABORT, dbglocking, esyslog, name, cStateKey::stateLock, syncStateKey, cThread::ThreadId(), and threadId.
Referenced by cListBase::SetSyncStateKey().
|
private |
Releases a lock that has been obtained by a previous call to Lock() with the given StateKey.
If this was a write-lock, and IncState is true, the state of the lock will be incremented. In any case, the (new) state of the lock will be copied to the StateKey's state.
Definition at line 767 of file thread.c.
References ABORT, dbglocking, dbglockseq, emArmed, emDisabled, emEnabled, esyslog, explicitModify, name, rwLock, state, cStateKey::state, cStateKey::stateLock, syncStateKey, cThread::ThreadId(), threadId, cRwLock::Unlock(), and cStateKey::write.
Referenced by cStateKey::Remove().
|
private |
Definition at line 179 of file thread.h.
Referenced by cStateLock(), SetExplicitModify(), SetModified(), and Unlock().
|
private |
Definition at line 175 of file thread.h.
Referenced by cStateLock(), Lock(), SetExplicitModify(), SetModified(), SetSyncStateKey(), Unlock(), and cStateKey::~cStateKey().
|
private |
|
private |
Definition at line 178 of file thread.h.
Referenced by cStateLock(), Lock(), cStateKey::StateChanged(), and Unlock().
|
private |
Definition at line 180 of file thread.h.
Referenced by cStateLock(), SetSyncStateKey(), and Unlock().
|
private |
Definition at line 176 of file thread.h.
Referenced by cStateLock(), Lock(), SetExplicitModify(), SetModified(), SetSyncStateKey(), Unlock(), and cStateKey::~cStateKey().