@@ -31,6 +31,8 @@ static int tcp_window = NET_IPV6_MTU;
3131
3232static sys_slist_t tcp_conns = SYS_SLIST_STATIC_INIT (& tcp_conns );
3333
34+ static K_MUTEX_DEFINE (tcp_lock );
35+
3436static K_MEM_SLAB_DEFINE (tcp_conns_slab , sizeof (struct tcp ),
3537 CONFIG_NET_MAX_CONTEXTS , 4 );
3638
@@ -327,7 +329,7 @@ static void tcp_send_queue_flush(struct tcp *conn)
327329
328330static int tcp_conn_unref (struct tcp * conn )
329331{
330- int key , ref_count = atomic_get (& conn -> ref_count );
332+ int ref_count = atomic_get (& conn -> ref_count );
331333 struct net_pkt * pkt ;
332334
333335 NET_DBG ("conn: %p, ref_count=%d" , conn , ref_count );
@@ -348,7 +350,7 @@ static int tcp_conn_unref(struct tcp *conn)
348350 goto out ;
349351 }
350352
351- key = irq_lock ( );
353+ k_mutex_lock ( & tcp_lock , K_FOREVER );
352354
353355 /* If there is any pending data, pass that to application */
354356 while ((pkt = k_fifo_get (& conn -> recv_data , K_NO_WAIT )) != NULL ) {
@@ -385,7 +387,7 @@ static int tcp_conn_unref(struct tcp *conn)
385387
386388 k_mem_slab_free (& tcp_conns_slab , (void * * )& conn );
387389
388- irq_unlock ( key );
390+ k_mutex_unlock ( & tcp_lock );
389391out :
390392 return ref_count ;
391393}
@@ -1058,9 +1060,11 @@ static struct tcp *tcp_conn_alloc(void)
10581060
10591061int net_tcp_get (struct net_context * context )
10601062{
1061- int ret = 0 , key = irq_lock () ;
1063+ int ret = 0 ;
10621064 struct tcp * conn ;
10631065
1066+ k_mutex_lock (& tcp_lock , K_FOREVER );
1067+
10641068 conn = tcp_conn_alloc ();
10651069 if (conn == NULL ) {
10661070 ret = - ENOMEM ;
@@ -1071,7 +1075,7 @@ int net_tcp_get(struct net_context *context)
10711075 conn -> context = context ;
10721076 context -> tcp = conn ;
10731077out :
1074- irq_unlock ( key );
1078+ k_mutex_unlock ( & tcp_lock );
10751079
10761080 return ret ;
10771081}
@@ -2246,20 +2250,19 @@ void net_tcp_foreach(net_tcp_cb_t cb, void *user_data)
22462250{
22472251 struct tcp * conn ;
22482252 struct tcp * tmp ;
2249- int key ;
22502253
2251- key = irq_lock ( );
2254+ k_mutex_lock ( & tcp_lock , K_FOREVER );
22522255
22532256 SYS_SLIST_FOR_EACH_CONTAINER_SAFE (& tcp_conns , conn , tmp , next ) {
22542257
22552258 if (atomic_get (& conn -> ref_count ) > 0 ) {
2256- irq_unlock ( key );
2259+ k_mutex_unlock ( & tcp_lock );
22572260 cb (conn , user_data );
2258- key = irq_lock ( );
2261+ k_mutex_lock ( & tcp_lock , K_FOREVER );
22592262 }
22602263 }
22612264
2262- irq_unlock ( key );
2265+ k_mutex_unlock ( & tcp_lock );
22632266}
22642267
22652268uint16_t net_tcp_get_recv_mss (const struct tcp * conn )
0 commit comments