Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix thread-safety issues #325

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/rttr/detail/type/type_register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,9 +1115,13 @@ flat_map<string_view, type>& type_register_private::get_orig_name_to_id()

/////////////////////////////////////////////////////////////////////////////////////

flat_map<std::string, type, hash>& type_register_private::get_custom_name_to_id()
type type_register_private::get_type_by_custom_name(string_view name)
{
return m_custom_name_to_id;
std::lock_guard<std::mutex> lock(m_mutex);
auto ret = m_custom_name_to_id.find(name);
if (ret != m_custom_name_to_id.end())
return (*ret);
return detail::get_invalid_type();
}

/////////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/rttr/detail/type/type_register_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class RTTR_LOCAL type_register_private
std::vector<type_data*>& get_type_data_storage();
std::vector<type>& get_type_storage();
flat_map<string_view, type>& get_orig_name_to_id();
flat_map<std::string, type, hash>& get_custom_name_to_id();
type get_type_by_custom_name(string_view name);

/////////////////////////////////////////////////////////////////////////////////////

Expand Down
7 changes: 1 addition & 6 deletions src/rttr/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,7 @@ variant type::invoke(string_view name, std::vector<argument> args)

type type::get_by_name(string_view name) RTTR_NOEXCEPT
{
auto& custom_name_to_id = detail::type_register_private::get_instance().get_custom_name_to_id();
auto ret = custom_name_to_id.find(name);
if (ret != custom_name_to_id.end())
return (*ret);

return detail::get_invalid_type();
return detail::type_register_private::get_instance().get_type_by_custom_name(name);
}

/////////////////////////////////////////////////////////////////////////////////////////
Expand Down