vdr 2.6.8
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
cStateLock Class Reference

#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
 
cStateKeysyncStateKey
 

Friends

class cStateKey
 

Detailed Description

Definition at line 171 of file thread.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
emDisabled 
emArmed 
emEnabled 

Definition at line 174 of file thread.h.

Constructor & Destructor Documentation

◆ cStateLock()

cStateLock::cStateLock ( const char * Name = NULL)

Definition at line 713 of file thread.c.

References emDisabled, explicitModify, name, state, syncStateKey, and threadId.

Member Function Documentation

◆ Lock()

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().

◆ SetExplicitModify()

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().

◆ SetModified()

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().

◆ SetSyncStateKey()

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().

◆ Unlock()

void cStateLock::Unlock ( cStateKey & StateKey,
bool IncState = true )
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().

Friends And Related Symbol Documentation

◆ cStateKey

friend class cStateKey
friend

Definition at line 172 of file thread.h.

Member Data Documentation

◆ explicitModify

int cStateLock::explicitModify
private

Definition at line 179 of file thread.h.

Referenced by cStateLock(), SetExplicitModify(), SetModified(), and Unlock().

◆ name

const char* cStateLock::name
private

◆ rwLock

cRwLock cStateLock::rwLock
private

Definition at line 177 of file thread.h.

Referenced by Lock(), and Unlock().

◆ state

int cStateLock::state
private

Definition at line 178 of file thread.h.

Referenced by cStateLock(), Lock(), cStateKey::StateChanged(), and Unlock().

◆ syncStateKey

cStateKey* cStateLock::syncStateKey
private

Definition at line 180 of file thread.h.

Referenced by cStateLock(), SetSyncStateKey(), and Unlock().

◆ threadId

tThreadId cStateLock::threadId
private

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