forked from gozfree/gear-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibmacro.h
63 lines (50 loc) · 1.92 KB
/
libmacro.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/******************************************************************************
* Copyright (C) 2014-2015
* file: libmacro.h
* author: gozfree <[email protected]>
* created: 2016-06-29 11:07:41
* updated: 2016-06-29 11:07:41
*****************************************************************************/
#ifndef _LIBMACRO_H_
#define _LIBMACRO_H_
#include "kernel_list.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* MACRO DEFINES ARE UPPERCASE
*/
#ifdef __GNUC__
#define LIKELY(x) (__builtin_expect(!!(x), 1))
#define UNLIKELY(x) (__builtin_expect(!!(x), 0))
#else
#define LIKELY(x) (x)
#define UNLIKELY(x) (x)
#endif
#define SWAP(a, b) \
do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define CALLOC(size, type) (type *)calloc(size, sizeof(type))
#define SIZEOF(array) (sizeof(array)/sizeof(array[0]))
#define VERBOSE() \
do {\
printf("%s:%s:%d xxxxxx\n", __FILE__, __func__, __LINE__);\
} while (0);
#define DUMP_BUFFER(buf, len) \
do { \
int _i; \
if (!buf || len <= 0) { \
break; \
} \
for (_i = 0; _i < len; _i++) { \
if (!(_i%16)) \
printf("\n%p: ", buf+_i); \
printf("%02x ", (*((char *)buf + _i)) & 0xff); \
} \
printf("\n"); \
} while (0)
#ifdef __cplusplus
}
#endif
#endif