mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #17734 from gschorcht/sys/posix/pthread_newlib_compatibility
sys/posix/pthread: newlib compatibility
This commit is contained in:
commit
644f32fb9c
@ -23,15 +23,21 @@ extern "C" {
|
||||
|
||||
/**
|
||||
* @brief Datatype to supply to pthread_once().
|
||||
* @details This data type must be compatible with the one defined
|
||||
* in newlib's `include/sys/_pthreadtypes.h`.
|
||||
*/
|
||||
typedef volatile int pthread_once_t;
|
||||
typedef struct {
|
||||
int is_initialized; /**< initialized */
|
||||
int init_executed; /**< init function executed */
|
||||
} pthread_once_t;
|
||||
|
||||
/**
|
||||
* @def PTHREAD_ONCE_INIT
|
||||
* @brief Initialization for pthread_once_t.
|
||||
* @details A zeroed out pthread_once_t is initialized.
|
||||
* @details pthread_once_t variables are declared as initialized, but
|
||||
* the init function is not yet executed.
|
||||
*/
|
||||
#define PTHREAD_ONCE_INIT 0
|
||||
#define PTHREAD_ONCE_INIT { 1, 0 }
|
||||
|
||||
/**
|
||||
* @brief Helper function that ensures that `init_routine` is called at once.
|
||||
|
@ -22,11 +22,11 @@
|
||||
|
||||
int pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
|
||||
{
|
||||
if (*once_control == PTHREAD_ONCE_INIT) {
|
||||
if (!once_control->init_executed) {
|
||||
init_routine();
|
||||
}
|
||||
|
||||
*once_control = PTHREAD_ONCE_INIT + 1;
|
||||
once_control->init_executed = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user