Skip to content

Commit

Permalink
bt_buf: use small lock in wireless/bluetooth/bt_buf.c
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 29f1ca2 commit 2c69d62
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions wireless/bluetooth/bt_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static struct bt_buf_s
g_buf_pool[CONFIG_BLUETOOTH_BUFFER_PREALLOC];

static bool g_poolinit = false;
static spinlock_t g_buf_lock = SP_UNLOCKED;

/****************************************************************************
* Public Functions
Expand Down Expand Up @@ -238,7 +239,7 @@ FAR struct bt_buf_s *bt_buf_alloc(enum bt_buf_type_e type,
* then try the list of messages reserved for interrupt handlers
*/

flags = spin_lock_irqsave(NULL); /* Always necessary in SMP mode */
flags = spin_lock_irqsave(&g_buf_lock); /* Always necessary in SMP mode */
if (up_interrupt_context())
{
#if CONFIG_BLUETOOTH_BUFFER_PREALLOC > CONFIG_BLUETOOTH_BUFFER_IRQRESERVE
Expand All @@ -249,7 +250,7 @@ FAR struct bt_buf_s *bt_buf_alloc(enum bt_buf_type_e type,
buf = g_buf_free;
g_buf_free = buf->flink;

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_buf_lock, flags);
pool = POOL_BUFFER_GENERAL;
}
else
Expand All @@ -262,13 +263,13 @@ FAR struct bt_buf_s *bt_buf_alloc(enum bt_buf_type_e type,
buf = g_buf_free_irq;
g_buf_free_irq = buf->flink;

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_buf_lock, flags);
pool = POOL_BUFFER_IRQ;
}
else
#endif
{
spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_buf_lock, flags);
return NULL;
}
}
Expand All @@ -285,7 +286,7 @@ FAR struct bt_buf_s *bt_buf_alloc(enum bt_buf_type_e type,
buf = g_buf_free;
g_buf_free = buf->flink;

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_buf_lock, flags);
pool = POOL_BUFFER_GENERAL;
}
else
Expand All @@ -295,7 +296,7 @@ FAR struct bt_buf_s *bt_buf_alloc(enum bt_buf_type_e type,
* will have to allocate one from the kernel memory pool.
*/

spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_buf_lock, flags);
buf = (FAR struct bt_buf_s *)
kmm_malloc((sizeof (struct bt_buf_s)));

Expand Down Expand Up @@ -425,10 +426,10 @@ void bt_buf_release(FAR struct bt_buf_s *buf)
* list from interrupt handlers.
*/

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_buf_lock);
buf->flink = g_buf_free;
g_buf_free = buf;
spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_buf_lock, flags);
}
else
#endif
Expand All @@ -444,10 +445,10 @@ void bt_buf_release(FAR struct bt_buf_s *buf)
* list from interrupt handlers.
*/

flags = spin_lock_irqsave(NULL);
flags = spin_lock_irqsave(&g_buf_lock);
buf->flink = g_buf_free_irq;
g_buf_free_irq = buf;
spin_unlock_irqrestore(NULL, flags);
spin_unlock_irqrestore(&g_buf_lock, flags);
}
else
#endif
Expand Down

0 comments on commit 2c69d62

Please sign in to comment.