15 #include <sys/types.h> 27 static void SleepMs(
int TimeoutMs);
33 bool Wait(
int TimeoutMs = 0);
61 cRwLock(
bool PreferWriter =
false);
63 bool Lock(
bool Write,
int TimeoutMs = 0);
96 virtual void Action(
void) = 0;
104 void Cancel(
int WaitSeconds = 0);
112 cThread(
const char *Description = NULL,
bool LowPriority =
false);
167 #define LOCK_THREAD cThreadLock ThreadLock(this) 188 bool Lock(
cStateKey &StateKey,
bool Write =
false,
int TimeoutMs = 0);
250 void Remove(
bool IncState =
true);
299 operator FILE* () {
return f; }
300 bool Open(
const char *Command,
const char *Mode);
323 static void BackTrace(FILE *f = NULL,
int Level = 0,
bool Mangled =
false);
340 int SystemExec(
const char *Command,
bool Detached =
false);
virtual void Action(void)=0
A derived cThread class must implement the code it wants to execute as a separate thread in this func...
bool Active(void)
Returns true if this I/O throttling object is currently active.
void SetDescription(const char *Description,...) __attribute__((format(printf
bool TimedOut(void) const
Returns true if the last lock attempt this key was used with failed due to a timeout.
void Unlock(cStateKey &StateKey, bool IncState=true)
Releases a lock that has been obtained by a previous call to Lock() with the given StateKey...
void Signal(void)
Signals a caller of Wait() that the condition it is waiting for is met.
void Remove(bool IncState=true)
Removes this key from the lock it was previously used with.
void SetPriority(int Priority)
cThreadLock(cThread *Thread=NULL)
static tThreadId IsMainThread(void)
tThreadId writeLockThreadId
static cString Demangle(char *s)
Demangles the function name in the given string and returns the converted version of s...
cRwLock(bool PreferWriter=false)
void Reset(void)
Resets the state of this key, so that the next call to a lock's Lock() function with this key will re...
void SetModified(void)
Sets this lock to have its state incremented when the current write lock state key is removed...
cMutexLock(cMutex *Mutex=NULL)
static void SleepMs(int TimeoutMs)
Creates a cCondWait object and uses it to sleep for TimeoutMs milliseconds, immediately giving up the...
static void * StartThread(cThread *Thread)
bool StateChanged(void)
Returns true if this key is used for obtaining a write lock, and the lock's state differs from that o...
void bool Start(void)
Sets the description of this thread, which will be used when logging starting or stopping of the thre...
bool Open(const char *Command, const char *Mode)
void SetSyncStateKey(cStateKey &StateKey)
Sets the given StateKey to be synchronized to the state of this lock.
bool Lock(bool Write, int TimeoutMs=0)
bool Running(void)
Returns false if a derived cThread object shall leave its Action() function.
bool Lock(cStateKey &StateKey, bool Write=false, int TimeoutMs=0)
Tries to get a lock and returns true if successful.
bool Wait(int TimeoutMs=0)
Waits at most TimeoutMs milliseconds for a call to Signal(), or forever if TimeoutMs is 0...
static tThreadId ThreadId(void)
bool TimedWait(cMutex &Mutex, int TimeoutMs)
void Activate(void)
Activates the global I/O throttling mechanism.
cStateLock(const char *Name=NULL)
struct __attribute__((packed))
void SetIOPriority(int Priority)
static void SetMainThreadId(void)
bool Active(void)
Checks whether the thread is still alive.
void SetExplicitModify(void)
If you have obtained a write lock on this lock, and you don't want its state to be automatically incr...
static bool Engaged(void)
Returns true if any I/O throttling object is currently active.
static void BackTrace(cStringList &StringList, int Level=0, bool Mangled=false)
Produces a backtrace and stores it in the given StringList.
static cString GetCaller(int Level=0, bool Mangled=false)
Returns the caller at the given Level (or the immediate caller, if Level is 0).
int SystemExec(const char *Command, bool Detached=false)
cThread(const char *Description=NULL, bool LowPriority=false)
Creates a new thread.
bool Lock(cThread *Thread)
void Cancel(int WaitSeconds=0)
Cancels the thread by first setting 'running' to false, so that the Action() loop can finish in an or...
static tThreadId mainThreadId
cStateKey(bool IgnoreFirst=false)
Sets up a new state key.
bool InLock(void)
Returns true if this key is currently in a lock.
void Release(void)
Releases the global I/O throttling mechanism.