00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __libutilxx__sella__util__CommonMacro_H__
00010 #define __libutilxx__sella__util__CommonMacro_H__
00011
00017 #define PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality)
00018
00019
00020 #define PREFETCH_RO 0
00021 #define PREFETCH_RW 1
00022
00023 #define PREFETCH_LOCALITY_NONE 0
00024 #define PREFETCH_LOCALITY_LOW 1
00025 #define PREFETCH_LOCALITY_MEDIUM 2
00026 #define PREFETCH_LOCALITY_HIGH 3
00027
00035 #define STANDARD_TYPEDEF(x) \
00036 typedef std::shared_ptr<x> shared; \
00037 typedef x * ptr;
00038
00055 #define CAS(variable, read, write) __sync_bool_compare_and_swap((variable), (read), (write))
00056
00057 #define ATOMIC_INC(x) __sync_add_and_fetch(&(x), 1)
00058 #define ATOMIC_DEC(x) __sync_dec_and_fetch(&(x), 1)
00059
00060 #if defined __GNUC__ && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2))
00061 #define LIBFLOW___API_DEPRECATED __attribute__((__deprecated__))
00062 #else
00063 #define LIBFLOW___API_DEPRECATED
00064 #endif
00065
00066 #if (__GNUC__ >= 3)
00067 #define LIKELY(x) __builtin_expect(!!(x), 1)
00068 #define UNLIKELY(x) __builtin_expect((x), 0)
00069 #else
00070 #define LIKELY(x) (x)
00071 #define UNLIKELY(x) (x)
00072 #endif
00073
00074 #define BSWAP64(x) __builtin_bswap64((x))
00075 #define BSWAP32(x) __builtin_bswap32((x))
00076
00077 #define CLZ32(x) (((x) == 0) ? 32 : __builtin_clzl(x))
00078 #define CLZ64(x) (((x) == 0) ? 64 : __builtin_clzll(x))
00079
00080 #define SAFE_FREE(x) if (x != 0) { free(x); x = 0; }
00081 #define SAFE_DELETE(x) if (x != 0) { delete x; x = 0; }
00082 #define SAFE_DELETE_ARRAY(x) if (x != 0) { delete[] x; x = 0; }
00083 #include <regex.h>
00084 #define SAFE_REGFREE(x) if (x->buffer != NULL) { regfree(x); bzero(x, sizeof(regex_t)); }
00085
00086 #ifndef FD_COPY
00087 #include <string.h>
00088 #define FD_COPY(d,s) memcpy((d), (s), sizeof(*(d)))
00089 #endif
00090
00091 #include <endian.h>
00092 #ifdef _BIG_ENDIAN
00093 #define htonll(x) (x)
00094 #define ntohll(x) (x)
00095 #elif defined(__GNUC__) && defined(__GLIBC__)
00096 #include <byteswap.h>
00097 #define htonll(x) bswap_64(x)
00098 #define ntohll(x) bswap_64(x)
00099 #else
00100 #define htonll(x) ((((uint64_t)htonl(x)) << 32) + htonl(x >> 32))
00101 #define ntohll(x) ((((uint64_t)ntohl(x)) << 32) + ntohl(x >> 32))
00102 #endif
00103
00104 #endif
00105
00106
00107
00108