summaryrefslogtreecommitdiff
path: root/src/util/simple_mtx.c
blob: 8b53e10f9a503e50ec013922a77f34852e519a10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
 * Copyright 2022 Yonggang Luo
 * SPDX-License-Identifier: MIT
 *
 */

#include "simple_mtx.h"

#if !UTIL_FUTEX_SUPPORTED

void _simple_mtx_plain_init_once(simple_mtx_t *mtx)
{
   mtx_init(&mtx->mtx, mtx_plain);
}

void
simple_mtx_init(simple_mtx_t *mtx, ASSERTED int type)
{
   const util_once_flag flag = UTIL_ONCE_FLAG_INIT;
   assert(type == mtx_plain);
   mtx->flag = flag;
   _simple_mtx_init_with_once(mtx);
}

void
simple_mtx_destroy(simple_mtx_t *mtx)
{
   if (mtx->flag.called) {
      mtx_destroy(&mtx->mtx);
   }
}

#endif /* !UTIL_FUTEX_SUPPORTED */