1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #6968 from smlng/net/gnrc_tcp/cleanup

gnrc_tcp: optimize and cleanup operations on TCB list
This commit is contained in:
Sebastian Meiling 2017-04-26 13:58:28 +02:00 committed by GitHub
commit c08cf4a596

View File

@ -32,6 +32,11 @@
#define ENABLE_DEBUG (0) #define ENABLE_DEBUG (0)
#include "debug.h" #include "debug.h"
/**
* @brief Helper macro for LL_SEARCH to compare TCBs
*/
#define TCB_EQUAL(a,b) ((a) != (b))
/** /**
* @brief Checks if a given port number is currently used by a TCB as local_port. * @brief Checks if a given port number is currently used by a TCB as local_port.
* *
@ -45,12 +50,8 @@
static int _is_local_port_in_use(const uint16_t port_number) static int _is_local_port_in_use(const uint16_t port_number)
{ {
gnrc_tcp_tcb_t *iter = NULL; gnrc_tcp_tcb_t *iter = NULL;
LL_FOREACH(_list_tcb_head, iter) { LL_SEARCH_SCALAR(_list_tcb_head, iter, local_port, port_number);
if (iter->local_port == port_number) { return (iter != NULL);
return 1;
}
}
return 0;
} }
/** /**
@ -113,6 +114,8 @@ static int _restart_timewait_timer(gnrc_tcp_tcb_t *tcb)
*/ */
static int _transition_to(gnrc_tcp_tcb_t *tcb, fsm_state_t state) static int _transition_to(gnrc_tcp_tcb_t *tcb, fsm_state_t state)
{ {
DEBUG("_transition_to: %d\n", state);
gnrc_tcp_tcb_t *iter = NULL; gnrc_tcp_tcb_t *iter = NULL;
switch (state) { switch (state) {
@ -122,14 +125,7 @@ static int _transition_to(gnrc_tcp_tcb_t *tcb, fsm_state_t state)
/* Remove connection from active connections */ /* Remove connection from active connections */
mutex_lock(&_list_tcb_lock); mutex_lock(&_list_tcb_lock);
LL_FOREACH(_list_tcb_head, iter) { LL_DELETE(_list_tcb_head, tcb);
if (iter == tcb) {
break;
}
}
if (iter != NULL) {
LL_DELETE(_list_tcb_head, iter);
}
mutex_unlock(&_list_tcb_lock); mutex_unlock(&_list_tcb_lock);
/* Free potencially allocated receive buffer */ /* Free potencially allocated receive buffer */
@ -156,13 +152,9 @@ static int _transition_to(gnrc_tcp_tcb_t *tcb, fsm_state_t state)
/* Add connection to active connections (if not already active) */ /* Add connection to active connections (if not already active) */
mutex_lock(&_list_tcb_lock); mutex_lock(&_list_tcb_lock);
LL_FOREACH(_list_tcb_head, iter) { LL_SEARCH(_list_tcb_head, iter, tcb, TCB_EQUAL);
if (iter == tcb) {
break;
}
}
if (iter == NULL) { if (iter == NULL) {
LL_APPEND(_list_tcb_head, tcb); LL_PREPEND(_list_tcb_head, tcb);
} }
mutex_unlock(&_list_tcb_lock); mutex_unlock(&_list_tcb_lock);
break; break;
@ -175,11 +167,7 @@ static int _transition_to(gnrc_tcp_tcb_t *tcb, fsm_state_t state)
/* Add connection to active connections (if not already active) */ /* Add connection to active connections (if not already active) */
mutex_lock(&_list_tcb_lock); mutex_lock(&_list_tcb_lock);
LL_FOREACH(_list_tcb_head, iter) { LL_SEARCH(_list_tcb_head, iter, tcb, TCB_EQUAL);
if (iter == tcb) {
break;
}
}
/* If connection is not already active: Check port number, append TCB */ /* If connection is not already active: Check port number, append TCB */
if (iter == NULL) { if (iter == NULL) {
/* Check if port number was specified */ /* Check if port number was specified */
@ -195,7 +183,7 @@ static int _transition_to(gnrc_tcp_tcb_t *tcb, fsm_state_t state)
else { else {
tcb->local_port = _get_random_local_port(); tcb->local_port = _get_random_local_port();
} }
LL_APPEND(_list_tcb_head, tcb); LL_PREPEND(_list_tcb_head, tcb);
} }
mutex_unlock(&_list_tcb_lock); mutex_unlock(&_list_tcb_lock);
break; break;