@@ -128,7 +128,7 @@ namespace cereal
128128 static bool exists ( std::type_index const & baseIndex, std::type_index const & derivedIndex )
129129 {
130130 // First phase of lookup - match base type index
131- auto & baseMap = StaticObject<PolymorphicCasters>::getInstance ().map ;
131+ auto const & baseMap = StaticObject<PolymorphicCasters>::getInstance ().map ;
132132 auto baseIter = baseMap.find ( baseIndex );
133133 if (baseIter == baseMap.end ())
134134 return false ;
@@ -151,7 +151,7 @@ namespace cereal
151151 static std::vector<PolymorphicCaster const *> const & lookup ( std::type_index const & baseIndex, std::type_index const & derivedIndex, F && exceptionFunc )
152152 {
153153 // First phase of lookup - match base type index
154- auto & baseMap = StaticObject<PolymorphicCasters>::getInstance ().map ;
154+ auto const & baseMap = StaticObject<PolymorphicCasters>::getInstance ().map ;
155155 auto baseIter = baseMap.find ( baseIndex );
156156 if ( baseIter == baseMap.end () )
157157 exceptionFunc ();
@@ -161,7 +161,7 @@ namespace cereal
161161 auto derivedIter = derivedMap.find ( derivedIndex );
162162 if ( derivedIter == derivedMap.end () )
163163 exceptionFunc ();
164-
164+
165165 return derivedIter->second ;
166166 }
167167
@@ -218,6 +218,7 @@ namespace cereal
218218 assuming dynamic type information is available */
219219 PolymorphicVirtualCaster ()
220220 {
221+ const auto lock = StaticObject<PolymorphicCasters>::lock ();
221222 auto & baseMap = StaticObject<PolymorphicCasters>::getInstance ().map ;
222223 auto baseKey = std::type_index (typeid (Base));
223224 auto lb = baseMap.lower_bound (baseKey);
@@ -236,7 +237,7 @@ namespace cereal
236237 auto checkRelation = [](std::type_index const & baseInfo, std::type_index const & derivedInfo)
237238 {
238239 const bool exists = PolymorphicCasters::exists ( baseInfo, derivedInfo );
239- return std::make_pair ( exists, exists ? PolymorphicCasters::lookup ( baseInfo, derivedInfo, [](){} ) :
240+ return std::make_pair ( exists, exists ? PolymorphicCasters::lookup ( baseInfo, derivedInfo, [](){} ) :
240241 std::vector<PolymorphicCaster const *>{} );
241242 };
242243
@@ -409,6 +410,7 @@ namespace cereal
409410 InputBindingCreator ()
410411 {
411412 auto & map = StaticObject<InputBindingMap<Archive>>::getInstance ().map ;
413+ auto lock = StaticObject<InputBindingMap<Archive>>::lock ();
412414 auto key = std::string (binding_name<T>::name ());
413415 auto lb = map.lower_bound (key);
414416
0 commit comments