@@ -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
@@ -142,7 +142,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 \
@@ -269,7 +269,7 @@ libpthread {
GLIBC_2.27 {
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 {
new file mode 100644
@@ -0,0 +1,33 @@
+/* C11 threads call once implementation.
+ Copyright (C) 2017 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"
+
+/* Call function func exactly once, even if invoked from several threads.
+ All calls must be made with the same flag object. */
+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);
+}
@@ -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,10 @@ 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 __flag object. */
+extern void call_once (once_flag *__flag, void (*__func)(void));
+
__END_DECLS
#endif /* _THREADS_H */