Arnaldo Carvalho de Melo | 43cbcd8 | 2009-07-01 12:28:37 -0300 | [diff] [blame] | 1 | #ifndef PERF_LINUX_KERNEL_H_ |
| 2 | #define PERF_LINUX_KERNEL_H_ |
| 3 | |
| 4 | #ifndef offsetof |
| 5 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) |
| 6 | #endif |
| 7 | |
| 8 | #ifndef container_of |
| 9 | /** |
| 10 | * container_of - cast a member of a structure out to the containing structure |
| 11 | * @ptr: the pointer to the member. |
| 12 | * @type: the type of the container struct this is embedded in. |
| 13 | * @member: the name of the member within the struct. |
| 14 | * |
| 15 | */ |
| 16 | #define container_of(ptr, type, member) ({ \ |
| 17 | const typeof(((type *)0)->member) * __mptr = (ptr); \ |
| 18 | (type *)((char *)__mptr - offsetof(type, member)); }) |
| 19 | #endif |
| 20 | |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 21 | #ifndef max |
| 22 | #define max(x, y) ({ \ |
| 23 | typeof(x) _max1 = (x); \ |
| 24 | typeof(y) _max2 = (y); \ |
| 25 | (void) (&_max1 == &_max2); \ |
| 26 | _max1 > _max2 ? _max1 : _max2; }) |
| 27 | #endif |
| 28 | |
Arnaldo Carvalho de Melo | 43cbcd8 | 2009-07-01 12:28:37 -0300 | [diff] [blame] | 29 | #endif |