@@ -141,7 +141,7 @@ class Blackboard
141141 const Blackboard* rootBlackboard () const ;
142142
143143private:
144- mutable std::mutex mutex_ ;
144+ mutable std::mutex storage_mutex_ ;
145145 mutable std::recursive_mutex entry_mutex_;
146146 std::unordered_map<std::string, std::shared_ptr<Entry>> storage_;
147147 std::weak_ptr<Blackboard> parent_bb_;
@@ -186,7 +186,7 @@ inline T Blackboard::get(const std::string& key) const
186186
187187inline void Blackboard::unset (const std::string& key)
188188{
189- std::unique_lock lock (mutex_ );
189+ std::unique_lock storage_lock (storage_mutex_ );
190190
191191 // check local storage
192192 auto it = storage_.find (key);
@@ -207,15 +207,15 @@ inline void Blackboard::set(const std::string& key, const T& value)
207207 rootBlackboard ()->set (key.substr (1 , key.size () - 1 ), value);
208208 return ;
209209 }
210- std::unique_lock lock (mutex_ );
210+ std::unique_lock storage_lock (storage_mutex_ );
211211
212212 // check local storage
213213 auto it = storage_.find (key);
214214 if (it == storage_.end ())
215215 {
216216 // create a new entry
217217 Any new_value (value);
218- lock .unlock ();
218+ storage_lock .unlock ();
219219 std::shared_ptr<Blackboard::Entry> entry;
220220 // if a new generic port is created with a string, it's type should be AnyTypeAllowed
221221 if constexpr (std::is_same_v<std::string, T>)
@@ -228,7 +228,7 @@ inline void Blackboard::set(const std::string& key, const T& value)
228228 GetAnyFromStringFunctor<T>());
229229 entry = createEntryImpl (key, new_port);
230230 }
231- lock .lock ();
231+ storage_lock .lock ();
232232
233233 entry->value = new_value;
234234 entry->sequence_id ++;
@@ -239,6 +239,8 @@ inline void Blackboard::set(const std::string& key, const T& value)
239239 // this is not the first time we set this entry, we need to check
240240 // if the type is the same or not.
241241 Entry& entry = *it->second ;
242+ storage_lock.unlock ();
243+
242244 std::scoped_lock scoped_lock (entry.entry_mutex );
243245
244246 Any& previous_any = entry.value ;
0 commit comments