This is an automated email from the ASF dual-hosted git repository.
GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 84df3fd6b87 bluetooth: net_snoop remove critical_section
84df3fd6b87 is described below
commit 84df3fd6b8746427ccec15c6d2fcf0406daf306b
Author: chengkai <[email protected]>
AuthorDate: Tue Jul 1 11:34:49 2025 +0800
bluetooth: net_snoop remove critical_section
Remove redundant critical_section
Signed-off-by: chengkai <[email protected]>
---
include/nuttx/net/snoop.h | 2 ++
net/utils/net_snoop.c | 24 ++++++++++++++++--------
2 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/include/nuttx/net/snoop.h b/include/nuttx/net/snoop.h
index 7a3524b0d2f..0e3c59d8e3c 100644
--- a/include/nuttx/net/snoop.h
+++ b/include/nuttx/net/snoop.h
@@ -31,6 +31,7 @@
#include <nuttx/fs/fs.h>
#include <nuttx/mutex.h>
+#include <nuttx/spinlock.h>
#include <nuttx/wqueue.h>
/****************************************************************************
@@ -96,6 +97,7 @@ struct snoop_s
uint32_t datalink;
struct file filep;
mutex_t mutex;
+ spinlock_t lock;
struct work_s work;
uint8_t buf[CONFIG_NET_SNOOP_BUFSIZE];
size_t next;
diff --git a/net/utils/net_snoop.c b/net/utils/net_snoop.c
index 53693751e1a..e1f15c0c89b 100644
--- a/net/utils/net_snoop.c
+++ b/net/utils/net_snoop.c
@@ -224,25 +224,34 @@ static void snoop_fill_packet_header(FAR struct snoop_s
*snoop,
static int snoop_flush(FAR struct snoop_s *snoop)
{
+ irqstate_t flags;
+ size_t len;
ssize_t ret;
- if (snoop->next == 0)
+ flags = spin_lock_irqsave(&snoop->lock);
+ len = snoop->next;
+ spin_unlock_irqrestore(&snoop->lock, flags);
+
+ if (len == 0)
{
return 0;
}
do
{
- ret = file_write(&snoop->filep, snoop->buf, snoop->next);
+ ret = file_write(&snoop->filep, snoop->buf, len);
if (ret < 0)
{
break;
}
+ flags = spin_lock_irqsave(&snoop->lock);
snoop->next -= ret;
memmove(snoop->buf, snoop->buf + ret, snoop->next);
+ len = snoop->next;
+ spin_unlock_irqrestore(&snoop->lock, flags);
}
- while (snoop->next > 0);
+ while (len > 0);
#ifndef CONFIG_DISABLE_MOUNTPOINT
if (snoop->autosync)
@@ -264,14 +273,11 @@ static int snoop_flush(FAR struct snoop_s *snoop)
static int snoop_flush_lock(FAR struct snoop_s *snoop)
{
- irqstate_t flags;
int ret;
- flags = enter_critical_section();
nxmutex_lock(&snoop->mutex);
ret = snoop_flush(snoop);
nxmutex_unlock(&snoop->mutex);
- leave_critical_section(flags);
return ret;
}
@@ -386,6 +392,7 @@ int snoop_open(FAR struct snoop_s *snoop, FAR const char
*filename,
}
nxmutex_init(&snoop->mutex);
+ spin_lock_init(&snoop->lock);
return OK;
error:
@@ -427,12 +434,13 @@ int snoop_dump(FAR struct snoop_s *snoop, FAR const void
*buf,
snoop_fill_packet_header(snoop, nbytes, drops, flags, &header);
- irqflags = enter_critical_section();
if (up_interrupt_context())
{
+ irqflags = spin_lock_irqsave(&snoop->lock);
if (sizeof(snoop->buf) - snoop->next <
nbytes + sizeof(struct snoop_packet_header_s))
{
+ spin_unlock_irqrestore(&snoop->lock, irqflags);
ret = -ENOMEM;
goto out_leave;
}
@@ -441,6 +449,7 @@ int snoop_dump(FAR struct snoop_s *snoop, FAR const void
*buf,
snoop->next += sizeof(header);
memcpy(snoop->buf + snoop->next, buf, nbytes);
snoop->next += nbytes;
+ spin_unlock_irqrestore(&snoop->lock, irqflags);
if (work_available(&snoop->work))
{
@@ -484,7 +493,6 @@ int snoop_dump(FAR struct snoop_s *snoop, FAR const void
*buf,
out_unlock:
nxmutex_unlock(&snoop->mutex);
out_leave:
- leave_critical_section(irqflags);
return ret;
}