X-Git-Url: http://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=compiler.h;h=99972f30e2ba89726f663c78261f4e9203b6d026;hp=fb09ca2b9b238ceec418ba5c21c660b4cebcb7fd;hb=ba59a0c7b244a0939a2298fc76a9002436ef9674;hpb=d8429b11e257939635c5dc4786756effdc38b494 diff --git a/compiler.h b/compiler.h index fb09ca2..99972f3 100644 --- a/compiler.h +++ b/compiler.h @@ -8,23 +8,21 @@ * * Copyright (c) 2009 Mathieu Desnoyers * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. -* - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * IBM's contributions to this file may be relicensed under LGPLv2 or later. + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. */ +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) + +#define barrier() asm volatile("" : : : "memory"); + /* * Instruct the compiler to perform only a single access to a variable * (prohibits merging and refetching). The compiler is also forbidden to reorder @@ -37,5 +35,16 @@ * use is to mediate communication between process-level code and irq/NMI * handlers, all running on the same CPU. */ +#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&x) + +#if (__GNUC__ == 4) +#define __compiler_offsetof(a, b) __builtin_offsetof(a, b) +#endif + +#ifdef __compiler_offsetof +#define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER) +#else +#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +#endif #endif /* _COMPILER_H */