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 program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "objfw-defs.h"
21 
22 #import "macros.h"
23 
24 #if defined(OF_HAVE_PTHREADS)
25 # include <pthread.h>
26 typedef pthread_once_t OFOnceControl;
27 # define OFOnceControlInitValue PTHREAD_ONCE_INIT
28 #elif defined(OF_HAVE_ATOMIC_OPS)
29 typedef volatile int OFOnceControl;
30 # define OFOnceControlInitValue 0
31 #elif defined(OF_AMIGAOS) || !defined(OF_HAVE_THREADS)
32 typedef int OFOnceControl;
33 # define OFOnceControlInitValue 0
34 #endif
35 
36 OF_ASSUME_NONNULL_BEGIN
37 
40 typedef void (*OFOnceFunction)(void);
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
53 extern void OFOnce(OFOnceControl *control, OFOnceFunction function);
54 #ifdef __cplusplus
55 }
56 #endif
57 
58 OF_ASSUME_NONNULL_END
void OFOnce(OFOnceControl *control, OFOnceFunction function)
Executes the specified function exactly once in the application&#39;s lifetime, even in a multi-threaded ...
Definition: OFOnce.m:37