diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2017-06-27 10:49:51 -0300 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2018-07-24 14:07:01 -0300 |
commit | 3c20a679b6e31af07542e56a446e2433fba53a7e (patch) | |
tree | b75bced95246c531ddd88d0f9429fbea145948ac /nptl/call_once.c | |
parent | 18d59c1b36e97d438ed964eb483c119517c18fee (diff) | |
download | glibc-3c20a679b6e31af07542e56a446e2433fba53a7e.tar glibc-3c20a679b6e31af07542e56a446e2433fba53a7e.tar.gz glibc-3c20a679b6e31af07542e56a446e2433fba53a7e.tar.bz2 glibc-3c20a679b6e31af07542e56a446e2433fba53a7e.zip |
nptl: Add C11 threads call_once functions
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,
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.
[BZ #14092]
* 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.28]: 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.
Diffstat (limited to 'nptl/call_once.c')
-rw-r--r-- | nptl/call_once.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/nptl/call_once.c b/nptl/call_once.c new file mode 100644 index 0000000000..5bc88cbbed --- /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), + "sizeof (once_flag) != sizeof (pthread_once_t)"); + _Static_assert (alignof (once_flag) == alignof (pthread_once_t), + "alignof (once_flag) != alignof (pthread_once_t)"); + __pthread_once (&flag->__data, func); +} |