1 /*
2  * Copyright 2022 Yonggang Luo
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #include "u_call_once.h"
7 
8 struct util_call_once_context_t
9 {
10    const void *data;
11    util_call_once_data_func func;
12 };
13 
14 static thread_local struct util_call_once_context_t call_once_context;
15 
16 static void
util_call_once_data_slow_once(void)17 util_call_once_data_slow_once(void)
18 {
19    struct util_call_once_context_t *once_context = &call_once_context;
20    once_context->func(once_context->data);
21 }
22 
23 void
util_call_once_data_slow(once_flag * once,util_call_once_data_func func,const void * data)24 util_call_once_data_slow(once_flag *once, util_call_once_data_func func, const void *data)
25 {
26    struct util_call_once_context_t *once_context = &call_once_context;
27    once_context->data = data;
28    once_context->func = func;
29    call_once(once, util_call_once_data_slow_once);
30 }
31