From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Subject: [PATCH v8 3/8] nptl: Add C11 threads call_once functions
Date: Fri, 2 Feb 2018 15:04:39 -0200 [thread overview]
Message-ID: <1517591084-11347-4-git-send-email-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <1517591084-11347-1-git-send-email-adhemerval.zanella@linaro.org>
This patch adds the call_* definitions from C11 threads (ISO/IEC 9899:2011),
more specifically call_once and required types.
Mostly of the definitions are composed based on POSIX conterparts,including
once_flag (pthread_once_t). The idea is to make possible to share POSIX
internal implementations for mostly of the code (and making adjustment only
when required).
Checked with a build for all major ABI (aarch64-linux-gnu, alpha-linux-gnu,
arm-linux-gnueabi, i386-linux-gnu, ia64-linux-gnu, m68k-linux-gnu,
microblaze-linux-gnu [1], mips{64}-linux-gnu, nios2-linux-gnu,
powerpc{64le}-linux-gnu, s390{x}-linux-gnu, sparc{64}-linux-gnu,
tile{pro,gx}-linux-gnu, and x86_64-linux-gnu).
Also ran a full check on aarch64-linux-gnu, x86_64-linux-gnu, i686-linux-gnu,
arm-linux-gnueabhf, and powerpc64le-linux-gnu.
* conform/data/threads.h-data (ONCE_FLAG_INIT): New macro.
(once_flag): New type.
(call_once): New function.
* nptl/Makefile (libpthread-routines): Add call_once object.
* nptl/Versions (libphread) [GLIBC_2.27]: Add call_once symbol.
* nptl/call_once.c: New file.
* sysdeps/nptl/threads.h (ONCE_FLAG_INIT): New define.
(once_flag): New type.
(call_once): New prototype.
---
ChangeLog | 10 ++++++++++
conform/data/threads.h-data | 5 +++++
nptl/Makefile | 2 +-
nptl/Versions | 2 +-
nptl/call_once.c | 31 +++++++++++++++++++++++++++++++
sysdeps/nptl/threads.h | 8 ++++++++
6 files changed, 56 insertions(+), 2 deletions(-)
create mode 100644 nptl/call_once.c
diff --git a/conform/data/threads.h-data b/conform/data/threads.h-data
index bb5ca75..70b2fe0 100644
--- a/conform/data/threads.h-data
+++ b/conform/data/threads.h-data
@@ -1,5 +1,7 @@
#if defined ISO11
+macro ONCE_FLAG_INIT
+
constant thrd_success
constant thrd_busy
constant thrd_error
@@ -13,6 +15,7 @@ constant mtx_timed
type thrd_t
type thrd_start_t
type mtx_t
+type once_flag
function int thrd_create (thrd_t*, thrd_start_t, void*)
function int thrd_equal (thrd_t, thrd_t)
@@ -30,6 +33,8 @@ function int mtx_trylock (mtx_t*)
function int mtx_unlock (mtx_t*)
function void mtx_destroy (mtx_t*)
+function void call_once (once_flag*, void (*)(void))
+
#include "time.h-data"
#endif
diff --git a/nptl/Makefile b/nptl/Makefile
index 1b8a6a8..e539df8 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -143,7 +143,7 @@ libpthread-routines = nptl-init vars events version pt-interp \
thrd_create thrd_current thrd_detach thrd_equal \
thrd_exit thrd_join thrd_sleep thrd_yield \
mtx_destroy mtx_init mtx_lock mtx_timedlock \
- mtx_trylock mtx_unlock
+ mtx_trylock mtx_unlock call_once
# pthread_setuid pthread_seteuid pthread_setreuid \
# pthread_setresuid \
# pthread_setgid pthread_setegid pthread_setregid \
diff --git a/nptl/Versions b/nptl/Versions
index a1969e3..f09e295 100644
--- a/nptl/Versions
+++ b/nptl/Versions
@@ -269,7 +269,7 @@ libpthread {
GLIBC_2.28 {
thrd_create; thrd_current; thrd_detach; thrd_equal; thrd_exit; thrd_join;
thrd_sleep; thrd_yield; mtx_init; mtx_lock; mtx_timedlock; mtx_trylock;
- mtx_unlock; mtx_destroy;
+ mtx_unlock; mtx_destroy; call_once;
}
GLIBC_PRIVATE {
diff --git a/nptl/call_once.c b/nptl/call_once.c
new file mode 100644
index 0000000..d66d728
--- /dev/null
+++ b/nptl/call_once.c
@@ -0,0 +1,31 @@
+/* C11 threads call once implementation.
+ Copyright (C) 2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stdalign.h>
+
+#include "thrd_priv.h"
+
+void
+call_once (once_flag *flag, void (*func)(void))
+{
+ _Static_assert (sizeof (once_flag) == sizeof (pthread_once_t),
+ "once_flag size");
+ _Static_assert (alignof (once_flag) == alignof (pthread_once_t),
+ "once_flag alignment");
+ __pthread_once (flag, func);
+}
diff --git a/sysdeps/nptl/threads.h b/sysdeps/nptl/threads.h
index 42d9b5c..6c9c3ef 100644
--- a/sysdeps/nptl/threads.h
+++ b/sysdeps/nptl/threads.h
@@ -27,8 +27,11 @@ __BEGIN_DECLS
#include <bits/pthreadtypes-arch.h>
#include <bits/types/struct_timespec.h>
+#define ONCE_FLAG_INIT 0
+
typedef unsigned long int thrd_t;
typedef int (*thrd_start_t) (void*);
+typedef int __ONCE_ALIGNMENT once_flag;
/* Exit and error codes. */
enum
@@ -129,6 +132,11 @@ extern int mtx_unlock (mtx_t *__mutex);
/* Destroy the mutex object pointed by __MUTEX. */
extern void mtx_destroy (mtx_t *__mutex);
+
+/* Call function __FUNC exactly once, even if invoked from several threads.
+ All calls must be made with the same __FLAGS object. */
+extern void call_once (once_flag *__flag, void (*__func)(void));
+
__END_DECLS
#endif /* _THREADS_H */
--
2.7.4
next prev parent reply other threads:[~2018-02-02 17:03 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-02 17:04 [PATCH v8 0/8] Add support for ISO C threads.h Adhemerval Zanella
2018-02-02 17:04 ` [PATCH v8 1/8] nptl: Add C11 threads thrd_* functions Adhemerval Zanella
2018-02-08 13:49 ` Gabriel F. T. Gomes
2018-02-09 10:56 ` Adhemerval Zanella
2018-02-26 12:28 ` Gabriel F. T. Gomes
2018-07-06 12:46 ` Florian Weimer
2018-07-10 19:26 ` Adhemerval Zanella
2018-07-11 15:49 ` Szabolcs Nagy
2018-07-11 16:24 ` Adhemerval Zanella
2018-07-12 12:18 ` Florian Weimer
2018-07-12 17:38 ` Adhemerval Zanella
2018-07-13 7:03 ` Florian Weimer
2018-07-12 16:46 ` Florian Weimer
2018-07-12 17:52 ` Adhemerval Zanella
2018-07-12 18:24 ` Florian Weimer
2018-07-12 19:19 ` Adhemerval Zanella
2018-07-12 19:26 ` Florian Weimer
2018-07-12 19:41 ` Adhemerval Zanella
2018-07-12 19:32 ` Adhemerval Zanella
2018-07-12 19:35 ` Florian Weimer
2018-07-12 19:43 ` Adhemerval Zanella
2018-07-13 9:45 ` Florian Weimer
2018-07-13 12:59 ` Adhemerval Zanella
2018-07-13 13:04 ` Florian Weimer
2018-07-13 13:18 ` Adhemerval Zanella
2018-07-13 13:21 ` Florian Weimer
2018-07-13 9:48 ` Florian Weimer
2018-07-25 7:20 ` Andreas Schwab
2018-07-25 7:38 ` Florian Weimer
2018-07-25 10:29 ` Joseph Myers
2018-02-02 17:04 ` [PATCH v8 2/8] nptl: Add C11 threads mtx_* functions Adhemerval Zanella
2018-07-06 12:51 ` Florian Weimer
2018-07-10 12:35 ` Adhemerval Zanella
2018-07-12 18:39 ` Florian Weimer
2018-07-12 20:30 ` Adhemerval Zanella
2018-07-12 20:38 ` Florian Weimer
2018-07-13 13:08 ` Adhemerval Zanella
2018-07-13 13:10 ` Florian Weimer
2018-07-24 12:04 ` Adhemerval Zanella
2018-07-24 16:04 ` Carlos O'Donell
2018-02-02 17:04 ` Adhemerval Zanella [this message]
2018-07-13 9:32 ` [PATCH v8 3/8] nptl: Add C11 threads call_once functions Florian Weimer
2018-02-02 17:04 ` [PATCH v8 4/8] nptl: Add C11 threads cnd_* functions Adhemerval Zanella
2018-02-02 17:04 ` [PATCH v8 5/8] nptl: Add C11 threads tss_* functions Adhemerval Zanella
2018-07-12 16:48 ` Florian Weimer
2018-07-12 20:32 ` Adhemerval Zanella
2018-07-12 20:37 ` Florian Weimer
2018-02-02 17:04 ` [PATCH v8 6/8] nptl: Add abilist symbols for C11 threads Adhemerval Zanella
2018-07-13 9:50 ` Florian Weimer
2018-07-13 15:49 ` Adhemerval Zanella
2018-07-13 17:49 ` Florian Weimer
2018-07-13 18:47 ` Adhemerval Zanella
2018-07-13 19:56 ` Florian Weimer
2018-07-13 21:09 ` Adhemerval Zanella
2018-07-14 13:50 ` Florian Weimer
2018-07-18 17:40 ` Joseph Myers
2018-07-18 20:02 ` Adhemerval Zanella
2018-07-18 21:19 ` Florian Weimer
2018-02-02 17:04 ` [PATCH v8 7/8] nptl: Add test cases for ISO " Adhemerval Zanella
2018-07-13 9:31 ` Florian Weimer
2018-07-13 13:10 ` Adhemerval Zanella
2018-07-13 13:11 ` Florian Weimer
2018-07-13 13:29 ` Adhemerval Zanella
2018-07-17 13:53 ` Adhemerval Zanella
2018-02-02 17:04 ` [PATCH v8 8/8] Add manual documentation for threads.h Adhemerval Zanella
2018-06-27 13:39 ` [PATCH v8 0/8] Add support for ISO C threads.h Adhemerval Zanella
2018-07-19 17:46 ` Adhemerval Zanella
2018-07-19 18:43 ` Carlos O'Donell
2018-07-19 19:12 ` Rical Jasan
2018-07-19 19:58 ` Adhemerval Zanella
2018-07-21 0:26 ` Rical Jasan
2018-07-21 2:11 ` Carlos O'Donell
2018-07-21 6:22 ` Rical Jasan
2018-07-21 13:40 ` Adhemerval Zanella
2018-07-19 21:26 ` Joseph Myers
2018-07-20 12:32 ` Adhemerval Zanella
2018-07-20 13:22 ` Rical Jasan
2018-07-20 13:54 ` Rical Jasan
2018-07-20 14:04 ` Carlos O'Donell
2018-07-20 15:02 ` [PATCH v8 0/8] Add support for ISO C threads.h [thrd_exit] Rical Jasan
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
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1517591084-11347-4-git-send-email-adhemerval.zanella@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=libc-alpha@sourceware.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).