Skip to content
Snippets Groups Projects
Commit 482e41e4 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

Add DIE_MSG_ERRNO() macro

parent f6184112
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include "Common.hpp"
void die(const char* message) {
std::cout << message << std::endl;
void die(const char* message, bool usePerror) {
if (usePerror) {
std::perror(message);
} else {
std::cout << message << std::endl;
}
exit(EXIT_FAILURE);
}
......@@ -8,14 +8,15 @@ typedef std::function<void(void)> func_t;
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define DIE die(__FILE__ ":" TOSTRING(__LINE__))
#define DIE_MSG(x) die(__FILE__ ":" TOSTRING(__LINE__) "-" #x)
#define DIE die(__FILE__ ":" TOSTRING(__LINE__), false)
#define DIE_MSG(x) die(__FILE__ ":" TOSTRING(__LINE__) "-" #x, false)
#define DIE_MSG_ERRNO(x) die(__FILE__ ":" TOSTRING(__LINE__) "-" #x, true)
#define likely(x) __builtin_expect(!!(x),1)
#define unlikely(x) __builtin_expect(!!(x),0)
#define ALIGN_TO_CACHE_LINE alignas(64)
void die(const char* message);
void die(const char* message, bool usePerror);
typedef unsigned int WORD;
......@@ -52,7 +52,7 @@ Runtime::Runtime(workerid_t workerCount, RuntimeStrategy& strategy) : workerCoun
CPU_SET(i % nprocs, &cpuset);
errno = pthread_attr_setaffinity_np(&attr, sizeof(cpuset), &cpuset);
if (errno) DIE_MSG("pthread_attr_setaffinity_np() failed");
if (errno) DIE_MSG_ERRNO("pthread_attr_setaffinity_np() failed");
// End non portable.
// Load the worker ID into the worker ID map.
......@@ -60,16 +60,16 @@ Runtime::Runtime(workerid_t workerCount, RuntimeStrategy& strategy) : workerCoun
auto thread_function = [](void* voidWorkerId) -> void* { return currentRuntime->workerLoop(voidWorkerId); };
errno = pthread_create(&threads[i], &attr, thread_function, &workerIds[i]);
if (errno) DIE_MSG("pthread_create() failed");
if (errno) DIE_MSG_ERRNO("pthread_create() failed");
}
}
Runtime::~Runtime() {
DBG("Runtime " << this << " is terminating");
for (workerid_t i = 0; i < workerCount; ++i) {
int res = pthread_cancel(threads[i]);
if (res) {
DIE_MSG("pthread_cancel() failed");
errno = pthread_cancel(threads[i]);
if (errno) {
DIE_MSG_ERRNO("pthread_cancel() failed");
}
}
{
......@@ -84,9 +84,9 @@ void* Runtime::workerLoop(void* voidWorkerId) {
LOGD("Worker loop started by thread " << syscall(SYS_gettid));
int oldType;
int res = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldType);
if (res) {
DIE_MSG("pthread_setcanceltype() failed");
errno = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldType);
if (errno) {
DIE_MSG_ERRNO("pthread_setcanceltype() failed");
}
// Initialze the workers PRNG seed.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment