Skip to content

Commit

Permalink
note: Remove enter_critical_section from the sched_note module to avo…
Browse files Browse the repository at this point in the history
…id recursive calls.

Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 committed Nov 25, 2024
1 parent 358261a commit 43eca5e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions drivers/note/noterpmsg_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <nuttx/rpmsg/rpmsg.h>
#include <nuttx/sched_note.h>
#include <nuttx/wqueue.h>
#include <nuttx/spinlock.h>

#include "noterpmsg.h"

Expand All @@ -49,6 +50,7 @@ struct noterpmsg_driver_s
uint8_t buffer[CONFIG_DRIVERS_NOTERPMSG_BUFSIZE];
struct work_s work;
struct rpmsg_endpoint ept;
spinlock_t note_driver_lock;
};

/****************************************************************************
Expand Down Expand Up @@ -178,15 +180,15 @@ static bool noterpmsg_transfer(FAR struct noterpmsg_driver_s *drv,
static void noterpmsg_work(FAR void *priv)
{
FAR struct noterpmsg_driver_s *drv = priv;
irqstate_t flags = enter_critical_section();
irqstate_t flags = spin_lock_irqsave_wo_note(&drv->note_driver_lock);

if (!noterpmsg_transfer(drv, false))
{
work_queue(HPWORK, &drv->work, noterpmsg_work, drv,
NOTE_RPMSG_WORK_DELAY);
}

leave_critical_section(flags);
spin_unlock_irqrestore_wo_note(&drv->note_driver_lock, flags);
}

static void noterpmsg_add(FAR struct note_driver_s *driver,
Expand All @@ -197,7 +199,7 @@ static void noterpmsg_add(FAR struct note_driver_s *driver,
irqstate_t flags;
size_t space;

flags = enter_critical_section();
flags = spin_lock_irqsave_wo_note(&drv->note_driver_lock);

space = CONFIG_DRIVERS_NOTERPMSG_BUFSIZE - noterpmsg_length(drv);
if (space < notelen)
Expand Down Expand Up @@ -234,7 +236,7 @@ static void noterpmsg_add(FAR struct note_driver_s *driver,
NOTE_RPMSG_WORK_DELAY);
}

leave_critical_section(flags);
spin_unlock_irqrestore_wo_note(&drv->note_driver_lock, flags);
}

static int noterpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
Expand All @@ -254,6 +256,7 @@ static void noterpmsg_device_created(FAR struct rpmsg_device *rdev,
rpmsg_get_cpuname(rdev)) == 0)
{
drv->ept.priv = drv;
spin_lock_init(&drv->note_driver_lock);

ret = rpmsg_create_ept(&drv->ept, rdev, NOTERPMSG_EPT_NAME,
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
Expand Down

0 comments on commit 43eca5e

Please sign in to comment.