22 #include "dabc/defines.h"
37 #define CPU_SETSIZE 32
39 extern "C" void CPU_ZERO(cpu_set_t *arg);
41 extern "C" void CPU_SET(
int cpu, cpu_set_t *arg);
43 extern "C" bool CPU_ISSET(
int cpu, cpu_set_t *arg);
45 extern "C" void CPU_CLR(
int cpu, cpu_set_t *arg);
47 extern "C" int sched_getaffinity(
int,
int, cpu_set_t* set);
49 extern "C" int sched_setaffinity(
int,
int, cpu_set_t*);
69 Mutex(
bool recursive =
false);
96 bool null()
const {
return fMutex == 0; }
107 #ifdef DABC_EXTRA_CHECKS
111 #define DABC_LOCKGUARD(mutex,info) \
112 dabc::LockGuard dabc_guard(mutex, false); \
113 while (!dabc_guard.TryingLock()) EOUT(info);
117 #define DABC_LOCKGUARD(mutex,info) dabc::LockGuard dabc_guard(mutex)
278 inline bool DoWait(
double wait_seconds = -1.)
301 pthread_cond_signal(&
fCond);
304 bool _DoWait(
double wait_seconds);
374 bool GetAffinity(
bool actual,
char* buf,
unsigned maxbuf);
386 void Kill(
int sig = 9);
404 inline bool IsItself()
const {
return pthread_equal(
fThrd, pthread_self()) != 0; }
Condition(Mutex *ext_mtx=nullptr)
long int _FiredCounter() const
Mutex * CondMutex() const
bool DoWait(double wait_seconds=-1.)
bool _DoWait(double wait_seconds)
IntGuard(const int &value)
IntGuard(const int *value)
Lock guard for posix mutex.
LockGuard(pthread_mutex_t &mutex, bool)
LockGuard(const Mutex *mutex, bool)
LockGuard(const Mutex *mutex)
LockGuard(pthread_mutex_t &mutex)
LockGuard(const Mutex &mutex)
LockGuard(pthread_mutex_t *mutex, bool)
LockGuard(const Mutex &mutex, bool)
LockGuard(pthread_mutex_t *mutex)
Pointer on posix pthread mutex
MutexPtr(pthread_mutex_t *mutex)
MutexPtr(const Mutex &mutex)
MutexPtr(pthread_mutex_t &mutex)
MutexPtr(const Mutex *mutex)
MutexPtr(const MutexPtr &src)
Mutex(bool recursive=false)
class represents posix pthread functionality
static bool SetDfltAffinity(const char *aff=nullptr)
Sets default affinity for next threads to be created and for main process.
cpu_set_t fCpuSet
affinity property of the thread
pthread_t fThrd
pthread handle
void Start(Runnable *run)
Start thread with provided runnable.
bool SetAffinity(const char *aff)
Sets affinity mask for the thread.
void Join()
Join thread - method waits until thread execution is completed.
bool GetAffinity(bool actual, char *buf, unsigned maxbuf)
Provides thread affinity in form of "xxxooooo".
void Kill(int sig=9)
Kill thread with specified signal.
void *() StartRoutine(void *)
static cpu_set_t fDfltSet
default affinity for new thread
bool IsItself() const
Returns true if called from thread context.
void Cancel()
Try to cancel thread execution.
static bool GetDfltAffinity(char *buf, unsigned maxbuf)
Returns default affinity mask in form "xxxooosss".
static cpu_set_t fSpecialSet
set of processors, which can be used for special threads
void SetPriority(int prio)
Change thread priority.
void SetThreadName(const char *thrdname)
Set thread name, which can be seen from htop.
Object which could be run inside the dabc::PosixThread
virtual void * MainLoop()=0
virtual void RunnableCancelled()
Represent thread functionality.
Unlock guard for posix mutex.
UnlockGuard(const Mutex *mutex)