fixed rpl-classic bug and moved the two lifetime loops into one

This commit is contained in:
Joakim Eriksson 2017-11-17 16:36:17 +01:00 committed by Simon Duquennoy
parent cbdc3e4569
commit a5039634d5
2 changed files with 6 additions and 15 deletions

View File

@ -203,9 +203,11 @@ void
rpl_ns_periodic(void)
{
rpl_ns_node_t *l;
rpl_ns_node_t *next;
/* First pass, for all expired nodes, deallocate them iff no child points to them */
for(l = list_head(nodelist); l != NULL; l = list_item_next(l)) {
for(l = list_head(nodelist); l != NULL; l = next) {
next = list_item_next(l);
if(l->lifetime == 0) {
rpl_ns_node_t *l2;
for(l2 = list_head(nodelist); l2 != NULL; l2 = list_item_next(l2)) {
@ -217,13 +219,8 @@ rpl_ns_periodic(void)
list_remove(nodelist, l);
memb_free(&nodememb, l);
num_nodes--;
}
}
/* Second pass, decrement lifetime for all nodes with non-infinite lifetime */
for(l = list_head(nodelist); l != NULL; l = list_item_next(l)) {
/* Don't touch infinite lifetime nodes */
if(l->lifetime != 0xffffffff && l->lifetime > 0) {
} else if(l->lifetime != 0xffffffff) {
/* Decrement lifetime for all nodes with non-infinite lifetime */
l->lifetime--;
}
}

View File

@ -229,13 +229,7 @@ rpl_ns_periodic(unsigned seconds)
list_remove(nodelist, l);
memb_free(&nodememb, l);
num_nodes--;
}
}
/* Second pass, decrement lifetime for all nodes with non-infinite lifetime */
for(l = list_head(nodelist); l != NULL; l = list_item_next(l)) {
/* Don't touch infinite lifetime nodes */
if(l->lifetime != RPL_ROUTE_INFINITE_LIFETIME) {
} else if(l->lifetime != RPL_ROUTE_INFINITE_LIFETIME) {
l->lifetime = l->lifetime > seconds ? l->lifetime - seconds : 0;
}
}