Blender
V4.3
source
blender
blenlib
intern
cache_mutex.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2023 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
5
#include "
BLI_cache_mutex.hh
"
6
#include "
BLI_task.hh
"
7
8
namespace
blender
{
9
10
void
CacheMutex::ensure
(
const
FunctionRef
<
void
()> compute_cache)
11
{
12
if
(cache_valid_.load(std::memory_order_acquire)) {
13
return
;
14
}
15
std::scoped_lock
lock
{mutex_};
16
/* Double checked lock. */
17
if
(cache_valid_.load(std::memory_order_relaxed)) {
18
return
;
19
}
20
/* Use task isolation because a mutex is locked and the cache computation might use
21
* multi-threading. */
22
threading::isolate_task
(compute_cache);
23
24
cache_valid_.store(
true
, std::memory_order_release);
25
}
26
27
}
// namespace blender
BLI_cache_mutex.hh
BLI_task.hh
lock
volatile int lock
Definition
atomic_ops_unix.h:0
blender::CacheMutex::ensure
void ensure(FunctionRef< void()> compute_cache)
Definition
cache_mutex.cc:10
blender::FunctionRef
Definition
BLI_function_ref.hh:74
blender::threading::isolate_task
void isolate_task(const Function &function)
Definition
BLI_task.hh:226
blender
Definition
ANIM_action.hh:36
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0