timely initialization of builtin topics (#138)

The rtps_init function used to initialize all data structures and start
all threads used by the protocol stack, allowing discovery of remote
entities before the built-in topic data structures were initialized.
(Very) early discovery of a remote participant thus led to a crash.

This commit splits the initialisation, providing a separate function for
starting, in particular, the threads receiving data from the network.
In terms of threads created, it matches exactly with the rtps_stop /
rtps_fini split that already existed to address the exact same problem
on termination.

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2019-03-27 09:15:41 +01:00 committed by eboasson
parent b9406b2dee
commit cb0d1a9e50
3 changed files with 67 additions and 47 deletions

View file

@ -113,6 +113,7 @@ dds_init(dds_domainid_t domain)
goto fail_rtps_config;
}
upgrade_main_thread();
ut_avlInit(&dds_domaintree_def, &dds_global.m_domains);
/* Start monitoring the liveliness of all threads. */
@ -129,7 +130,7 @@ dds_init(dds_domainid_t domain)
}
}
if (rtps_init() < 0)
if (rtps_init () < 0)
{
DDS_LOG(DDS_LC_CONFIG, "Failed to initialize RTPS\n");
ret = DDS_ERRNO(DDS_RETCODE_ERROR);
@ -138,6 +139,13 @@ dds_init(dds_domainid_t domain)
dds__builtin_init ();
if (rtps_start () < 0)
{
DDS_LOG(DDS_LC_CONFIG, "Failed to start RTPS\n");
ret = DDS_ERRNO(DDS_RETCODE_ERROR);
goto fail_rtps_start;
}
if (gv.servicelease && nn_servicelease_start_renewing(gv.servicelease) < 0)
{
DDS_ERROR("Failed to start the servicelease\n");
@ -145,8 +153,6 @@ dds_init(dds_domainid_t domain)
goto fail_servicelease_start;
}
upgrade_main_thread();
/* Set additional default participant properties */
gv.default_plist_pp.process_id = (unsigned)ddsrt_getpid();
@ -173,6 +179,8 @@ fail_servicelease_start:
if (gv.servicelease)
nn_servicelease_stop_renewing (gv.servicelease);
rtps_stop ();
fail_rtps_start:
dds__builtin_fini ();
rtps_fini ();
fail_rtps_init:
if (gv.servicelease)
@ -181,6 +189,7 @@ fail_rtps_init:
gv.servicelease = NULL;
}
fail_servicelease_new:
downgrade_main_thread ();
thread_states_fini();
fail_rtps_config:
fail_config_domainid: