mesa/src/util/simple_mtx.c
Yonggang Luo 7dfd54cf4a util: Add util_call_once for optimize call to util_call_once_with_context out for hot path
For hot path, there is only need to a load instruction to load if initialized are true now,
So the extra cost is minimal.

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Acked-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18323>
2022-09-22 04:16:29 +00:00

33 lines
566 B
C

/*
* 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 */