KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Data Structures | Macros | Functions
once.h File Reference

Dynamic package initialization. More...

#include <sys/cdefs.h>

Go to the source code of this file.

Data Structures

struct  kthread_once_t
 Object type backing kthread_once. More...
 

Macros

#define KTHREAD_ONCE_INIT   { 1, 0 }
 Initializer for a kthread_once_t object. More...
 

Functions

int kthread_once (kthread_once_t *once_control, void(*init_routine)(void))
 Run a function once. More...
 

Detailed Description

Dynamic package initialization.

This file provides definitions for an object that functions the same way as the pthread_once_t function does from the POSIX specification. This object type and functionality is generally used to make sure that a given initialization function is run once, and only once, no matter how many threads attempt to call it.

Author
Lawrence Sebald

Macro Definition Documentation

#define KTHREAD_ONCE_INIT   { 1, 0 }

Initializer for a kthread_once_t object.

Function Documentation

int kthread_once ( kthread_once_t once_control,
void(*)(void)  init_routine 
)

Run a function once.

This function, when used with a kthread_once_t object (that should be shared amongst all threads) will run the init_routine once, and set the once_control to make sure that the function will not be run again (as long as all threads attempt to call the init_routine through this function.

Parameters
once_controlThe kthread_once_t object to run against.
init_routineThe function to call.
Return values
-1On failure, and sets errno to one of the following: ENOMEM if out of memory, EPERM if called inside an interrupt, or EINTR if interrupted.
0On success.