Blender V4.5
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
70namespace blender {
71
73 private:
74 Mutex mutex_;
75 std::atomic<bool> cache_valid_ = false;
76
77 public:
85 void ensure(FunctionRef<void()> compute_cache);
86
90 void tag_dirty()
91 {
92 cache_valid_.store(false);
93 }
94
98 bool is_dirty() const
99 {
100 return !this->is_cached();
101 }
102
106 bool is_cached() const
107 {
108 return cache_valid_.load(std::memory_order_relaxed);
109 }
110};
111
112} // namespace blender
void ensure(FunctionRef< void()> compute_cache)
std::mutex Mutex
Definition BLI_mutex.hh:47