X-Git-Url: http://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=include%2Furcu%2Fcompiler.h;fp=include%2Furcu%2Fcompiler.h;h=09953f2c2b96eeb5dfd27e04b43825a717d1e38c;hp=827ec1fd6eee0d00d5e863f9268fa89b7ae2d59e;hb=4b3a7ebd5597b5e241c39110eb426f7832066308;hpb=67988e204d2c471b24cae61f3f8fedb4f9375034 diff --git a/include/urcu/compiler.h b/include/urcu/compiler.h index 827ec1f..09953f2 100644 --- a/include/urcu/compiler.h +++ b/include/urcu/compiler.h @@ -74,6 +74,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))