[PATCH V2 1/3] kernel.h: Add DO_ONCE statement expression macro



Add a DO_ONCE statement expression analogous to printk_once
that executes any arbitrary statement exactly once.

This will take the place of printk_once so that
DO_ONCE(pr_<foo>) can be more easily written.

Signed-off-by: Joe Perches <joe@xxxxxxxxxxx>
---
include/linux/kernel.h | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 883cd44..179fdac 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -637,6 +637,17 @@ static inline void ftrace_dump(void) { }
#define swap(a, b) \
do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)

+/*
+ * Do something once (analogous to WARN_ONCE() et al):
+ */
+#define DO_ONCE(x...) ({ \
+ static unsigned long __done; \
+ \
+ if (!test_and_set_bit(0, &__done)) { \
+ x; \
+ } \
+})
+
/**
* container_of - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
--
1.6.3.1.10.g659a0.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • [PATCH 1/3] kernel.h: Add DO_ONCE statement expression macro
    ... that executes any arbitrary statement exactly once. ... a single time may be easily written. ... container_of - cast a member of a structure out to the containing structure ... More majordomo info at http://vger.kernel.org/majordomo-info.html ...
    (Linux-Kernel)
  • Re: [Cbe-oss-dev] [RFC, PATCH] CELL Oprofile SPU profiling updated patch
    ... On Thursday 15 February 2007 17:15, Maynard Johnson wrote: ... I think you don't need the profile_private member here, ... More majordomo info at http://vger.kernel.org/majordomo-info.html ... Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)
  • [PATCH] Dynamic debug: fix typo: -/->
    ... The member was intended, not the local variable. ... if (newflags) { ... More majordomo info at http://vger.kernel.org/majordomo-info.html ... Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)
  • [-mm][PATCH 3/10] fix munlock page table walk - now requires mm
    ... Initialize the 'mm' member of the mm_walk structure, ... More majordomo info at http://vger.kernel.org/majordomo-info.html ... Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)
  • Re: [-mm] Add an owner to the mm_struct (v2)
    ... Balbir Singh wrote: ... and I don't have to access mm_struct's member in this case. ... More majordomo info at http://vger.kernel.org/majordomo-info.html ... Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)