9#define TESTRUN(cmd, msg) \
21 Mutex() { TESTRUN(pthread_mutex_init(&
mtx, NULL),
"Mutex init failed with msg %d") }
24 virtual ~Mutex() { TESTRUN(pthread_mutex_destroy(&
mtx),
"Mutex destroy failed with msg %d") }
27 void lock() { TESTRUN(pthread_mutex_lock(&
mtx),
"Mutex lock failed with msg %d") }
30 void unlock() { TESTRUN(pthread_mutex_unlock(&
mtx),
"Mutex unlock failed with msg %d") }
36 return pthread_mutex_trylock(&
mtx) == 0;
49 Thread(
void* (*main)(
void*),
void* arg) { pthread_create(&
myTid, NULL, main, arg); }
54 void setThreadAffinity(
int coreId)
58 CPU_SET(coreId, &cpuset);
60 pthread_setaffinity_np(this->
myTid,
sizeof(cpu_set_t), &cpuset);
Mutex class.
Definition Threading.hpp:18
pthread_mutex_t mtx
A pthread mutex.
Definition Threading.hpp:41
void unlock()
Unlock the mutex.
Definition Threading.hpp:30
Mutex()
Constructor.
Definition Threading.hpp:21
virtual ~Mutex()
Destructor.
Definition Threading.hpp:24
bool tryLock()
Try to lock the mutex, return true if succes else false.
Definition Threading.hpp:33
void lock()
Lock the mutex.
Definition Threading.hpp:27
Thread class.
Definition Threading.hpp:46
void join()
Join the thread.
Definition Threading.hpp:52
pthread_t myTid
The id of the pthread.
Definition Threading.hpp:65
Thread(void *(*main)(void *), void *arg)
Constructor.
Definition Threading.hpp:49