KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
once.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 include/kos/once.h
4 Copyright (C) 2009, 2010, 2023 Lawrence Sebald
5
6*/
7
8#ifndef __KOS_ONCE_H
9#define __KOS_ONCE_H
10
11/** \file kos/once.h
12 \brief Dynamic package initialization.
13 \ingroup kthreads
14
15 This file provides definitions for an object that functions the same way as
16 the pthread_once_t function does from the POSIX specification. This object
17 type and functionality is generally used to make sure that a given
18 initialization function is run once, and only once, no matter how many
19 threads attempt to call it.
20
21 \author Lawrence Sebald
22*/
23
24#include <sys/cdefs.h>
25
26__BEGIN_DECLS
27
28/** \brief Object type backing kthread_once.
29
30 This object type should always be initialized with the KTHREAD_ONCE_INIT
31 macro.
32
33 \headerfile kos/once.h
34*/
35typedef volatile int kthread_once_t;
36
37/** \brief Initializer for a kthread_once_t object. */
38#define KTHREAD_ONCE_INIT 0
39
40/** \brief Run a function once.
41
42 This function, when used with a kthread_once_t object (that should be shared
43 amongst all threads) will run the init_routine once, and set the
44 once_control to make sure that the function will not be run again (as long
45 as all threads attempt to call the init_routine through this function.
46
47 \param once_control The kthread_once_t object to run against.
48 \param init_routine The function to call.
49 \retval -1 On failure, and sets errno to one of the following: EPERM if
50 called inside an interrupt or EINVAL if *once_control is not
51 valid or was not initialized with KTHREAD_ONCE_INIT.
52 \retval 0 On success. */
53int kthread_once(kthread_once_t *once_control, void (*init_routine)(void));
54
55__END_DECLS
56
57#endif /* !__KOS_ONCE_H */
volatile int kthread_once_t
Object type backing kthread_once.
Definition once.h:35
int kthread_once(kthread_once_t *once_control, void(*init_routine)(void))
Run a function once.