Skip to content

Commit

Permalink
bt_buf: use small lock to protect bt_bufferlist_s
Browse files Browse the repository at this point in the history
reason:
We would like to replace the big lock with a small lock.

Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 authored and xiaoxiang781216 committed Dec 18, 2024
1 parent 658e4ff commit bc6bf01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/nuttx/wireless/bluetooth/bt_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include <stddef.h>
#include <stdint.h>

#include <nuttx/spinlock.h>

/****************************************************************************
* Public Types
****************************************************************************/
Expand Down Expand Up @@ -114,6 +116,7 @@ struct bt_bufferlist_s
{
FAR struct bt_buf_s *head;
FAR struct bt_buf_s *tail;
spinlock_t lock;
};

/****************************************************************************
Expand Down
11 changes: 7 additions & 4 deletions wireless/bluetooth/bt_hcicore.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ static void bt_enqueue_bufwork(FAR struct bt_bufferlist_s *list,
{
irqstate_t flags;

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&list->lock);
buf->flink = list->head;
if (list->head == NULL)
{
list->tail = buf;
}

list->head = buf;
spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&list->lock, flags);
}

/****************************************************************************
Expand All @@ -172,7 +172,7 @@ static FAR struct bt_buf_s *
FAR struct bt_buf_s *buf;
irqstate_t flags;

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&list->lock);
buf = list->tail;
if (buf != NULL)
{
Expand Down Expand Up @@ -201,7 +201,7 @@ static FAR struct bt_buf_s *
buf->flink = NULL;
}

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&list->lock, flags);
return buf;
}

Expand Down Expand Up @@ -1653,6 +1653,9 @@ int bt_initialize(void)
memset(&g_lp_rxlist, 0, sizeof(g_lp_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);
bt_buf_initialize();

Expand Down

0 comments on commit bc6bf01

Please sign in to comment.