@@ -76,6 +76,12 @@ void DiscoveryDatabase::stop() noexcept
7676 {
7777 logDebug (DDSPIPE_DISCOVERY_DATABASE , " Processing thread routine already stopped." );
7878 }
79+
80+ {
81+ std::unique_lock<std::shared_timed_mutex> lock (mutex_);
82+ entities_.clear ();
83+ entities_filter_.clear ();
84+ }
7985}
8086
8187bool DiscoveryDatabase::topic_exists (
@@ -107,6 +113,7 @@ bool DiscoveryDatabase::add_endpoint_(
107113{
108114 {
109115 std::unique_lock<std::shared_timed_mutex> lock (mutex_);
116+ entities_filter_.erase (new_endpoint.guid );
110117
111118 auto it = entities_.find (new_endpoint.guid );
112119 if (it != entities_.end ())
@@ -151,8 +158,14 @@ bool DiscoveryDatabase::add_endpoint_(
151158bool DiscoveryDatabase::update_endpoint_ (
152159 const Endpoint& endpoint_to_update)
153160{
161+ if (!endpoint_to_update.active )
162+ {
163+ return erase_endpoint_ (endpoint_to_update) == utils::ReturnCode::RETCODE_OK ;
164+ }
165+
154166 {
155167 std::unique_lock<std::shared_timed_mutex> lock (mutex_);
168+ entities_filter_.erase (endpoint_to_update.guid );
156169
157170 auto it = entities_.find (endpoint_to_update.guid );
158171 if (it == entities_.end ())
@@ -185,14 +198,18 @@ bool DiscoveryDatabase::update_endpoint_(
185198utils::ReturnCode DiscoveryDatabase::erase_endpoint_ (
186199 const Endpoint& endpoint_to_erase)
187200{
201+ bool endpoint_erased = false ;
202+
188203 {
189204 std::unique_lock<std::shared_timed_mutex> lock (mutex_);
190205
191206 EPROSIMA_LOG_INFO (DDSPIPE_DISCOVERY_DATABASE , " Erasing Endpoint " << endpoint_to_erase << " ." );
192207
193208 auto erased = entities_.erase (endpoint_to_erase.guid );
209+ auto filtered_erased = entities_filter_.erase (endpoint_to_erase.guid );
210+ endpoint_erased = erased > 0 ;
194211
195- if (erased == 0 )
212+ if (erased == 0 && filtered_erased == 0 )
196213 {
197214 throw utils::InconsistencyException (
198215 utils::Formatter () <<
@@ -201,10 +218,13 @@ utils::ReturnCode DiscoveryDatabase::erase_endpoint_(
201218 }
202219 }
203220
204- std::lock_guard<std::mutex> lock (callbacks_mutex_);
205- for (auto erased_endpoint_callback : erased_endpoint_callbacks_)
221+ if (endpoint_erased)
206222 {
207- erased_endpoint_callback (endpoint_to_erase);
223+ std::lock_guard<std::mutex> lock (callbacks_mutex_);
224+ for (auto erased_endpoint_callback : erased_endpoint_callbacks_)
225+ {
226+ erased_endpoint_callback (endpoint_to_erase);
227+ }
208228 }
209229
210230 return utils::ReturnCode::RETCODE_OK ;
@@ -213,6 +233,7 @@ utils::ReturnCode DiscoveryDatabase::erase_endpoint_(
213233void DiscoveryDatabase::add_filtered_endpoint (
214234 const types::Guid guid)
215235{
236+ std::unique_lock<std::shared_timed_mutex> lock (mutex_);
216237 entities_filter_.insert (guid);
217238}
218239
@@ -237,6 +258,7 @@ void DiscoveryDatabase::erase_endpoint(
237258bool DiscoveryDatabase::exists_filtered_endpoint (
238259 const Guid endpoint_guid)
239260{
261+ std::shared_lock<std::shared_timed_mutex> lock (mutex_);
240262 return entities_filter_.find (endpoint_guid) != entities_filter_.end ();
241263}
242264
0 commit comments