From f12606d7c0811f460423b3bc0a215913b069ba3b Mon Sep 17 00:00:00 2001
From: Gunar Schorcht <gunar@schorcht.net>
Date: Thu, 24 Jan 2019 17:25:15 +0100
Subject: [PATCH] cpu/esp8266: removes the mutex in esp_wifi

Since _esp_wifi_recv_cb is not executed in interrupt context but in the context of the `ets` thread, the receive function can be called directly. There is no need for a mutex anymore to synchronize the access to the receive buffer between _esp_wifi_recv_cb and _recv function.
---
 cpu/esp8266/esp-wifi/esp_wifi_netdev.c | 15 ---------------
 cpu/esp8266/esp-wifi/esp_wifi_netdev.h |  2 --
 2 files changed, 17 deletions(-)

diff --git a/cpu/esp8266/esp-wifi/esp_wifi_netdev.c b/cpu/esp8266/esp-wifi/esp_wifi_netdev.c
index 0219396857..29ea56c563 100644
--- a/cpu/esp8266/esp-wifi/esp_wifi_netdev.c
+++ b/cpu/esp8266/esp-wifi/esp_wifi_netdev.c
@@ -179,9 +179,6 @@ void IRAM _esp_wifi_recv_cb(struct pbuf *pb, struct netif *netif)
     }
     _in_esp_wifi_recv_cb = true;
 
-    /* avoid concurrent access to the receive buffer */
-    mutex_lock(&_esp_wifi_dev.dev_lock);
-
     critical_enter();
 
     /* first, check packet buffer for the minimum packet size */
@@ -191,7 +188,6 @@ void IRAM _esp_wifi_recv_cb(struct pbuf *pb, struct netif *netif)
         pbuf_free(pb);
         _in_esp_wifi_recv_cb = false;
         critical_exit();
-        mutex_unlock(&_esp_wifi_dev.dev_lock);
         return;
     }
 
@@ -202,7 +198,6 @@ void IRAM _esp_wifi_recv_cb(struct pbuf *pb, struct netif *netif)
         pbuf_free(pb);
         _in_esp_wifi_recv_cb = false;
         critical_exit();
-        mutex_unlock(&_esp_wifi_dev.dev_lock);
         return;
     }
 
@@ -213,7 +208,6 @@ void IRAM _esp_wifi_recv_cb(struct pbuf *pb, struct netif *netif)
         pbuf_free(pb);
         _in_esp_wifi_recv_cb = false;
         critical_exit();
-        mutex_unlock(&_esp_wifi_dev.dev_lock);
         return;
     }
 
@@ -243,7 +237,6 @@ void IRAM _esp_wifi_recv_cb(struct pbuf *pb, struct netif *netif)
 
     _in_esp_wifi_recv_cb = false;
     critical_exit();
-    mutex_unlock(&_esp_wifi_dev.dev_lock);
 }
 
 /**
@@ -470,9 +463,6 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
 
     esp_wifi_netdev_t* dev = (esp_wifi_netdev_t*)netdev;
 
-    /* avoid concurrent access to the receive buffer */
-    mutex_lock(&dev->dev_lock);
-
     uint16_t size = dev->rx_len ? dev->rx_len : 0;
 
     if (!buf) {
@@ -481,7 +471,6 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
             /* if len > 0, drop the frame */
             dev->rx_len = 0;
         }
-        mutex_unlock(&dev->dev_lock);
         return size;
     }
 
@@ -490,7 +479,6 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
         ESP_WIFI_DEBUG("not enough space in receive buffer");
         /* newest API requires to drop the frame in that case */
         dev->rx_len = 0;
-        mutex_unlock(&dev->dev_lock);
         return -ENOBUFS;
     }
 
@@ -513,7 +501,6 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
     netdev->stats.rx_bytes += size;
 #endif
 
-    mutex_unlock(&dev->dev_lock);
     return size;
 }
 
@@ -625,8 +612,6 @@ static void _esp_wifi_setup(void)
     dev->rx_len = 0;
     dev->state = ESP_WIFI_DISCONNECTED;
 
-    mutex_init(&dev->dev_lock);
-
     /* set the netdev driver */
     dev->netdev.driver = &_esp_wifi_driver;
 
diff --git a/cpu/esp8266/esp-wifi/esp_wifi_netdev.h b/cpu/esp8266/esp-wifi/esp_wifi_netdev.h
index 8cb331eb7a..5f21cf5c02 100644
--- a/cpu/esp8266/esp-wifi/esp_wifi_netdev.h
+++ b/cpu/esp8266/esp-wifi/esp_wifi_netdev.h
@@ -49,8 +49,6 @@ typedef struct
 
     esp_wifi_state_t state;           /**< indicates the interface state */
 
-    mutex_t dev_lock;                 /**< for exclusive access to buffer in
-                                           receive functions */
 } esp_wifi_netdev_t;
 
 #ifdef __cplusplus
-- 
GitLab