libisdn
common.h
Go to the documentation of this file.
00001 /*
00002  * Common utility macros
00003  *
00004  */
00005 #ifndef _UTILS_COMMON_H_
00006 #define _UTILS_COMMON_H_
00007 
00008 #ifndef ARRAY_SIZE
00009 #define ARRAY_SIZE(x)   (sizeof((x)) / sizeof((x)[0]))
00010 #endif
00011 
00012 #ifndef MAX
00013 #define MAX(x, y)       (((x) > (y)) ?  (x) : (y))
00014 #endif
00015 
00016 #ifndef MIN
00017 #define MIN(x, y)       (((x) < (y)) ?  (x) : (y))
00018 #endif
00019 
00023 #ifndef offset_of
00024 #define offset_of(type, member)                 \
00025         (uintptr_t)&(((type *)0)->member)
00026 #endif
00027 
00031 #ifndef container_of
00032 #define container_of(ptr, type, member)                         \
00033         (type *)((uintptr_t)ptr - offset_of(type, member))
00034 #endif
00035 
00039 #ifndef ACCESS_ONCE
00040 #define ACCESS_ONCE(x)  (*((volatile typeof(x) *)&(x)))
00041 #endif
00042 
00043 #endif  /* _UTILS_COMMON_H_ */