Move deleted participants admin into "gv"

That reduces the number of global variables in preparation for
supporting multi domains simultaneously.

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2019-06-27 10:11:04 +02:00 committed by eboasson
parent 59fb537ba3
commit cf46ddbb7b
7 changed files with 58 additions and 50 deletions

View file

@ -77,7 +77,6 @@ dds_init(dds_domainid_t domain)
} }
gv.tstart = now (); gv.tstart = now ();
gv.exception = false;
ddsrt_mutex_init (&dds_global.m_mutex); ddsrt_mutex_init (&dds_global.m_mutex);
thread_states_init_static(); thread_states_init_static();

View file

@ -386,10 +386,10 @@ extern const ddsrt_avl_treedef_t deleted_participants_treedef;
#define DPG_LOCAL 1 #define DPG_LOCAL 1
#define DPG_REMOTE 2 #define DPG_REMOTE 2
struct deleted_participants_admin;
int deleted_participants_admin_init (void); struct deleted_participants_admin *deleted_participants_admin_new (void);
void deleted_participants_admin_fini (void); void deleted_participants_admin_free (struct deleted_participants_admin *admin);
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);
nn_entityid_t to_entityid (unsigned u); nn_entityid_t to_entityid (unsigned u);
int is_builtin_entityid (nn_entityid_t id, nn_vendorid_t vendorid); int is_builtin_entityid (nn_entityid_t id, nn_vendorid_t vendorid);

View file

@ -83,9 +83,10 @@ struct recv_thread_arg {
} u; } u;
}; };
struct deleted_participants_admin;
struct q_globals { struct q_globals {
volatile int terminate; volatile int terminate;
volatile int exception;
volatile int deaf; volatile int deaf;
volatile int mute; volatile int mute;
@ -150,6 +151,9 @@ struct q_globals {
struct participant *privileged_pp; struct participant *privileged_pp;
ddsrt_mutex_t privileged_pp_lock; 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 /* GUID to be used in next call to new_participant; also protected
by privileged_pp_lock */ by privileged_pp_lock */
struct nn_guid next_ppguid; struct nn_guid next_ppguid;

View file

@ -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 consequently the looped back packet may appear to be from an
unknown participant. So we handle that, too. */ 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)); DDS_LOG(DDS_LC_TRACE, "SPDP ST0 "PGUIDFMT" (recently deleted)", PGUID (datap->participant_guid));
return 1; 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.prefix = datap->endpoint_guid.prefix;
ppguid.entityid.u = NN_ENTITYID_PARTICIPANT; 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); E (" local dead pp?\n", err);
if (ephash_lookup_participant_guid (&ppguid) != NULL) if (ephash_lookup_participant_guid (&ppguid) != NULL)

View file

