Commit 6a1704f0 authored by Eurecom's avatar Eurecom

C and C++

parent d17d22c1
#ifndef TASK_WORK_STEALING_THREAD_POOL_H #ifndef TASK_WORK_STEALING_THREAD_POOL_H
#define TASK_WORK_STEALING_THREAD_POOL_H #define TASK_WORK_STEALING_THREAD_POOL_H
#ifndef __cplusplus
#include <stdalign.h>
#else
#define _Alignas(X) alignas(X)
#endif
#if defined (__i386__) || defined(__x86_64__) #if defined (__i386__) || defined(__x86_64__)
#define LEVEL1_DCACHE_LINESIZE 64 #define LEVEL1_DCACHE_LINESIZE 64
#elif __aarch64__ #elif __aarch64__
...@@ -12,6 +18,7 @@ ...@@ -12,6 +18,7 @@
static_assert(0!=0, "Unknown CPU architecture"); static_assert(0!=0, "Unknown CPU architecture");
#endif #endif
typedef struct{ typedef struct{
// Avoid false sharing. Doing it in the first member // Avoid false sharing. Doing it in the first member
_Alignas(LEVEL1_DCACHE_LINESIZE) void* args; _Alignas(LEVEL1_DCACHE_LINESIZE) void* args;
......
...@@ -14,10 +14,18 @@ ...@@ -14,10 +14,18 @@
#include "task.h" #include "task.h"
#include <pthread.h> #include <pthread.h>
#include <stdatomic.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#ifndef __cplusplus
#include <stdalign.h>
#include <stdatomic.h>
#else
#include <atomic>
#define _Atomic(X) std::atomic< X >
#define _Alignas(X) alignas(X)
#endif
#if defined (__i386__) || defined(__x86_64__) #if defined (__i386__) || defined(__x86_64__)
#define pause_or_yield __builtin_ia32_pause #define pause_or_yield __builtin_ia32_pause
#elif __aarch64__ #elif __aarch64__
...@@ -42,11 +50,11 @@ typedef struct{ ...@@ -42,11 +50,11 @@ typedef struct{
pthread_t* t_arr; pthread_t* t_arr;
size_t len_thr; size_t len_thr;
atomic_uint_fast64_t index; _Atomic(uint64_t) index;
void* q_arr; void* q_arr;
atomic_uint_fast64_t num_task; _Atomic(uint64_t) num_task;
// pthread_cond_t wait_cv; // pthread_cond_t wait_cv;
// pthread_mutex_t wait_mtx; // pthread_mutex_t wait_mtx;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment