ObjFW
OFOnce.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2024 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 #import "macros.h"
19 
20 #if defined(OF_HAVE_PTHREADS)
21 # include <pthread.h>
22 typedef pthread_once_t OFOnceControl;
23 # define OFOnceControlInitValue PTHREAD_ONCE_INIT
24 #elif defined(OF_HAVE_ATOMIC_OPS)
25 typedef volatile int OFOnceControl;
26 # define OFOnceControlInitValue 0
27 #elif defined(OF_AMIGAOS) || !defined(OF_HAVE_THREADS)
28 typedef int OFOnceControl;
29 # define OFOnceControlInitValue 0
30 #endif
31 
32 OF_ASSUME_NONNULL_BEGIN
33 
36 typedef void (*OFOnceFunction)(void);
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
49 extern void OFOnce(OFOnceControl *control, OFOnceFunction function);
50 #ifdef __cplusplus
51 }
52 #endif
53 
54 OF_ASSUME_NONNULL_END
void OFOnce(OFOnceControl *control, OFOnceFunction function)
Executes the specified function exactly once in the application's lifetime, even in a multi-threaded ...
Definition: OFOnce.m:33