KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
once.h
Go to the documentation of this file.
1 /* KallistiOS ##version##
2 
3  include/kos/once.h
4  Copyright (C) 2009, 2010 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 
14  This file provides definitions for an object that functions the same way as
15  the pthread_once_t function does from the POSIX specification. This object
16  type and functionality is generally used to make sure that a given
17  initialization function is run once, and only once, no matter how many
18  threads attempt to call it.
19 
20  \author Lawrence Sebald
21 */
22 
23 #include <sys/cdefs.h>
24 
25 __BEGIN_DECLS
26 
27 /** \brief Object type backing kthread_once.
28 
29  This object type should always be initialized with the KTHREAD_ONCE_INIT
30  macro.
31 
32  \headerfile kos/once.h
33 */
34 typedef struct {
36  int run;
38 
39 /** \brief Initializer for a kthread_once_t object. */
40 #define KTHREAD_ONCE_INIT { 1, 0 }
41 
42 /** \brief Run a function once.
43 
44  This function, when used with a kthread_once_t object (that should be shared
45  amongst all threads) will run the init_routine once, and set the
46  once_control to make sure that the function will not be run again (as long
47  as all threads attempt to call the init_routine through this function.
48 
49  \param once_control The kthread_once_t object to run against.
50  \param init_routine The function to call.
51  \retval -1 On failure, and sets errno to one of the following: ENOMEM
52  if out of memory, EPERM if called inside an interrupt, or
53  EINTR if interrupted.
54  \retval 0 On success. */
55 int kthread_once(kthread_once_t *once_control, void (*init_routine)(void));
56 
57 __END_DECLS
58 
59 #endif /* !__KOS_ONCE_H */
Object type backing kthread_once.
Definition: once.h:34
int run
Definition: once.h:36
int initialized
Definition: once.h:35
int kthread_once(kthread_once_t *once_control, void(*init_routine)(void))
Run a function once.