mesa/src/util/u_call_once.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

30 lines
711 B
C

/*
* Copyright 2022 Yonggang Luo
* SPDX-License-Identifier: MIT
*/
#include "u_call_once.h"
struct util_call_once_context_t
{
const void *data;
util_call_once_data_func func;
};
static thread_local struct util_call_once_context_t call_once_context;
static void
util_call_once_data_slow_once(void)
{
struct util_call_once_context_t *once_context = &call_once_context;
once_context->func(once_context->data);
}
void
util_call_once_data_slow(once_flag *once, util_call_once_data_func func, const void *data)
{
struct util_call_once_context_t *once_context = &call_once_context;
once_context->data = data;
once_context->func = func;
call_once(once, util_call_once_data_slow_once);
}