Macro to use for making functions called only once in multi-threaded
tests such as init or cleanup function.

Signed-off-by: Alexey Kodanev <[email protected]>
---
 include/test.h |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/include/test.h b/include/test.h
index d46fdbf..78f13c2 100644
--- a/include/test.h
+++ b/include/test.h
@@ -111,6 +111,21 @@ pid_t tst_vfork(void);
 #endif
 
 /*
+ * Macro to use for making functions called only once in
+ * multi-threaded tests such as init or cleanup function.
+ * The first call to @name_fn function by any thread shall
+ * call the @exec_fn. Subsequent calls shall not call @exec_fn.
+ * *_fn functions must not take any arguments.
+ */
+#define DECLARE_ONCE_FN(name_fn, exec_fn)                              \
+       void name_fn(void)                                              \
+       {                                                               \
+               static pthread_once_t name_fn##_ex = PTHREAD_ONCE_INIT; \
+               pthread_once(&name_fn##_ex, exec_fn);                   \
+       }
+
+
+/*
  * lib/forker.c
  */
 extern int Forker_pids[];
-- 
1.7.1


------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to