Skip to content

Commit

Permalink
Fix compilation if stdatomic.h is present (uperf#65)
Browse files Browse the repository at this point in the history
At least recent versions of macOS and FreeBSD provide stdatomic.h.
Fix building uperf on these platfroms.
  • Loading branch information
tuexen committed Apr 26, 2024
1 parent 4afed34 commit 766ca23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/shm.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#ifndef _SHM_H
#define _SHM_H

#ifdef HAVE_STDATOMIC_H
#include <stdatomic.h>
#endif /* HAVE_STDATOMIC_H */
#include "logging.h"
#include "sync.h"
#include "workorder.h"
Expand Down Expand Up @@ -75,7 +78,11 @@ struct uperf_shm {
uperf_log_t log;
int global_error;
uint32_t sstate1[NUM_STATES];
#ifdef HAVE_STDATOMIC_H
atomic_uint finished;
#else
uint32_t finished;
#endif /* HAVE_STDATOMIC_H */
int cleaned_up;

/* callouts */
Expand Down
7 changes: 7 additions & 0 deletions src/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#ifndef _SYNC_H
#define _SYNC_H

#ifdef HAVE_STDATOMIC_H
#include <stdatomic.h>
#endif /* HAVE_STDATOMIC_H */
#include <pthread.h>

#define BARRIER_REACHED(a) !barrier_notreached((a))
Expand All @@ -36,7 +39,11 @@ typedef struct sync_barrier {
pthread_mutexattr_t count_mtx_attr;
pthread_mutex_t count_mutex;
#endif /* HAVE_ATOMIC_H && HAVE_STDATOMIC_H */
#ifdef HAVE_STDATOMIC_H
atomic_uint count;
#else
volatile unsigned int count;
#endif /* HAVE_STDATOMIC_H */
volatile unsigned int limit;
int group;
int txn;
Expand Down

0 comments on commit 766ca23

Please sign in to comment.