1 /*
2  * Copyright 2022 Yonggang Luo
3  * SPDX-License-Identifier: MIT
4  *
5  */
6 
7 #include "simple_mtx.h"
8 
9 #if !UTIL_FUTEX_SUPPORTED
10 
_simple_mtx_plain_init_once(simple_mtx_t * mtx)11 void _simple_mtx_plain_init_once(simple_mtx_t *mtx)
12 {
13    mtx_init(&mtx->mtx, mtx_plain);
14 }
15 
16 void
simple_mtx_init(simple_mtx_t * mtx,ASSERTED int type)17 simple_mtx_init(simple_mtx_t *mtx, ASSERTED int type)
18 {
19    const util_once_flag flag = UTIL_ONCE_FLAG_INIT;
20    assert(type == mtx_plain);
21    mtx->flag = flag;
22    _simple_mtx_init_with_once(mtx);
23 }
24 
25 void
simple_mtx_destroy(simple_mtx_t * mtx)26 simple_mtx_destroy(simple_mtx_t *mtx)
27 {
28    if (mtx->flag.called) {
29       mtx_destroy(&mtx->mtx);
30    }
31 }
32 
33 #endif /* !UTIL_FUTEX_SUPPORTED */
34