1 /*
2 * Copyright (c) 2023, Meta
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include "thrd.h"
8
9 #include <stdint.h>
10 #include <threads.h>
11
12 #include <zephyr/ztest.h>
13
14 static size_t number_of_calls;
15 static once_flag flag = ONCE_FLAG_INIT;
16
once_func(void)17 static void once_func(void)
18 {
19 number_of_calls++;
20 }
21
ZTEST(libc_once,test_call_once)22 ZTEST(libc_once, test_call_once)
23 {
24 zassert_equal(number_of_calls, 0);
25
26 call_once(&flag, once_func);
27 call_once(&flag, once_func);
28 call_once(&flag, once_func);
29
30 zassert_equal(number_of_calls, 1);
31 }
32
33 ZTEST_SUITE(libc_once, NULL, NULL, NULL, NULL, NULL);
34