#ifndef ATOMIC_H
#define ATOMIC_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __gnu_linux__
#define ws_atomic_inc32(intptr) __sync_fetch_and_add(intptr, 1)
#define ws_atomic_dec32(intptr) __sync_fetch_and_sub(intptr, 1) - 1
#define ws_atomic_add32(intptr, val) __sync_fetch_and_add(intptr, val)
#define ws_atomic_sub32(intptr, val) __sync_fetch_and_sub(intptr, val)
#elif defined(OSX)
#include <libkern/OSAtomic.h>
#define ws_atomic_inc32(intptr) OSAtomicIncrement32((volatile int32_t *)intptr)
#define ws_atomic_dec32(intptr) OSAtomicDecrement32((volatile int32_t *)intptr)
#elif defined(BSD)
#define ws_atomic_inc32(intptr) __sync_fetch_and_add(intptr, 1)
#define ws_atomic_dec32(intptr) __sync_fetch_and_sub(intptr, 1) - 1
#define ws_atomic_add32(intptr, val) __sync_fetch_and_add(intptr, val)
#define ws_atomic_sub32(intptr, val) __sync_fetch_and_sub(intptr, va
#else
#include <atomic.h>
#define ws_atomic_inc32(intptr) atomic_inc_32_nv(intptr)
#define ws_atomic_dec32(intptr) atomic_dec_32_nv(intptr)
#endif
#ifdef __cplusplus
}
#endif
#endif