@ -56,8 +56,10 @@ struct deleted_participant {
nn_mtime_t t_prune; nn_mtime_t t_prune;
}; };
static ddsrt_mutex_t deleted_participants_lock; struct deleted_participants_admin {
static ddsrt_avl_tree_t deleted_participants; ddsrt_mutex_t deleted_participants_lock;
ddsrt_avl_tree_t deleted_participants;
};
static int compare_guid (const void *va, const void *vb); static int compare_guid (const void *va, const void *vb);
static void augment_wr_prd_match (void *vnode, const void *vleft, const void *vright); 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 --------------------------------------------- */ /* DELETED PARTICIPANTS --------------------------------------------- */
int deleted_participants_admin_init (void) struct deleted_participants_admin *deleted_participants_admin_new (void)
{ {
ddsrt_mutex_init (&deleted_participants_lock); struct deleted_participants_admin *admin = ddsrt_malloc (sizeof (*admin));
ddsrt_avl_init (&deleted_participants_treedef, &deleted_participants); ddsrt_mutex_init (&admin->deleted_participants_lock);
return 0; 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_avl_free (&deleted_participants_treedef, &admin->deleted_participants, ddsrt_free);
ddsrt_mutex_destroy (&deleted_participants_lock); 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 /* Could do a better job of finding prunable ones efficiently under
all circumstances, but I expect the tree to be very small at all all circumstances, but I expect the tree to be very small at all
times, so a full scan is fine, too ... */ times, so a full scan is fine, too ... */
struct deleted_participant *dpp; 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) 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) 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); ddsrt_free (dpp);
} }
dpp = dpp1; 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); ddsrt_mutex_lock (&admin->deleted_participants_lock);
prune_deleted_participant_guids_unlocked (tnow); prune_deleted_participant_guids_unlocked (admin, tnow);
ddsrt_mutex_unlock (&deleted_participants_lock); 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; struct deleted_participant *n;
ddsrt_avl_ipath_t path; ddsrt_avl_ipath_t path;
ddsrt_mutex_lock (&deleted_participants_lock); ddsrt_mutex_lock (&admin->deleted_participants_lock);
if (ddsrt_avl_lookup_ipath (&deleted_participants_treedef, &deleted_participants, guid, &path) == NULL) if (ddsrt_avl_lookup_ipath (&deleted_participants_treedef, &admin->deleted_participants, guid, &path) == NULL)
{ {
if ((n = ddsrt_malloc (sizeof (*n))) != NULL) if ((n = ddsrt_malloc (sizeof (*n))) != NULL)
{ {
n->guid = *guid; n->guid = *guid;
n->t_prune.v = T_NEVER; n->t_prune.v = T_NEVER;
n->for_what = DPG_LOCAL | DPG_REMOTE; 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; struct deleted_participant *n;
int known; int known;
ddsrt_mutex_lock (&deleted_participants_lock); ddsrt_mutex_lock (&admin->deleted_participants_lock);
prune_deleted_participant_guids_unlocked (now_mt()); prune_deleted_participant_guids_unlocked (admin, now_mt ());
if ((n = ddsrt_avl_lookup (&deleted_participants_treedef, &deleted_participants, guid)) == NULL) if ((n = ddsrt_avl_lookup (&deleted_participants_treedef, &admin->deleted_participants, guid)) == NULL)
known = 0; known = 0;
else else
known = ((n->for_what & for_what) != 0); known = ((n->for_what & for_what) != 0);
ddsrt_mutex_unlock (&deleted_participants_lock); ddsrt_mutex_unlock (&admin->deleted_participants_lock);
return known; 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; struct deleted_participant *n;
DDS_LOG(DDS_LC_DISCOVERY, "remove_deleted_participant_guid("PGUIDFMT" for_what=%x)\n", PGUID (*guid), for_what); DDS_LOG(DDS_LC_DISCOVERY, "remove_deleted_participant_guid("PGUIDFMT" for_what=%x)\n", PGUID (*guid), for_what);
ddsrt_mutex_lock (&deleted_participants_lock); ddsrt_mutex_lock (&admin->deleted_participants_lock);
if ((n = ddsrt_avl_lookup (&deleted_participants_treedef, &deleted_participants, guid)) != NULL) if ((n = ddsrt_avl_lookup (&deleted_participants_treedef, &admin->deleted_participants, guid)) != NULL)
{ {
if (config.prune_deleted_ppant.enforce_delay) if (config.prune_deleted_ppant.enforce_delay)
{ {
@ -366,12 +370,12 @@ static void remove_deleted_participant_guid (const struct nn_guid *guid, unsigne
} }
else else
{ {
ddsrt_avl_delete (&deleted_participants_treedef, &deleted_participants, n); ddsrt_avl_delete (&deleted_participants_treedef, &admin->deleted_participants, n);
ddsrt_free (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 */ /* 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); 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 */ /* 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_free (pp->plist);
ddsrt_mutex_destroy (&pp->refc_lock); ddsrt_mutex_destroy (&pp->refc_lock);
entity_common_fini (&pp->e); 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); inverse_uint32_set_fini(&pp->avail_entityids.x);
ddsrt_free (pp); 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) if ((pp = ephash_lookup_participant_guid (ppguid)) == NULL)
return DDS_RETCODE_BAD_PARAMETER; return DDS_RETCODE_BAD_PARAMETER;
ddsi_plugin.builtintopic_write (&pp->e, now(), false); 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); ephash_remove_participant_guid (pp);
gcreq_participant (pp); gcreq_participant (pp);
return 0; return 0;
@ -3500,7 +3504,7 @@ void new_proxy_participant
assert (ephash_lookup_proxy_participant_guid (ppguid) == NULL); assert (ephash_lookup_proxy_participant_guid (ppguid) == NULL);
assert (privileged_pp_guid == NULL || privileged_pp_guid->entityid.u == NN_ENTITYID_PARTICIPANT); 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)); proxypp = ddsrt_malloc (sizeof (*proxypp));
@ -3750,7 +3754,7 @@ static void unref_proxy_participant (struct proxy_participant *proxypp, struct p
if (proxypp->owns_lease) if (proxypp->owns_lease)
lease_free (ddsrt_atomic_ldvoidp (&proxypp->lease)); lease_free (ddsrt_atomic_ldvoidp (&proxypp->lease));
entity_common_fini (&proxypp->e); 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); ddsrt_free (proxypp);
} }
else if (proxypp->endpoints == NULL && proxypp->implicitly_created) 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"); DDS_LOG(DDS_LC_DISCOVERY, "- deleting\n");
ddsi_plugin.builtintopic_write (&ppt->e, timestamp, false); 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); ephash_remove_proxy_participant_guid (ppt);
ddsrt_mutex_unlock (&gv.lock); ddsrt_mutex_unlock (&gv.lock);
delete_ppt (ppt, timestamp, isimplicit); delete_ppt (ppt, timestamp, isimplicit);

View file

@ -1029,7 +1029,7 @@ int rtps_init (void)
ddsrt_mutex_init (&gv.participant_set_lock); ddsrt_mutex_init (&gv.participant_set_lock);
ddsrt_cond_init (&gv.participant_set_cond); ddsrt_cond_init (&gv.participant_set_cond);
lease_management_init (); lease_management_init ();
deleted_participants_admin_init (); gv.deleted_participants = deleted_participants_admin_new ();
gv.guid_hash = ephash_new (); gv.guid_hash = ephash_new ();
ddsrt_mutex_init (&gv.privileged_pp_lock); ddsrt_mutex_init (&gv.privileged_pp_lock);
@ -1306,7 +1306,7 @@ err_unicast_sockets:
ddsrt_mutex_destroy (&gv.privileged_pp_lock); ddsrt_mutex_destroy (&gv.privileged_pp_lock);
ephash_free (gv.guid_hash); ephash_free (gv.guid_hash);
gv.guid_hash = NULL; gv.guid_hash = NULL;
deleted_participants_admin_fini (); deleted_participants_admin_free (gv.deleted_participants);
lease_management_term (); lease_management_term ();
ddsrt_cond_destroy (&gv.participant_set_cond); ddsrt_cond_destroy (&gv.participant_set_cond);
ddsrt_mutex_destroy (&gv.participant_set_lock); ddsrt_mutex_destroy (&gv.participant_set_lock);
@ -1640,7 +1640,7 @@ void rtps_fini (void)
ephash_free (gv.guid_hash); ephash_free (gv.guid_hash);
gv.guid_hash = NULL; gv.guid_hash = NULL;
deleted_participants_admin_fini (); deleted_participants_admin_free (gv.deleted_participants);
lease_management_term (); lease_management_term ();
ddsrt_mutex_destroy (&gv.participant_set_lock); ddsrt_mutex_destroy (&gv.participant_set_lock);
ddsrt_cond_destroy (&gv.participant_set_cond); ddsrt_cond_destroy (&gv.participant_set_cond);

View file

@ -1508,7 +1508,8 @@ static int handle_InfoDST (struct receiver_state *rst, const InfoDST_t *msg, con
nn_guid_t dst; nn_guid_t dst;
dst.prefix = rst->dst_guid_prefix; dst.prefix = rst->dst_guid_prefix;
dst.entityid = to_entityid(NN_ENTITYID_PARTICIPANT); 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; return 1;
} }