Skip to content

Commit

Permalink
clang15 atomic fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Pantelis Antoniou <[email protected]>
  • Loading branch information
pantoniou committed Sep 7, 2023
1 parent f44efdb commit 3938e8e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
15 changes: 8 additions & 7 deletions src/blake3/blake3_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
#if defined(__linux__) && !defined(BLAKE3_THREAD_PORTABLE)

/* linux pedal to the metal implementation */
static inline int futex(uint32_t *uaddr, int futex_op, uint32_t val, const struct timespec *timeout, uint32_t *uaddr2, uint32_t val3)
static inline int futex(_Atomic(uint32_t) *uaddr, int futex_op, uint32_t val, const struct timespec *timeout, uint32_t *uaddr2, uint32_t val3)
{
return syscall(SYS_futex, uaddr, futex_op, val, timeout, uaddr2, val3);
}

static inline int fwait(uint32_t *futexp)
static inline int fwait(_Atomic(uint32_t) *futexp)
{
long s;
const uint32_t one = 1;
uint32_t one = 1;

while (!atomic_compare_exchange_strong(futexp, &one, 0)) {
s = futex(futexp, FUTEX_WAIT, 0, NULL, NULL, 0);
Expand All @@ -43,10 +43,10 @@ static inline int fwait(uint32_t *futexp)
return 0;
}

static inline int fpost(uint32_t *futexp)
static inline int fpost(_Atomic(uint32_t) *futexp)
{
long s;
const uint32_t zero = 0;
uint32_t zero = 0;

if (atomic_compare_exchange_strong(futexp, &zero, 1)) {
s = futex(futexp, FUTEX_WAKE, 1, NULL, NULL, 0);
Expand Down Expand Up @@ -228,7 +228,8 @@ blake3_thread *blake3_thread_pool_reserve(blake3_thread_pool *tp)
{
blake3_thread *t;
unsigned int slot;
uint64_t *free, v, exp;
_Atomic(uint64_t) *free;
uint64_t exp, v;
unsigned int i;

t = NULL;
Expand All @@ -254,7 +255,7 @@ blake3_thread *blake3_thread_pool_reserve(blake3_thread_pool *tp)

void blake3_thread_pool_unreserve(blake3_thread_pool *tp, blake3_thread *t)
{
uint64_t *free;
_Atomic(uint64_t) *free;

free = tp->freep + (unsigned int)(t->id / 64);
atomic_fetch_or(free, BIT64(t->id & 63));
Expand Down
11 changes: 5 additions & 6 deletions src/blake3/blake3_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ typedef struct _blake3_thread_work {
void *arg;
} blake3_thread_work;

// #define BLAKE3_THREAD_PORTABLE
//#define BLAKE3_THREAD_PORTABLE
typedef struct _blake3_thread {
struct _blake3_thread_pool *tp;
unsigned int id;
pthread_t tid;
void *arg;
const blake3_thread_work *work;
_Atomic(const blake3_thread_work *)work;
#if defined(__linux__) && !defined(BLAKE3_THREAD_PORTABLE)
uint32_t submit;
uint32_t done;
_Atomic(uint32_t) submit;
_Atomic(uint32_t) done;
#else
pthread_mutex_t lock;
pthread_cond_t cond;
Expand All @@ -41,8 +41,7 @@ typedef struct _blake3_thread {
typedef struct _blake3_thread_pool {
unsigned int num_threads;
struct _blake3_thread *threads;
uint64_t *freep;
uint64_t free;
_Atomic(uint64_t) *freep;
unsigned int free_count;
} blake3_thread_pool;

Expand Down
2 changes: 1 addition & 1 deletion src/internal/fy-b3sum.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

static void test_worker_thread_fn(void *arg)
{
int *p = arg;
_Atomic(int) *p = arg;
int v, exp_v;

/* atomically increase the counter */
Expand Down

0 comments on commit 3938e8e

Please sign in to comment.