Merge pull request #15207 from chrysn-pull-requests/rpl-no-race

gnrc_rpl: Check for race against initializer thread
This commit is contained in:
Martine Lenders 2020-10-20 19:04:14 +02:00 committed by GitHub
commit 5d1d38d8f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -69,17 +69,24 @@ kernel_pid_t gnrc_rpl_init(kernel_pid_t if_pid)
{
/* check if RPL was initialized before */
if (gnrc_rpl_pid == KERNEL_PID_UNDEF) {
mutex_t eventloop_startup = MUTEX_INIT_LOCKED;
_instance_id = 0;
/* start the event loop */
gnrc_rpl_pid = thread_create(_stack, sizeof(_stack), GNRC_RPL_PRIO,
THREAD_CREATE_STACKTEST,
_event_loop, NULL, "RPL");
_event_loop, (void*)&eventloop_startup,
"RPL");
if (gnrc_rpl_pid == KERNEL_PID_UNDEF) {
DEBUG("RPL: could not start the event loop\n");
return KERNEL_PID_UNDEF;
}
/* Wait for the event loop to indicate that it set up its message
* queue, and registration with netreg can commence. */
mutex_lock(&eventloop_startup);
_me_reg.demux_ctx = ICMPV6_RPL_CTRL;
_me_reg.target.pid = gnrc_rpl_pid;
/* register interest in all ICMPv6 packets */
@ -246,8 +253,15 @@ static void *_event_loop(void *args)
{
msg_t msg, reply;
(void)args;
msg_init_queue(_msg_q, GNRC_RPL_MSG_QUEUE_SIZE);
{
mutex_t *eventloop_startup = (mutex_t*)args;
msg_init_queue(_msg_q, GNRC_RPL_MSG_QUEUE_SIZE);
/* Message queue is initialized, gnrc_rpl_init can continue and will
* pop the underlying mutex off its stack. */
mutex_unlock(eventloop_startup);
}
/* preinitialize ACK */
reply.type = GNRC_NETAPI_MSG_TYPE_ACK;