gettext: Sync with gettext 0.23.
[gnulib.git] / lib / call_once.c
blob54a864deda5fcdbca58a6683458071df84d66d51
1 /* ISO C 11 once-only initialization.
2 Copyright (C) 2005-2024 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2005, 2019.
18 Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-win32.h. */
20 #include <config.h>
22 #include <threads.h>
24 #include <errno.h>
26 #if defined _WIN32 && ! defined __CYGWIN__
27 /* Use Windows threads. */
29 # define WIN32_LEAN_AND_MEAN /* avoid including junk */
30 # include <windows.h>
32 # include <stdlib.h>
34 #else
35 /* Use POSIX threads. */
37 # include <pthread.h>
39 #endif
41 #if defined _WIN32 && ! defined __CYGWIN__
42 /* Use Windows threads. */
44 void
45 call_once (once_flag *flagp, void (*func) (void))
47 glwthread_once (flagp, func);
50 #else
51 /* Use POSIX threads. */
53 void
54 call_once (once_flag *flagp, void (*func) (void))
56 # if defined __CYGWIN__
57 /* Verify that once_flag and pthread_once_t are of the same size. */
58 struct _ { int v [sizeof (once_flag) == sizeof (pthread_once_t) ? 1 : -1]; };
59 pthread_once ((pthread_once_t *) flagp, func);
60 # else
61 pthread_once (flagp, func);
62 # endif
65 #endif