#ifndef _TYPEDEF_H_ #define _TYPEDEF_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef _ERROR_H_ #include "error.h" #endif /* 内存访问栅 */ #define barrier() (__sync_synchronize()) /*原子设置,如果原值和新值不一样则设置*/ #define AO_SET(ptr, value) ((void)__sync_lock_test_and_set((ptr), (value))) /*原子获取*/ #define AO_GET(ptr) ({ __typeof__(*(ptr)) volatile *_val = (ptr); barrier(); (*_val); }) /*原子加*/ #define AO_F_ADD(ptr, value) ((__typeof__(*(ptr)))__sync_fetch_and_add((ptr), (value))) /*原子减*/ #define AO_F_SUB(ptr, value) ((__typeof__(*(ptr)))__sync_fetch_and_sub((ptr), (value))) #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #endif