mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
use stdatomic (#1317)
This commit is contained in:
@@ -1,14 +1,42 @@
|
||||
#ifndef SKYNET_ATOMIC_H
|
||||
#define SKYNET_ATOMIC_H
|
||||
|
||||
#ifdef NO_STDATOMIC
|
||||
|
||||
#define ATOM_BYTE unsigned char
|
||||
#define ATOM_INT int
|
||||
#define ATOM_POINTER void *
|
||||
#define ATOM_SIZET size_t
|
||||
#define ATOM_INIT(ptr, v) (*(ptr) = v)
|
||||
#define ATOM_LOAD(ptr) (*(ptr))
|
||||
#define ATOM_STORE(ptr, v) (*(ptr) = v)
|
||||
#define ATOM_CAS(ptr, oval, nval) __sync_bool_compare_and_swap(ptr, oval, nval)
|
||||
#define ATOM_CAS_POINTER(ptr, oval, nval) __sync_bool_compare_and_swap(ptr, oval, nval)
|
||||
#define ATOM_INC(ptr) __sync_add_and_fetch(ptr, 1)
|
||||
#define ATOM_FINC(ptr) __sync_fetch_and_add(ptr, 1)
|
||||
#define ATOM_DEC(ptr) __sync_sub_and_fetch(ptr, 1)
|
||||
#define ATOM_FDEC(ptr) __sync_fetch_and_sub(ptr, 1)
|
||||
#define ATOM_ADD(ptr,n) __sync_add_and_fetch(ptr, n)
|
||||
#define ATOM_SUB(ptr,n) __sync_sub_and_fetch(ptr, n)
|
||||
#define ATOM_AND(ptr,n) __sync_and_and_fetch(ptr, n)
|
||||
#define ATOM_FADD(ptr,n) __sync_fetch_and_add(ptr, n)
|
||||
#define ATOM_FSUB(ptr,n) __sync_fetch_and_sub(ptr, n)
|
||||
#define ATOM_FAND(ptr,n) __sync_fetch_and_and(ptr, n)
|
||||
|
||||
#else
|
||||
|
||||
#include <stdatomic.h>
|
||||
|
||||
#define ATOM_BYTE atomic_uchar
|
||||
#define ATOM_INT atomic_int
|
||||
#define ATOM_POINTER atomic_uintptr_t
|
||||
#define ATOM_SIZET atomic_size_t
|
||||
#define ATOM_INIT(ref, v) atomic_init(ref, v)
|
||||
#define ATOM_LOAD(ptr) atomic_load(ptr)
|
||||
#define ATOM_STORE(ptr, v) atomic_store(ptr, v)
|
||||
#define ATOM_CAS(ptr, oval, nval) atomic_compare_exchange_weak(ptr, &(oval), nval)
|
||||
#define ATOM_CAS_POINTER(ptr, oval, nval) atomic_compare_exchange_weak(ptr, &(oval), nval)
|
||||
#define ATOM_FINC(ptr) atomic_fetch_add(ptr, 1)
|
||||
#define ATOM_FDEC(ptr) atomic_fetch_sub(ptr, 1)
|
||||
#define ATOM_FADD(ptr,n) atomic_fetch_add(ptr, n)
|
||||
#define ATOM_FSUB(ptr,n) atomic_fetch_sub(ptr, n)
|
||||
#define ATOM_FAND(ptr,n) atomic_fetch_and(ptr, n)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user