All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 2/4] lib/test.h: create macro to declare init/cleanup functions
@ 2014-02-11  9:48 Alexey Kodanev
  2014-02-11  9:48 ` [LTP] [PATCH v2 3/4] lib: compile *_r.c to libltp_r library, add testcases_r.mk Alexey Kodanev
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Alexey Kodanev @ 2014-02-11  9:48 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko, Alexey Kodanev

Use thread-safe versions of tst_res's functions if tests linked
with pthread library.

Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
---
 include/test.h |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/include/test.h b/include/test.h
index 29824d3..e3de278 100644
--- a/include/test.h
+++ b/include/test.h
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  * Copyright (c) 2009-2013 Cyril Hrubis chrubis@suse.cz
+ * Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of version 2 of the GNU General Public License as
@@ -114,6 +115,36 @@
 extern int Forker_pids[];
 extern int Forker_npids;
 
+/*
+ * 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)			\
+	static pthread_once_t name_fn##_ex = PTHREAD_ONCE_INIT;	\
+	void name_fn(void)					\
+	{							\
+		pthread_once(&name_fn##_ex, exec_fn);		\
+	}
+
+/*
+ * Will be defined if test is compiled with -pthread.
+ * Then we can use thread-safe versions.
+ */
+#ifdef _REENTRANT
+#define tst_res			tst_res_r
+#define tst_resm		tst_resm_r
+#define tst_resm_hexd		tst_resm_hexd_r
+#define tst_brk			tst_brk_r
+#define tst_brkm		tst_brkm_r
+#define tst_require_root	tst_require_root_r
+#define tst_flush		tst_flush_r
+#define tst_exit		tst_exit_r
+#define tst_environ		tst_environ_r
+#endif
+
 /* lib/tst_res.c */
 const char *strttype(int ttype);
 void tst_res(int ttype, char *fname, char *arg_fmt, ...)
-- 
1.7.1


------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2014-02-19 15:19 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-11  9:48 [LTP] [PATCH v2 2/4] lib/test.h: create macro to declare init/cleanup functions Alexey Kodanev
2014-02-11  9:48 ` [LTP] [PATCH v2 3/4] lib: compile *_r.c to libltp_r library, add testcases_r.mk Alexey Kodanev
2014-02-11  9:48 ` [LTP] [PATCH 4/4] lib: add tst_res_r.c Alexey Kodanev
2014-02-12 15:44   ` chrubis
     [not found]     ` <5128140.KmexAZrTeg@vapier>
2014-02-13 10:21       ` chrubis
     [not found]         ` <52FCA8DF.4030503@oracle.com>
2014-02-13 13:04           ` chrubis
2014-02-13  8:47   ` Mike Frysinger
2014-02-13 10:05     ` Alexey Kodanev
2014-02-13 23:06       ` Mike Frysinger
2014-02-14 13:59         ` Alexey Kodanev
2014-02-14 17:16           ` Mike Frysinger
2014-02-19 15:19         ` chrubis
2014-02-13 10:11     ` chrubis
2014-02-12 15:37 ` [LTP] [PATCH v2 2/4] lib/test.h: create macro to declare init/cleanup functions chrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.