diff --git a/include/villas/common.h b/include/villas/common.h index b32dc717c..47f09b944 100644 --- a/include/villas/common.h +++ b/include/villas/common.h @@ -33,4 +33,14 @@ enum state { STATE_LOADED = 4, /* alias for STATE_STARTED used by plugins */ STATE_STOPPED = 5, STATE_UNLOADED = 5 /* alias for STATE_STARTED used by plugins */ -}; \ No newline at end of file +}; + +#ifdef __cpluscplus + +typedef std::atomic_int atomic_state; + +#else + +typedef _Atomic enum state atomic_state; + +#endif diff --git a/include/villas/queue.h b/include/villas/queue.h index 30e29b64b..ce1ab58d5 100644 --- a/include/villas/queue.h +++ b/include/villas/queue.h @@ -56,7 +56,7 @@ struct queue_cell { struct queue { cacheline_pad_t _pad0; /**< Shared area: all threads read */ - atomic_size_t state; + atomic_state state; struct memtype *mem; size_t buffer_mask; diff --git a/lib/queue.c b/lib/queue.c index a10d9c360..96e82993d 100644 --- a/lib/queue.c +++ b/lib/queue.c @@ -188,8 +188,8 @@ int queue_pull_many(struct queue *q, void *ptr[], size_t cnt) int queue_close(struct queue *q) { - size_t expected = STATE_INITIALIZED; - if (atomic_compare_exchange_weak_explicit(&q->state, &expected, STATE_STOPPED, memory_order_relaxed, memory_order_relaxed)) { + int expected = STATE_INITIALIZED; + if (atomic_compare_exchange_weak_explicit(&q->state, &expected, STATE_STOPPED, memory_order_relaxed, memory_order_relaxed)) return 0; return -1;