Blender
V5.0
source
blender
blenlib
BLI_cache_mutex.hh
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2023 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9
#pragma once
10
64
65
#include <atomic>
66
67
#include "
BLI_function_ref.hh
"
68
#include "
BLI_mutex.hh
"
69
70
namespace
blender
{
71
72
class
CacheMutex
{
73
private
:
74
Mutex
mutex_;
75
std::atomic<bool> cache_valid_ =
false
;
76
77
public
:
85
void
ensure
(
const
FunctionRef
<
void
()> compute_cache)
86
{
87
/* Handle fast case when the cache is up-to-date. */
88
if
(cache_valid_.load(std::memory_order_acquire)) {
89
return
;
90
}
91
this->ensure_impl(compute_cache);
92
}
93
97
void
tag_dirty
()
98
{
99
cache_valid_.store(
false
);
100
}
101
105
bool
is_dirty
()
const
106
{
107
return
!this->
is_cached
();
108
}
109
113
bool
is_cached
()
const
114
{
115
return
cache_valid_.load(std::memory_order_relaxed);
116
}
117
118
private
:
119
void
ensure_impl(
FunctionRef
<
void
()> compute_cache);
120
};
121
122
}
// namespace blender
BLI_function_ref.hh
BLI_mutex.hh
blender::CacheMutex
Definition
BLI_cache_mutex.hh:72
blender::CacheMutex::tag_dirty
void tag_dirty()
Definition
BLI_cache_mutex.hh:97
blender::CacheMutex::ensure
void ensure(const FunctionRef< void()> compute_cache)
Definition
BLI_cache_mutex.hh:85
blender::CacheMutex::is_dirty
bool is_dirty() const
Definition
BLI_cache_mutex.hh:105
blender::CacheMutex::is_cached
bool is_cached() const
Definition
BLI_cache_mutex.hh:113
blender::FunctionRef
Definition
BLI_function_ref.hh:72
blender
Definition
ANIM_action.hh:36
blender::Mutex
std::mutex Mutex
Definition
BLI_mutex.hh:47
Generated on
for Blender by
doxygen
1.16.1