Blender V4.3
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
5#pragma once
6
61#include <atomic>
62#include <mutex>
63
64#include "BLI_function_ref.hh"
65
66namespace blender {
67
69 private:
70 std::mutex mutex_;
71 std::atomic<bool> cache_valid_ = false;
72
73 public:
81 void ensure(FunctionRef<void()> compute_cache);
82
86 void tag_dirty()
87 {
88 cache_valid_.store(false);
89 }
90
94 bool is_dirty() const
95 {
96 return !this->is_cached();
97 }
98
102 bool is_cached() const
103 {
104 return cache_valid_.load(std::memory_order_relaxed);
105 }
106};
107
108} // namespace blender
void ensure(FunctionRef< void()> compute_cache)