Add NetBSD atomic ops support.

Signed-off-by: Thomas Klausner <wiz@NetBSD.org>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@ubuntu.com>
main
Thomas Klausner 2014-07-20 10:23:58 +02:00 committed by Maarten Lankhorst
parent 96cf455425
commit 87fdd32c87
1 changed files with 10 additions and 3 deletions

View File

@ -75,21 +75,28 @@ typedef struct {
#endif
#if defined(__sun) && !defined(HAS_ATOMIC_OPS) /* Solaris & OpenSolaris */
#if (defined(__sun) || defined(__NetBSD__)) && !defined(HAS_ATOMIC_OPS) /* Solaris & OpenSolaris & NetBSD */
#include <sys/atomic.h>
#define HAS_ATOMIC_OPS 1
typedef struct { uint_t atomic; } atomic_t;
#if defined(__NetBSD__)
#define _ATOMIC_TYPE int
#else
#define _ATOMIC_TYPE uint_t
#endif
typedef struct { _ATOMIC_TYPE atomic; } atomic_t;
# define atomic_read(x) (int) ((x)->atomic)
# define atomic_set(x, val) ((x)->atomic = (uint_t)(val))
# define atomic_set(x, val) ((x)->atomic = (_ATOMIC_TYPE)(val))
# define atomic_inc(x) (atomic_inc_uint (&(x)->atomic))
# define atomic_dec_and_test(x) (atomic_dec_uint_nv(&(x)->atomic) == 0)
# define atomic_add(x, v) (atomic_add_int(&(x)->atomic, (v)))
# define atomic_dec(x, v) (atomic_add_int(&(x)->atomic, -(v)))
# define atomic_cmpxchg(x, oldv, newv) atomic_cas_uint (&(x)->atomic, oldv, newv)
#undef _ATOMIC_TYPE
#endif
#if ! HAS_ATOMIC_OPS