Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933689Ab3JOUvD (ORCPT ); Tue, 15 Oct 2013 16:51:03 -0400 Received: from mail-wg0-f45.google.com ([74.125.82.45]:54001 "EHLO mail-wg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933371Ab3JOUvA (ORCPT ); Tue, 15 Oct 2013 16:51:00 -0400 From: Frederic Weisbecker To: Andrew Morton Cc: LKML , Frederic Weisbecker , Steven Rostedt , Linus Torvalds , "H. Peter Anvin" , Peter Zijlstra , Thomas Gleixner , Liu Chuansheng , Ingo Molnar Subject: [PATCH 1/3] core: New macro to execute code only once Date: Tue, 15 Oct 2013 22:50:50 +0200 Message-Id: <1381870252-5430-2-git-send-email-fweisbec@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1381870252-5430-1-git-send-email-fweisbec@gmail.com> References: <1381870252-5430-1-git-send-email-fweisbec@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1674 Lines: 60 Introduce DO_COND(), DO_ONCE() and DO_ONCE_COND(). These macros should ease the consolidation of CPP code when it is deemed to be executed only once and/or after a condition is verified. This incluse printk_once, WARN_ON, WARN_ON_ONCE, etc... Signed-off-by: Frederic Weisbecker Cc: Andrew Morton Cc: Steven Rostedt Cc: Linus Torvalds Cc: H. Peter Anvin Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Liu Chuansheng Cc: Ingo Molnar --- include/linux/once.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 include/linux/once.h diff --git a/include/linux/once.h b/include/linux/once.h new file mode 100644 index 0000000..9399f37 --- /dev/null +++ b/include/linux/once.h @@ -0,0 +1,26 @@ +#ifndef _LINUX_ONCE_H +#define _LINUX_ONCE_H + +#include + +#define DO_COND(condition, to_do) ({ \ + int __ret = !!(condition); \ + if (unlikely(__ret)) { \ + to_do; \ + } \ + unlikely(__ret); \ +}) + +#define DO_ONCE(to_do) ({ \ + static bool __done; \ + \ + if (!__done) { \ + __done = true; \ + to_do; \ + } \ +}) + +#define DO_ONCE_COND(condition, to_do) \ + DO_COND(condition, DO_ONCE(to_do)) + +#endif /* _LINUX_ONCE_H */ -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/