diff --git a/3rd_party/chaiscript-6.1.0/chaiscript/dispatchkit/type_conversions.hpp b/3rd_party/chaiscript-6.1.0/chaiscript/dispatchkit/type_conversions.hpp index d9d2f374..1da22587 100644 --- a/3rd_party/chaiscript-6.1.0/chaiscript/dispatchkit/type_conversions.hpp +++ b/3rd_party/chaiscript-6.1.0/chaiscript/dispatchkit/type_conversions.hpp @@ -11,7 +11,9 @@ #ifndef CHAISCRIPT_DYNAMIC_CAST_CONVERSION_HPP_ #define CHAISCRIPT_DYNAMIC_CAST_CONVERSION_HPP_ +#ifndef RTTR_NO_CXX11_THREAD #include +#endif #include #include #include diff --git a/3rd_party/chaiscript-develop/chaiscript/dispatchkit/type_conversions.hpp b/3rd_party/chaiscript-develop/chaiscript/dispatchkit/type_conversions.hpp index d9d2f374..1da22587 100644 --- a/3rd_party/chaiscript-develop/chaiscript/dispatchkit/type_conversions.hpp +++ b/3rd_party/chaiscript-develop/chaiscript/dispatchkit/type_conversions.hpp @@ -11,7 +11,9 @@ #ifndef CHAISCRIPT_DYNAMIC_CAST_CONVERSION_HPP_ #define CHAISCRIPT_DYNAMIC_CAST_CONVERSION_HPP_ +#ifndef RTTR_NO_CXX11_THREAD #include +#endif #include #include #include diff --git a/src/rttr/detail/library/library_p.h b/src/rttr/detail/library/library_p.h index 2892502d..859a6ee2 100644 --- a/src/rttr/detail/library/library_p.h +++ b/src/rttr/detail/library/library_p.h @@ -40,7 +40,9 @@ #include #endif +#ifndef RTTR_NO_CXX11_THREAD #include +#endif namespace rttr { @@ -95,7 +97,12 @@ class RTTR_LOCAL library_private --m_load_count; - if (m_load_count.load() == 0) +#ifdef RTTR_NO_CXX11_THREAD + auto load_count = m_load_count; +#else + auto load_count = m_load_count.load(); +#endif + if (load_count == 0) { auto ret = unload_native(); if (ret) @@ -126,9 +133,15 @@ class RTTR_LOCAL library_private array_range get_global_methods() const RTTR_NOEXCEPT { return m_state_saver.get_global_methods(); } +#ifdef RTTR_NO_CXX11_THREAD + int get_load_count() const RTTR_NOEXCEPT { return m_load_count; } + + void set_load_count(int count) { m_load_count = count; } +#else int get_load_count() const RTTR_NOEXCEPT { return m_load_count.load(); } void set_load_count(int count) { m_load_count.store(count); } +#endif private: bool load_native(); @@ -141,7 +154,11 @@ class RTTR_LOCAL library_private std::string m_error_string; registration_state_saver m_state_saver; +#ifdef RTTR_NO_CXX11_THREAD + int m_load_count; +#else std::atomic_int m_load_count; +#endif #if RTTR_PLATFORM == RTTR_PLATFORM_WINDOWS HMODULE diff --git a/src/rttr/detail/type/type_register.cpp b/src/rttr/detail/type/type_register.cpp index 25181117..0a79ea66 100644 --- a/src/rttr/detail/type/type_register.cpp +++ b/src/rttr/detail/type/type_register.cpp @@ -491,7 +491,9 @@ type_data* type_register_private::register_name_if_neccessary(type_data* info) if (ret != m_orig_name_to_id.end()) return ret->m_type_data; +#ifndef RTTR_NO_CXX11_THREAD std::lock_guard lock(m_mutex); +#endif m_orig_name_to_id.insert(std::make_pair(info->type_name, type(info))); info->name = derive_name(type(info)); @@ -556,7 +558,9 @@ type_data* type_register_private::register_type(type_data* info) RTTR_NOEXCEPT info->raw_type_data = !info->raw_type_data->is_valid ? info : info->raw_type_data; { +#ifndef RTTR_NO_CXX11_THREAD std::lock_guard lock(m_mutex); +#endif m_type_data_storage.push_back(info); } @@ -607,7 +611,9 @@ void type_register_private::unregister_type(type_data* info) RTTR_NOEXCEPT // REMARK: the base_types has to be provided as argument explicitely and cannot be retrieve via the type_data itself, // because the `class_data` which holds the base_types information cannot be retrieve via the function `get_class_data` // anymore because the containing std::unique_ptr is already destroyed +#ifndef RTTR_NO_CXX11_THREAD std::lock_guard lock(m_mutex); +#endif bool found_type_data = false; @@ -672,7 +678,9 @@ std::string type_register_private::derive_template_instance_name(type_data* info void type_register_private::update_custom_name(std::string new_name, const type& t) { +#ifndef RTTR_NO_CXX11_THREAD std::lock_guard lock(m_mutex); +#endif auto& type_name = t.m_type_data->name; diff --git a/src/rttr/detail/type/type_register_p.h b/src/rttr/detail/type/type_register_p.h index 93188251..68ad3892 100644 --- a/src/rttr/detail/type/type_register_p.h +++ b/src/rttr/detail/type/type_register_p.h @@ -40,7 +40,10 @@ #include #include #include + +#ifndef RTTR_NO_CXX11_THREAD #include +#endif namespace rttr { @@ -227,7 +230,9 @@ class RTTR_LOCAL type_register_private std::vector> m_type_equal_cmp_list; std::vector> m_type_less_than_cmp_list; +#ifndef RTTR_NO_CXX11_THREAD std::mutex m_mutex; +#endif }; } // end namespace detail diff --git a/src/rttr/library.cpp b/src/rttr/library.cpp index 55b70ffa..f401133a 100644 --- a/src/rttr/library.cpp +++ b/src/rttr/library.cpp @@ -29,7 +29,10 @@ #include "rttr/detail/library/library_p.h" #include + +#ifndef RTTR_NO_CXX11_THREAD #include +#endif namespace rttr { @@ -49,7 +52,9 @@ class library_manager static std::shared_ptr create_or_find_library(string_view file_name, string_view version) { auto& manager = get_instance(); +#ifndef RTTR_NO_CXX11_THREAD std::lock_guard lock(manager.m_library_mutex); +#endif auto file_as_string = file_name.to_string(); auto itr = manager.m_library_map.find(file_as_string); @@ -71,7 +76,9 @@ class library_manager static void remove_item(const std::shared_ptr& item) { auto& manager = get_instance(); +#ifndef RTTR_NO_CXX11_THREAD std::lock_guard lock(manager.m_library_mutex); +#endif auto itr = manager.m_library_map.find(item->get_file_name().to_string()); // because we use string_view to find the item if (itr != manager.m_library_map.end()) @@ -102,7 +109,10 @@ class library_manager // use std::less in order to use string_view for finding the item std::map> m_library_map; + +#ifndef RTTR_NO_CXX11_THREAD std::mutex m_library_mutex; +#endif }; } diff --git a/src/rttr/type.cpp b/src/rttr/type.cpp index 77aa4514..a4e4d465 100644 --- a/src/rttr/type.cpp +++ b/src/rttr/type.cpp @@ -49,12 +49,15 @@ #include #include #include -#include -#include #include #include #include +#ifndef RTTR_NO_CXX11_THREAD +#include +#include +#endif + using namespace std; namespace rttr