ObjFW
once.h
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #include "objfw-defs.h"
17 
18 #include "platform.h"
19 
20 #if defined(OF_HAVE_PTHREADS)
21 # include <pthread.h>
22 typedef pthread_once_t of_once_t;
23 # define OF_ONCE_INIT PTHREAD_ONCE_INIT
24 #elif defined(OF_HAVE_ATOMIC_OPS)
25 typedef volatile int of_once_t;
26 # define OF_ONCE_INIT 0
27 #elif defined(OF_AMIGAOS) || !defined(OF_HAVE_THREADS)
28 typedef int of_once_t;
29 # define OF_ONCE_INIT 0
30 #endif
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 extern void of_once(of_once_t *control, void (*func)(void));
36 #ifdef __cplusplus
37 }
38 #endif