From 2dc5fa0f7cfbfb0a64a7a67b39626650e863f16a Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 13 May 2009 11:15:37 -0400 Subject: [PATCH] Rewrite of likely, unlikely, barrier and ACCESS_ONCE compiler.h now licensed under MIT-style license. Signed-off-by: Mathieu Desnoyers --- LICENSE | 1 + compiler.h | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/LICENSE b/LICENSE index fa10831..f02264e 100644 --- a/LICENSE +++ b/LICENSE @@ -38,6 +38,7 @@ This license applies to : arch_atomic_x86.h arch_atomic_ppc.h +compiler.h * GPLv2 diff --git a/compiler.h b/compiler.h index fb09ca2..717465c 100644 --- a/compiler.h +++ b/compiler.h @@ -25,6 +25,11 @@ * IBM's contributions to this file may be relicensed under LGPLv2 or later. */ +#define likely() __builtin_expect(!!(x), 1) +#define unlikely() __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 +42,6 @@ * 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) #endif /* _COMPILER_H */ -- 2.34.1