* [LTP] [PATCH v3] lib/test.h: add macro to declare init/cleanup functions
@ 2014-02-18 14:08 Alexey Kodanev
2014-02-25 13:17 ` chrubis
0 siblings, 1 reply; 3+ messages in thread
From: Alexey Kodanev @ 2014-02-18 14:08 UTC (permalink / raw)
To: ltp-list; +Cc: vasily.isaenko, Alexey Kodanev
Macro to use for making functions called only once in multi-threaded
tests such as init or cleanup function.
Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
---
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [LTP] [PATCH v3] lib/test.h: add macro to declare init/cleanup functions
2014-02-18 14:08 [LTP] [PATCH v3] lib/test.h: add macro to declare init/cleanup functions Alexey Kodanev
@ 2014-02-25 13:17 ` chrubis
[not found] ` <530C9E61.5080009@oracle.com>
0 siblings, 1 reply; 3+ messages in thread
From: chrubis @ 2014-02-25 13:17 UTC (permalink / raw)
To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list
Hi!
> Macro to use for making functions called only once in multi-threaded
> tests such as init or cleanup function.
>
> Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
> ---
> 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[];
This is fine, although I would rather prefix the macro name with TST_ or
LTP_ and once the pthread_once_t variable is hidden from the global
namespace we don't have to prefix it with name_fn.
If you are OK with these changes, I can commit modified version right
away ;).
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [LTP] [PATCH v3] lib/test.h: add macro to declare init/cleanup functions
[not found] ` <530C9E61.5080009@oracle.com>
@ 2014-02-25 14:10 ` chrubis
0 siblings, 0 replies; 3+ messages in thread
From: chrubis @ 2014-02-25 14:10 UTC (permalink / raw)
To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list
Hi!
> > If you are OK with these changes, I can commit modified version right
> > away ;).
> Sure!
>
Pushed along with very simple test (just to make sure the code compiles
fine).
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-02-25 14:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-18 14:08 [LTP] [PATCH v3] lib/test.h: add macro to declare init/cleanup functions Alexey Kodanev
2014-02-25 13:17 ` chrubis
[not found] ` <530C9E61.5080009@oracle.com>
2014-02-25 14:10 ` chrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox