X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=include%2Furcu%2Fcompiler.h;fp=include%2Furcu%2Fcompiler.h;h=3ba9aeca0c075b10d36e116112b5a359c59b16ff;hb=2a17fe10ad97e997981a98463a4cbda9b4a933a5;hp=fb3c8f160dc580aa8ede55e1ad0fa525e5942ade;hpb=20865c71e59536962252babe23c8ebdbd1cc28b0;p=urcu.git diff --git a/include/urcu/compiler.h b/include/urcu/compiler.h index fb3c8f1..3ba9aec 100644 --- a/include/urcu/compiler.h +++ b/include/urcu/compiler.h @@ -70,6 +70,23 @@ (type *)((char *)__ptr - offsetof(type, member)); \ }) +/* + * caa_container_of_check_null - Get the address of an object containing a field. + * + * @ptr: pointer to the field. + * @type: type of the object. + * @member: name of the field within the object. + * + * Return the address of the object containing the field. Return NULL if + * @ptr is NULL. + */ +#define caa_container_of_check_null(ptr, type, member) \ + __extension__ \ + ({ \ + const __typeof__(((type *) NULL)->member) * __ptr = (ptr); \ + (__ptr) ? (type *)((char *)__ptr - offsetof(type, member)) : NULL; \ + }) + #define CAA_BUILD_BUG_ON_ZERO(cond) (sizeof(struct { int:-!!(cond); })) #define CAA_BUILD_BUG_ON(cond) ((void)CAA_BUILD_BUG_ON_ZERO(cond))