diff --git a/subsys/net/ip/tcp2.c b/subsys/net/ip/tcp2.c index 5b36a0c7bf5..d36f1de9fb5 100644 --- a/subsys/net/ip/tcp2.c +++ b/subsys/net/ip/tcp2.c @@ -608,6 +608,8 @@ static struct tcp *tcp_conn_alloc(void) memset(conn, 0, sizeof(*conn)); + k_mutex_init(&conn->lock); + conn->state = TCP_LISTEN; conn->win = tcp_window; @@ -790,6 +792,8 @@ static void tcp_in(struct tcp *conn, struct net_pkt *pkt) u8_t next = 0, fl = th ? th->th_flags : 0; size_t len; + k_mutex_lock(&conn->lock, K_FOREVER); + NET_DBG("%s", log_strdup(tcp_conn_state(conn, pkt))); if (th && th->th_off < 5) { @@ -898,6 +902,8 @@ next_state: next = 0; goto next_state; } + + k_mutex_unlock(&conn->lock); } /* close() has been called on the socket */ diff --git a/subsys/net/ip/tcp2_priv.h b/subsys/net/ip/tcp2_priv.h index 730a68eabb5..502db8223e2 100644 --- a/subsys/net/ip/tcp2_priv.h +++ b/subsys/net/ip/tcp2_priv.h @@ -141,6 +141,7 @@ union tcp_endpoint { struct tcp { /* TCP connection */ sys_snode_t next; struct net_context *context; + struct k_mutex lock; void *recv_user_data; enum tcp_state state; u32_t seq;