Replace nxsem API when used as a lock with nxmutex API

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
anjiahao
2022-09-06 14:18:45 +08:00
committed by Masayuki Ishikawa
parent 0dfd1f004d
commit d1d46335df
710 changed files with 7503 additions and 14852 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ struct bt_conn_handoff_s
static struct bt_conn_s g_conns[CONFIG_BLUETOOTH_MAX_CONN];
static struct bt_conn_handoff_s g_conn_handoff =
{
SEM_INITIALIZER(1),
NXSEM_INITIALIZER(1, PRIOINHERIT_FLAGS_DISABLE),
NULL
};
+9 -8
View File
@@ -30,6 +30,7 @@
#include <debug.h>
#include <nuttx/wqueue.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/bluetooth.h>
@@ -53,7 +54,7 @@
struct btnet_scanstate_s
{
sem_t bs_exclsem; /* Manages exclusive access */
mutex_t bs_lock; /* Manages exclusive access */
volatile bool bs_scanning; /* True: Scanning in progress */
volatile uint8_t bs_head; /* Head of circular list (for removal) */
uint8_t bs_tail; /* Tail of circular list (for addition) */
@@ -159,7 +160,7 @@ static void btnet_scan_callback(FAR const bt_addr_le_t *addr,
/* Get exclusive access to the scan data */
ret = nxsem_wait_uninterruptible(&g_scanstate.bs_exclsem);
ret = nxmutex_lock(&g_scanstate.bs_lock);
if (ret < 0)
{
wlerr("nxsem_wait_uninterruptible() failed: %d\n", ret);
@@ -201,7 +202,7 @@ static void btnet_scan_callback(FAR const bt_addr_le_t *addr,
memcpy(&rsp->sr_data, adv_data, len);
g_scanstate.bs_tail = nexttail;
nxsem_post(&g_scanstate.bs_exclsem);
nxmutex_unlock(&g_scanstate.bs_lock);
}
/****************************************************************************
@@ -241,7 +242,7 @@ static int btnet_scan_result(FAR struct bt_scanresponse_s *result,
{
/* Get exclusive access to the scan data */
ret = nxsem_wait(&g_scanstate.bs_exclsem);
ret = nxmutex_lock(&g_scanstate.bs_lock);
if (ret < 0)
{
return ret;
@@ -276,7 +277,7 @@ static int btnet_scan_result(FAR struct bt_scanresponse_s *result,
if (scanning)
{
nxsem_post(&g_scanstate.bs_exclsem);
nxmutex_unlock(&g_scanstate.bs_lock);
}
return nrsp;
@@ -617,7 +618,7 @@ int btnet_ioctl(FAR struct net_driver_s *netdev, int cmd, unsigned long arg)
{
/* Initialize scan state */
nxsem_init(&g_scanstate.bs_exclsem, 0, 1);
nxmutex_init(&g_scanstate.bs_lock);
g_scanstate.bs_scanning = true;
g_scanstate.bs_head = 0;
g_scanstate.bs_tail = 0;
@@ -628,7 +629,7 @@ int btnet_ioctl(FAR struct net_driver_s *netdev, int cmd, unsigned long arg)
if (ret < 0)
{
nxsem_destroy(&g_scanstate.bs_exclsem);
nxmutex_destroy(&g_scanstate.bs_lock);
g_scanstate.bs_scanning = false;
}
}
@@ -663,7 +664,7 @@ int btnet_ioctl(FAR struct net_driver_s *netdev, int cmd, unsigned long arg)
ret = bt_stop_scanning();
wlinfo("Stop scanning: %d\n", ret);
nxsem_destroy(&g_scanstate.bs_exclsem);
nxmutex_destroy(&g_scanstate.bs_lock);
g_scanstate.bs_scanning = false;
}
break;
-9
View File
@@ -103,7 +103,6 @@ struct btnet_driver_s
/* For internal use by this driver */
sem_t bd_exclsem; /* Exclusive access to struct */
bool bd_bifup; /* true:ifup false:ifdown */
struct work_s bd_pollwork; /* Defer poll work to the work queue */
@@ -1249,10 +1248,6 @@ int bt_netdev_register(FAR struct bt_driver_s *btdev)
bt_hci_cb_register(hcicb);
#endif
/* Setup a locking semaphore for exclusive device driver access */
nxsem_init(&priv->bd_exclsem, 0, 1);
/* Set the network mask. */
btnet_netmask(netdev);
@@ -1321,10 +1316,6 @@ int bt_netdev_register(FAR struct bt_driver_s *btdev)
errout:
/* Un-initialize semaphores */
nxsem_destroy(&priv->bd_exclsem);
/* Free memory and return the error */
kmm_free(priv);