mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-02-01 02:30:24 +01:00
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>
30 lines
711 B
C
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);
|
|
}
|