mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-14 11:40:35 +07:00
add state registry mutex
This commit is contained in:
@@ -19,28 +19,29 @@ namespace meta_hpp::detail
|
||||
}
|
||||
|
||||
[[nodiscard]] scope get_scope_by_name(std::string_view name) const noexcept {
|
||||
const std::lock_guard<std::mutex> lock{mutex_};
|
||||
|
||||
if ( auto iter = scopes_.find(name); iter != scopes_.end() ) {
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
return scope{};
|
||||
}
|
||||
|
||||
[[nodiscard]] scope resolve_scope(std::string_view name) {
|
||||
return ensure_scope(name);
|
||||
}
|
||||
private:
|
||||
state_registry() = default;
|
||||
const std::lock_guard<std::mutex> lock{mutex_};
|
||||
|
||||
scope ensure_scope(std::string_view name) {
|
||||
if ( auto iter = scopes_.find(name); iter != scopes_.end() ) {
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
return scopes_.emplace(
|
||||
std::string{name},
|
||||
scope_state::make(std::string{name})).first->second;
|
||||
auto state = scope_state::make(std::string{name}, metadata_map{});
|
||||
return scopes_.emplace(std::string{name}, std::move(state)).first->second;
|
||||
}
|
||||
private:
|
||||
state_registry() = default;
|
||||
private:
|
||||
mutable std::mutex mutex_;
|
||||
std::map<std::string, scope, std::less<>> scopes_;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -20,17 +20,21 @@ namespace meta_hpp::detail
|
||||
|
||||
[[nodiscard]] any_type get_type_by_id(type_id id) const noexcept {
|
||||
const std::lock_guard<std::mutex> lock{mutex_};
|
||||
|
||||
if ( auto iter = type_by_id_.find(id); iter != type_by_id_.end() ) {
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
return any_type{};
|
||||
}
|
||||
|
||||
[[nodiscard]] any_type get_type_by_rtti(const std::type_index& index) const noexcept {
|
||||
const std::lock_guard<std::mutex> lock{mutex_};
|
||||
|
||||
if ( auto iter = type_by_rtti_.find(index); iter != type_by_rtti_.end() ) {
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
return any_type{};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user