bt_buf: use small lock to protect bt_bufferlist_s

reason:
We would like to replace the big lock with a small lock.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2024-12-18 09:25:29 +08:00 committed by Xiang Xiao
parent 658e4ffae2
commit bc6bf019dd
2 changed files with 10 additions and 4 deletions

View file

@ -43,6 +43,8 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <nuttx/spinlock.h>
/**************************************************************************** /****************************************************************************
* Public Types * Public Types
****************************************************************************/ ****************************************************************************/
@ -114,6 +116,7 @@ struct bt_bufferlist_s
{ {
FAR struct bt_buf_s *head; FAR struct bt_buf_s *head;
FAR struct bt_buf_s *tail; FAR struct bt_buf_s *tail;
spinlock_t lock;
}; };
/**************************************************************************** /****************************************************************************

View file

@ -139,7 +139,7 @@ static void bt_enqueue_bufwork(FAR struct bt_bufferlist_s *list,
{ {
irqstate_t flags; irqstate_t flags;
flags = spin_lock_irqsave(NULL); flags = spin_lock_irqsave(&list->lock);
buf->flink = list->head; buf->flink = list->head;
if (list->head == NULL) if (list->head == NULL)
{ {
@ -147,7 +147,7 @@ static void bt_enqueue_bufwork(FAR struct bt_bufferlist_s *list,
} }
list->head = buf; list->head = buf;
spin_unlock_irqrestore(NULL, flags); spin_unlock_irqrestore(&list->lock, flags);
} }
/**************************************************************************** /****************************************************************************
@ -172,7 +172,7 @@ static FAR struct bt_buf_s *
FAR struct bt_buf_s *buf; FAR struct bt_buf_s *buf;
irqstate_t flags; irqstate_t flags;
flags = spin_lock_irqsave(NULL); flags = spin_lock_irqsave(&list->lock);
buf = list->tail; buf = list->tail;
if (buf != NULL) if (buf != NULL)
{ {
@ -201,7 +201,7 @@ static FAR struct bt_buf_s *
buf->flink = NULL; buf->flink = NULL;
} }
spin_unlock_irqrestore(NULL, flags); spin_unlock_irqrestore(&list->lock, flags);
return buf; return buf;
} }
@ -1653,6 +1653,9 @@ int bt_initialize(void)
memset(&g_lp_rxlist, 0, sizeof(g_lp_rxlist)); memset(&g_lp_rxlist, 0, sizeof(g_lp_rxlist));
memset(&g_hp_rxlist, 0, sizeof(g_hp_rxlist)); memset(&g_hp_rxlist, 0, sizeof(g_hp_rxlist));
spin_lock_init(&g_hp_rxlist.lock);
spin_lock_init(&g_lp_rxlist.lock);
DEBUGASSERT(btdev != NULL); DEBUGASSERT(btdev != NULL);
bt_buf_initialize(); bt_buf_initialize();