51 lines
1.0 KiB
C
51 lines
1.0 KiB
C
#ifndef _TYPEDEF_H_
|
|
#define _TYPEDEF_H_
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <signal.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/ioctl.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
#include <netinet/in.h>
|
|
#include <netinet/tcp.h>
|
|
#include <arpa/inet.h>
|
|
#include <fcntl.h>
|
|
#include <sys/time.h>
|
|
#include <pthread.h>
|
|
#include <stdarg.h>
|
|
#include <errno.h>
|
|
#include <time.h>
|
|
|
|
|
|
#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 |