Made assets::data_stores thread safe.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "generic/generic_basic_store.hpp"
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include "assets/data/shader_source_data.hpp"
|
||||
#include "assets/data_views/shader_source_view.hpp"
|
||||
|
||||
@@ -95,29 +96,33 @@ public:
|
||||
using size_type = std::size_t;
|
||||
using count_type = ztu::u32;
|
||||
|
||||
using iterator_type = shader_source_store_iterator<char>;
|
||||
using iterator = shader_source_store_iterator<char>;
|
||||
using const_iterator = shader_source_store_iterator<const char>;
|
||||
using view_type = std::ranges::subrange<iterator_type>;
|
||||
using view_type = std::ranges::subrange<iterator>;
|
||||
using const_view_type = std::ranges::subrange<const_iterator>;
|
||||
using id_type = shader_source_id;
|
||||
using data_type = shader_source_data;
|
||||
|
||||
// TODO not storing metadata
|
||||
inline id_type add(
|
||||
shader_source_id id,
|
||||
const shader_source_data& shader_source
|
||||
);
|
||||
bool insert(id_type id, const data_type& data);
|
||||
|
||||
[[nodiscard]] inline std::pair<iterator_type, bool> find(id_type id);
|
||||
bool insert(iterator it, id_type id, const data_type& data);
|
||||
|
||||
[[nodiscard]] inline std::pair<const_iterator, bool> find(id_type id) const;
|
||||
[[nodiscard]] std::pair<iterator, bool> find(id_type id);
|
||||
|
||||
inline void remove(const iterator_type& it);
|
||||
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
|
||||
|
||||
|
||||
inline void remove(const iterator& it);
|
||||
|
||||
inline void clear();
|
||||
|
||||
[[nodiscard]] inline iterator_type begin();
|
||||
[[nodiscard]] inline std::shared_lock<std::shared_mutex> acquire_read_lock() const;
|
||||
|
||||
[[nodiscard]] inline iterator_type end();
|
||||
[[nodiscard]] inline std::unique_lock<std::shared_mutex> acquire_write_lock();
|
||||
|
||||
[[nodiscard]] inline iterator begin();
|
||||
|
||||
[[nodiscard]] inline iterator end();
|
||||
|
||||
[[nodiscard]] inline const_iterator begin() const;
|
||||
|
||||
@@ -127,12 +132,19 @@ public:
|
||||
|
||||
[[nodiscard]] inline const_iterator cend() const;
|
||||
|
||||
protected:
|
||||
bool unsafe_insert(iterator it, id_type id, const data_type& data);
|
||||
|
||||
[[nodiscard]] std::pair<iterator, bool> unsafe_find(id_type id);
|
||||
|
||||
[[nodiscard]] std::pair<const_iterator, bool> unsafe_find(id_type id) const;
|
||||
|
||||
private:
|
||||
std::vector<id_type> m_ids;
|
||||
std::vector<char> m_strings;
|
||||
std::vector<count_type> m_lengths;
|
||||
std::vector<shader_source_data::metadata> m_metadata;
|
||||
mutable std::shared_mutex m_mutex;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user