Skip to content

Commit 0b30678

Browse files
nehebarr2036
authored andcommitted
solaris: use C11 atomics
Signed-off-by: Rosen Penev <rosenp@gmail.com>
1 parent ea30540 commit 0b30678

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/solaris/platform.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,27 @@
1717
#ifndef _KQUEUE_SOLARIS_PLATFORM_H
1818
#define _KQUEUE_SOLARIS_PLATFORM_H
1919

20-
#include <atomic.h>
2120
#include <errno.h>
2221
#include <pthread.h>
22+
#include <stdatomic.h>
2323
#include <string.h>
2424
#include <sys/queue.h>
2525
#include <sys/resource.h>
2626
#include <sys/time.h>
2727

2828
#include "../posix/eventfd.h"
2929

30-
#define atomic_uintptr_t uintptr_t
31-
#define atomic_uint unsigned int
32-
#define atomic_inc atomic_inc_32_nv
33-
#define atomic_dec atomic_dec_32_nv
34-
#define atomic_cas(p, oval, nval) (atomic_cas(p, oval, nval) == oval)
35-
#define atomic_ptr_cas(p, oval, nval) (atomic_cas_ptr(p, oval, nval) == oval)
36-
#define atomic_ptr_swap(p, nval) (atomic_swap_ptr(p, nval)
37-
#define atomic_ptr_load(p) (*p)
30+
/*
31+
* C11 atomic operations
32+
*/
33+
#define atomic_inc(p) (atomic_fetch_add((p), 1) + 1)
34+
#define atomic_dec(p) (atomic_fetch_sub((p), 1) - 1)
35+
36+
/* We use compound literals here to stop the 'expected' values from being overwritten */
37+
#define atomic_cas(p, oval, nval) atomic_compare_exchange_strong(p, &(__typeof__(oval)){ oval }, nval)
38+
#define atomic_ptr_cas(p, oval, nval) atomic_compare_exchange_strong(p, (&(uintptr_t){ (uintptr_t)oval }), (uintptr_t)nval)
39+
#define atomic_ptr_swap(p, nval) atomic_exchange(p, (uintptr_t)nval)
40+
#define atomic_ptr_load(p) atomic_load(p)
3841

3942
/*
4043
* Event ports

0 commit comments

Comments
 (0)