diff --git a/src/core/ddsc/src/dds_init.c b/src/core/ddsc/src/dds_init.c index 33c9540..1492c74 100644 --- a/src/core/ddsc/src/dds_init.c +++ b/src/core/ddsc/src/dds_init.c @@ -77,7 +77,6 @@ dds_init(dds_domainid_t domain) } gv.tstart = now (); - gv.exception = false; ddsrt_mutex_init (&dds_global.m_mutex); thread_states_init_static(); diff --git a/src/core/ddsi/include/dds/ddsi/q_entity.h b/src/core/ddsi/include/dds/ddsi/q_entity.h index 5d6dccb..53b4205 100644 --- a/src/core/ddsi/include/dds/ddsi/q_entity.h +++ b/src/core/ddsi/include/dds/ddsi/q_entity.h @@ -386,10 +386,10 @@ extern const ddsrt_avl_treedef_t deleted_participants_treedef; #define DPG_LOCAL 1 #define DPG_REMOTE 2 - -int deleted_participants_admin_init (void); -void deleted_participants_admin_fini (void); -int is_deleted_participant_guid (const struct nn_guid *guid, unsigned for_what); +struct deleted_participants_admin; +struct deleted_participants_admin *deleted_participants_admin_new (void); +void deleted_participants_admin_free (struct deleted_participants_admin *admin); +int is_deleted_participant_guid (struct deleted_participants_admin *admin, const struct nn_guid *guid, unsigned for_what); nn_entityid_t to_entityid (unsigned u); int is_builtin_entityid (nn_entityid_t id, nn_vendorid_t vendorid); diff --git a/src/core/ddsi/include/dds/ddsi/q_globals.h b/src/core/ddsi/include/dds/ddsi/q_globals.h index 93bdd5e..55efe7c 100644 --- a/src/core/ddsi/include/dds/ddsi/q_globals.h +++ b/src/core/ddsi/include/dds/ddsi/q_globals.h @@ -83,9 +83,10 @@ struct recv_thread_arg { } u; }; +struct deleted_participants_admin; + struct q_globals { volatile int terminate; - volatile int exception; volatile int deaf; volatile int mute; @@ -150,6 +151,9 @@ struct q_globals { struct participant *privileged_pp; ddsrt_mutex_t privileged_pp_lock; + /* For tracking (recently) deleted participants */ + struct deleted_participants_admin *deleted_participants; + /* GUID to be used in next call to new_participant; also protected by privileged_pp_lock */ struct nn_guid next_ppguid; diff --git a/src/core/ddsi/src/q_ddsi_discovery.c b/src/core/ddsi/src/q_ddsi_discovery.c index 5df36a1..5bfabc4 100644 --- a/src/core/ddsi/src/q_ddsi_discovery.c +++ b/src/core/ddsi/src/q_ddsi_discovery.c @@ -567,7 +567,7 @@ static int handle_SPDP_alive (const struct receiver_state *rst, seqno_t seq, nn_ consequently the looped back packet may appear to be from an unknown participant. So we handle that, too. */ - if (is_deleted_participant_guid (&datap->participant_guid, DPG_REMOTE)) + if (is_deleted_participant_guid (gv.deleted_participants, &datap->participant_guid, DPG_REMOTE)) { DDS_LOG(DDS_LC_TRACE, "SPDP ST0 "PGUIDFMT" (recently deleted)", PGUID (datap->participant_guid)); return 1; @@ -1126,7 +1126,7 @@ static void handle_SEDP_alive (const struct receiver_state *rst, nn_plist_t *dat ppguid.prefix = datap->endpoint_guid.prefix; ppguid.entityid.u = NN_ENTITYID_PARTICIPANT; - if (is_deleted_participant_guid (&ppguid, DPG_REMOTE)) + if (is_deleted_participant_guid (gv.deleted_participants, &ppguid, DPG_REMOTE)) E (" local dead pp?\n", err); if (ephash_lookup_participant_guid (&ppguid) != NULL) diff --git a/src/core/ddsi/src/q_entity.c b/src/core/ddsi/src/q_entity.c index 5471720..c94cd89 100644 --- a/src/core/ddsi/src/q_entity.c +++ b/src/core/ddsi/src/q_entity.c @@ -56,8 +56,10 @@ struct deleted_participant { nn_mtime_t t_prune; }; -static ddsrt_mutex_t deleted_participants_lock; -static ddsrt_avl_tree_t deleted_participants; +struct deleted_participants_admin { + ddsrt_mutex_t deleted_participants_lock; + ddsrt_avl_tree_t deleted_participants; +}; static int compare_guid (const void *va, const void *vb); static void augment_wr_prd_match (void *vnode, const void *vleft, const void *vright); @@ -273,83 +275,85 @@ nn_vendorid_t get_entity_vendorid (const struct entity_common *e) /* DELETED PARTICIPANTS --------------------------------------------- */ -int deleted_participants_admin_init (void) +struct deleted_participants_admin *deleted_participants_admin_new (void) { - ddsrt_mutex_init (&deleted_participants_lock); - ddsrt_avl_init (&deleted_participants_treedef, &deleted_participants); - return 0; + struct deleted_participants_admin *admin = ddsrt_malloc (sizeof (*admin)); + ddsrt_mutex_init (&admin->deleted_participants_lock); + ddsrt_avl_init (&deleted_participants_treedef, &admin->deleted_participants); + return admin; } -void deleted_participants_admin_fini (void) +void deleted_participants_admin_free (struct deleted_participants_admin *admin) { - ddsrt_avl_free (&deleted_participants_treedef, &deleted_participants, ddsrt_free); - ddsrt_mutex_destroy (&deleted_participants_lock); + ddsrt_avl_free (&deleted_participants_treedef, &admin->deleted_participants, ddsrt_free); + ddsrt_mutex_destroy (&admin->deleted_participants_lock); + ddsrt_free (admin); } -static void prune_deleted_participant_guids_unlocked (nn_mtime_t tnow) +static void prune_deleted_participant_guids_unlocked (struct deleted_participants_admin *admin, nn_mtime_t tnow) { /* Could do a better job of finding prunable ones efficiently under all circumstances, but I expect the tree to be very small at all times, so a full scan is fine, too ... */ struct deleted_participant *dpp; - dpp = ddsrt_avl_find_min (&deleted_participants_treedef, &deleted_participants); + dpp = ddsrt_avl_find_min (&deleted_participants_treedef, &admin->deleted_participants); while (dpp) { - struct deleted_participant *dpp1 = ddsrt_avl_find_succ (&deleted_participants_treedef, &deleted_participants, dpp); + struct deleted_participant *dpp1 = ddsrt_avl_find_succ (&deleted_participants_treedef, &admin->deleted_participants, dpp); if (dpp->t_prune.v < tnow.v) { - ddsrt_avl_delete (&deleted_participants_treedef, &deleted_participants, dpp); + ddsrt_avl_delete (&deleted_participants_treedef, &admin->deleted_participants, dpp); ddsrt_free (dpp); } dpp = dpp1; } } -static void prune_deleted_participant_guids (nn_mtime_t tnow) +static void prune_deleted_participant_guids (struct deleted_participants_admin *admin, nn_mtime_t tnow) { - ddsrt_mutex_lock (&deleted_participants_lock); - prune_deleted_participant_guids_unlocked (tnow); - ddsrt_mutex_unlock (&deleted_participants_lock); + ddsrt_mutex_lock (&admin->deleted_participants_lock); + prune_deleted_participant_guids_unlocked (admin, tnow); + ddsrt_mutex_unlock (&admin->deleted_participants_lock); } -static void remember_deleted_participant_guid (const struct nn_guid *guid) +static void remember_deleted_participant_guid (struct deleted_participants_admin *admin, const struct nn_guid *guid) { struct deleted_participant *n; ddsrt_avl_ipath_t path; - ddsrt_mutex_lock (&deleted_participants_lock); - if (ddsrt_avl_lookup_ipath (&deleted_participants_treedef, &deleted_participants, guid, &path) == NULL) + ddsrt_mutex_lock (&admin->deleted_participants_lock); + if (ddsrt_avl_lookup_ipath (&deleted_participants_treedef, &admin->deleted_participants, guid, &path) == NULL) { if ((n = ddsrt_malloc (sizeof (*n))) != NULL) { n->guid = *guid; n->t_prune.v = T_NEVER; n->for_what = DPG_LOCAL | DPG_REMOTE; - ddsrt_avl_insert_ipath (&deleted_participants_treedef, &deleted_participants, n, &path); + ddsrt_avl_insert_ipath (&deleted_participants_treedef, &admin->deleted_participants, n, &path); } } - ddsrt_mutex_unlock (&deleted_participants_lock); + ddsrt_mutex_unlock (&admin->deleted_participants_lock); } -int is_deleted_participant_guid (const struct nn_guid *guid, unsigned for_what) +int is_deleted_participant_guid (struct deleted_participants_admin *admin, const struct nn_guid *guid, unsigned for_what) { struct deleted_participant *n; int known; - ddsrt_mutex_lock (&deleted_participants_lock); - prune_deleted_participant_guids_unlocked (now_mt()); - if ((n = ddsrt_avl_lookup (&deleted_participants_treedef, &deleted_participants, guid)) == NULL) + ddsrt_mutex_lock (&admin->deleted_participants_lock); + prune_deleted_participant_guids_unlocked (admin, now_mt ()); + if ((n = ddsrt_avl_lookup (&deleted_participants_treedef, &admin->deleted_participants, guid)) == NULL) known = 0; else known = ((n->for_what & for_what) != 0); - ddsrt_mutex_unlock (&deleted_participants_lock); + ddsrt_mutex_unlock (&admin->deleted_participants_lock); return known; } -static void remove_deleted_participant_guid (const struct nn_guid *guid, unsigned for_what) +static void remove_deleted_participant_guid (struct deleted_participants_admin *admin, const struct nn_guid *guid, unsigned for_what) { struct deleted_participant *n; DDS_LOG(DDS_LC_DISCOVERY, "remove_deleted_participant_guid("PGUIDFMT" for_what=%x)\n", PGUID (*guid), for_what); - ddsrt_mutex_lock (&deleted_participants_lock); - if ((n = ddsrt_avl_lookup (&deleted_participants_treedef, &deleted_participants, guid)) != NULL) + ddsrt_mutex_lock (&admin->deleted_participants_lock); + if ((n = ddsrt_avl_lookup (&deleted_participants_treedef, &admin->deleted_participants, guid)) != NULL) { if (config.prune_deleted_ppant.enforce_delay) { @@ -366,12 +370,12 @@ static void remove_deleted_participant_guid (const struct nn_guid *guid, unsigne } else { - ddsrt_avl_delete (&deleted_participants_treedef, &deleted_participants, n); + ddsrt_avl_delete (&deleted_participants_treedef, &admin->deleted_participants, n); ddsrt_free (n); } } } - ddsrt_mutex_unlock (&deleted_participants_lock); + ddsrt_mutex_unlock (&admin->deleted_participants_lock); } @@ -443,7 +447,7 @@ dds_return_t new_participant_guid (const nn_guid_t *ppguid, unsigned flags, cons /* privileged participant MUST have builtin readers and writers */ assert (!(flags & RTPS_PF_PRIVILEGED_PP) || (flags & (RTPS_PF_NO_BUILTIN_READERS | RTPS_PF_NO_BUILTIN_WRITERS)) == 0); - prune_deleted_participant_guids (now_mt ()); + prune_deleted_participant_guids (gv.deleted_participants, now_mt ()); /* FIXME: FULL LOCKING AROUND NEW_XXX FUNCTIONS, JUST SO EXISTENCE TESTS ARE PRECISE */ @@ -879,7 +883,7 @@ static void unref_participant (struct participant *pp, const struct nn_guid *gui ddsrt_free (pp->plist); ddsrt_mutex_destroy (&pp->refc_lock); entity_common_fini (&pp->e); - remove_deleted_participant_guid (&pp->e.guid, DPG_LOCAL); + remove_deleted_participant_guid (gv.deleted_participants, &pp->e.guid, DPG_LOCAL); inverse_uint32_set_fini(&pp->avail_entityids.x); ddsrt_free (pp); } @@ -903,7 +907,7 @@ dds_return_t delete_participant (const struct nn_guid *ppguid) if ((pp = ephash_lookup_participant_guid (ppguid)) == NULL) return DDS_RETCODE_BAD_PARAMETER; ddsi_plugin.builtintopic_write (&pp->e, now(), false); - remember_deleted_participant_guid (&pp->e.guid); + remember_deleted_participant_guid (gv.deleted_participants, &pp->e.guid); ephash_remove_participant_guid (pp); gcreq_participant (pp); return 0; @@ -3500,7 +3504,7 @@ void new_proxy_participant assert (ephash_lookup_proxy_participant_guid (ppguid) == NULL); assert (privileged_pp_guid == NULL || privileged_pp_guid->entityid.u == NN_ENTITYID_PARTICIPANT); - prune_deleted_participant_guids (now_mt ()); + prune_deleted_participant_guids (gv.deleted_participants, now_mt ()); proxypp = ddsrt_malloc (sizeof (*proxypp)); @@ -3750,7 +3754,7 @@ static void unref_proxy_participant (struct proxy_participant *proxypp, struct p if (proxypp->owns_lease) lease_free (ddsrt_atomic_ldvoidp (&proxypp->lease)); entity_common_fini (&proxypp->e); - remove_deleted_participant_guid (&proxypp->e.guid, DPG_LOCAL | DPG_REMOTE); + remove_deleted_participant_guid (gv.deleted_participants, &proxypp->e.guid, DPG_LOCAL | DPG_REMOTE); ddsrt_free (proxypp); } else if (proxypp->endpoints == NULL && proxypp->implicitly_created) @@ -3912,7 +3916,7 @@ int delete_proxy_participant_by_guid (const struct nn_guid * guid, nn_wctime_t t } DDS_LOG(DDS_LC_DISCOVERY, "- deleting\n"); ddsi_plugin.builtintopic_write (&ppt->e, timestamp, false); - remember_deleted_participant_guid (&ppt->e.guid); + remember_deleted_participant_guid (gv.deleted_participants, &ppt->e.guid); ephash_remove_proxy_participant_guid (ppt); ddsrt_mutex_unlock (&gv.lock); delete_ppt (ppt, timestamp, isimplicit); diff --git a/src/core/ddsi/src/q_init.c b/src/core/ddsi/src/q_init.c index 9b238bb..7976841 100644 --- a/src/core/ddsi/src/q_init.c +++ b/src/core/ddsi/src/q_init.c @@ -1029,7 +1029,7 @@ int rtps_init (void) ddsrt_mutex_init (&gv.participant_set_lock); ddsrt_cond_init (&gv.participant_set_cond); lease_management_init (); - deleted_participants_admin_init (); + gv.deleted_participants = deleted_participants_admin_new (); gv.guid_hash = ephash_new (); ddsrt_mutex_init (&gv.privileged_pp_lock); @@ -1306,7 +1306,7 @@ err_unicast_sockets: ddsrt_mutex_destroy (&gv.privileged_pp_lock); ephash_free (gv.guid_hash); gv.guid_hash = NULL; - deleted_participants_admin_fini (); + deleted_participants_admin_free (gv.deleted_participants); lease_management_term (); ddsrt_cond_destroy (&gv.participant_set_cond); ddsrt_mutex_destroy (&gv.participant_set_lock); @@ -1640,7 +1640,7 @@ void rtps_fini (void) ephash_free (gv.guid_hash); gv.guid_hash = NULL; - deleted_participants_admin_fini (); + deleted_participants_admin_free (gv.deleted_participants); lease_management_term (); ddsrt_mutex_destroy (&gv.participant_set_lock); ddsrt_cond_destroy (&gv.participant_set_cond); diff --git a/src/core/ddsi/src/q_receive.c b/src/core/ddsi/src/q_receive.c index e340dc6..a7231e0 100644 --- a/src/core/ddsi/src/q_receive.c +++ b/src/core/ddsi/src/q_receive.c @@ -1508,7 +1508,8 @@ static int handle_InfoDST (struct receiver_state *rst, const InfoDST_t *msg, con nn_guid_t dst; dst.prefix = rst->dst_guid_prefix; dst.entityid = to_entityid(NN_ENTITYID_PARTICIPANT); - rst->forme = (ephash_lookup_participant_guid (&dst) != NULL) || is_deleted_participant_guid (&dst, DPG_LOCAL); + rst->forme = (ephash_lookup_participant_guid (&dst) != NULL || + is_deleted_participant_guid (gv.deleted_participants, &dst, DPG_LOCAL)); } return 1; }