From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 2/3] tst_test: add macro helper to invoke pthread_once()
Date: Mon, 23 Jan 2017 15:58:28 +0100 [thread overview]
Message-ID: <20170123145828.GD25788@rei.lan> (raw)
In-Reply-To: <1482154595-4641-2-git-send-email-alexey.kodanev@oracle.com>
Hi!
> Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
> ---
> include/tst_test.h | 14 ++++++++++++++
> 1 files changed, 14 insertions(+), 0 deletions(-)
>
> diff --git a/include/tst_test.h b/include/tst_test.h
> index 3c77a98..a4ba167 100644
> --- a/include/tst_test.h
> +++ b/include/tst_test.h
> @@ -71,6 +71,20 @@ pid_t safe_fork(const char *filename, unsigned int lineno);
> ({int ret = expr; \
> ret != 0 ? tst_res(TINFO, #expr " failed"), ret : ret; }) \
>
> +/*
> + * 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 TST_DECLARE_ONCE_FN(name_fn, exec_fn) \
> + void name_fn(void) \
> + { \
> + static pthread_once_t ltp_once = PTHREAD_ONCE_INIT; \
> + pthread_once(<p_once, exec_fn); \
> + }
This should rather be in tst_safe_pthread.h, otherwise it's fine.
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2017-01-23 14:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-19 13:36 [LTP] [PATCH 1/3] tst_test: add tst_parse_long() Alexey Kodanev
2016-12-19 13:36 ` [LTP] [PATCH 2/3] tst_test: add macro helper to invoke pthread_once() Alexey Kodanev
2017-01-23 14:58 ` Cyril Hrubis [this message]
2016-12-19 13:36 ` [LTP] [PATCH 3/3] netstress.c: convert to new library API Alexey Kodanev
2017-01-23 14:57 ` Cyril Hrubis
2017-01-27 14:07 ` Alexey Kodanev
2017-01-30 13:13 ` Cyril Hrubis
2017-01-30 13:32 ` Alexey Kodanev
2017-01-23 14:26 ` [LTP] [PATCH 1/3] tst_test: add tst_parse_long() Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170123145828.GD25788@rei.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.