Merge pull request #358 from simonduq/fix/rpl-nbr-init

Only initialize rpl-neighbor module once
This commit is contained in:
George Oikonomou 2018-03-19 21:48:59 +00:00 committed by GitHub
commit 0b3655a11c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 6 deletions

View File

@ -186,7 +186,7 @@ int
sixp_nbr_init(void) sixp_nbr_init(void)
{ {
sixp_nbr_t *nbr, *next_nbr; sixp_nbr_t *nbr, *next_nbr;
if(nbr_table_is_register(sixp_nbrs) == 0) { if(nbr_table_is_registered(sixp_nbrs) == 0) {
nbr_table_register(sixp_nbrs, NULL); nbr_table_register(sixp_nbrs, NULL);
} else { } else {
/* remove all the existing nbrs */ /* remove all the existing nbrs */

View File

@ -290,6 +290,13 @@ nbr_table_register(nbr_table_t *table, nbr_table_callback *callback)
ctimer_set(&periodic_timer, CLOCK_SECOND * 60, handle_periodic_timer, NULL); ctimer_set(&periodic_timer, CLOCK_SECOND * 60, handle_periodic_timer, NULL);
} }
#endif #endif
if(nbr_table_is_registered(table)) {
/* Table already registered, just update callback */
table->callback = callback;
return 1;
}
if(num_tables < MAX_NUM_TABLES) { if(num_tables < MAX_NUM_TABLES) {
table->index = num_tables++; table->index = num_tables++;
table->callback = callback; table->callback = callback;
@ -303,9 +310,10 @@ nbr_table_register(nbr_table_t *table, nbr_table_callback *callback)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Test whether a specified table has been registered or not */ /* Test whether a specified table has been registered or not */
int int
nbr_table_is_register(nbr_table_t *table) nbr_table_is_registered(nbr_table_t *table)
{ {
if(table != NULL && all_tables[table->index] == table) { if(table != NULL && table->index >= 0 && table->index < MAX_NUM_TABLES
&& all_tables[table->index] == table) {
return 1; return 1;
} }
return 0; return 0;
@ -490,4 +498,3 @@ handle_periodic_timer(void *ptr)
ctimer_reset(&periodic_timer); ctimer_reset(&periodic_timer);
} }
#endif #endif

View File

@ -92,7 +92,7 @@ typedef enum {
/** \name Neighbor tables: register and loop through table elements */ /** \name Neighbor tables: register and loop through table elements */
/** @{ */ /** @{ */
int nbr_table_register(nbr_table_t *table, nbr_table_callback *callback); int nbr_table_register(nbr_table_t *table, nbr_table_callback *callback);
int nbr_table_is_register(nbr_table_t *table); int nbr_table_is_registered(nbr_table_t *table);
nbr_table_item_t *nbr_table_head(nbr_table_t *table); nbr_table_item_t *nbr_table_head(nbr_table_t *table);
nbr_table_item_t *nbr_table_next(nbr_table_t *table, nbr_table_item_t *item); nbr_table_item_t *nbr_table_next(nbr_table_t *table, nbr_table_item_t *item);
/** @} */ /** @} */

View File

@ -716,7 +716,6 @@ void
rpl_dag_init(void) rpl_dag_init(void)
{ {
memset(&curr_instance, 0, sizeof(curr_instance)); memset(&curr_instance, 0, sizeof(curr_instance));
rpl_neighbor_init();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** @} */ /** @} */