Skip to content

Commit

Permalink
spin_lock: inline spin_lock
Browse files Browse the repository at this point in the history
test:
We can use qemu for testing.
compiling
make distclean -j20; ./tools/configure.sh -l qemu-armv8a:nsh_smp ;make -j20
running
qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic -machine virt,virtualization=on,gic-version=3 -net none -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -kernel ./nuttx
  • Loading branch information
hujun260 committed Jul 3, 2024
1 parent 0083ae1 commit 2e15099
Show file tree
Hide file tree
Showing 29 changed files with 305 additions and 596 deletions.
1 change: 1 addition & 0 deletions arch/arm/src/lpc54xx/lpc54_lowputc.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include <arch/board/board.h>

#include <nuttx/arch.h>
#include <nuttx/spinlock.h>

/****************************************************************************
* Pre-processor Definitions
Expand Down
1 change: 1 addition & 0 deletions arch/arm/src/lpc54xx/lpc54_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/serial/serial.h>
#include <nuttx/spinlock.h>

#include <arch/board/board.h>

Expand Down
1 change: 1 addition & 0 deletions arch/arm/src/stm32/stm32_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <nuttx/fs/ioctl.h>
#include <nuttx/serial/serial.h>
#include <nuttx/power/pm.h>
#include <nuttx/spinlock.h>

#ifdef CONFIG_SERIAL_TERMIOS
# include <termios.h>
Expand Down
1 change: 1 addition & 0 deletions arch/arm/src/stm32f0l0g0/stm32_serial_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <nuttx/arch.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/serial/serial.h>
#include <nuttx/spinlock.h>
#include <nuttx/power/pm.h>

#ifdef CONFIG_SERIAL_TERMIOS
Expand Down
1 change: 1 addition & 0 deletions arch/arm/src/stm32f0l0g0/stm32_serial_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <nuttx/arch.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/serial/serial.h>
#include <nuttx/spinlock.h>
#include <nuttx/power/pm.h>

#ifdef CONFIG_SERIAL_TERMIOS
Expand Down
1 change: 1 addition & 0 deletions arch/arm/src/stm32h7/stm32_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <nuttx/arch.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/serial/serial.h>
#include <nuttx/spinlock.h>
#include <nuttx/semaphore.h>
#include <nuttx/power/pm.h>

Expand Down
1 change: 1 addition & 0 deletions arch/arm/src/stm32l4/stm32l4_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <nuttx/arch.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/serial/serial.h>
#include <nuttx/spinlock.h>
#include <nuttx/power/pm.h>

#ifdef CONFIG_SERIAL_TERMIOS
Expand Down
1 change: 1 addition & 0 deletions arch/arm/src/stm32l5/stm32l5_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <nuttx/arch.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/serial/serial.h>
#include <nuttx/spinlock.h>
#include <nuttx/power/pm.h>

#ifdef CONFIG_SERIAL_TERMIOS
Expand Down
1 change: 1 addition & 0 deletions arch/arm/src/stm32u5/stm32_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <nuttx/arch.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/serial/serial.h>
#include <nuttx/spinlock.h>
#include <nuttx/power/pm.h>

#ifdef CONFIG_SERIAL_TERMIOS
Expand Down
1 change: 1 addition & 0 deletions arch/arm/src/stm32wb/stm32wb_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <nuttx/arch.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/serial/serial.h>
#include <nuttx/spinlock.h>
#include <nuttx/power/pm.h>
#include <arch/board/board.h>

Expand Down
1 change: 1 addition & 0 deletions arch/arm/src/stm32wl5/stm32wl5_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <nuttx/arch.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/serial/serial.h>
#include <nuttx/spinlock.h>
#include <nuttx/power/pm.h>

#ifdef CONFIG_SERIAL_TERMIOS
Expand Down
1 change: 1 addition & 0 deletions arch/arm/src/tms570/tms570_lowputc.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <arch/board/board.h>
#include <nuttx/spinlock.h>

#include "arm_internal.h"
#include "hardware/tms570_sci.h"
Expand Down
1 change: 1 addition & 0 deletions arch/arm/src/xmc4/xmc4_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/serial/serial.h>
#include <nuttx/spinlock.h>

#include <arch/board/board.h>

Expand Down
1 change: 1 addition & 0 deletions arch/mips/src/pic32mx/pic32mx_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/serial/serial.h>
#include <nuttx/spinlock.h>

#include <arch/board/board.h>

Expand Down
1 change: 1 addition & 0 deletions arch/mips/src/pic32mz/pic32mz_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <nuttx/arch.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/serial/serial.h>
#include <nuttx/spinlock.h>

#include <arch/board/board.h>

Expand Down
1 change: 1 addition & 0 deletions arch/risc-v/src/bl602/bl602_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <nuttx/serial/serial.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/serial/tioctl.h>
#include <nuttx/spinlock.h>

#include "bl602_lowputc.h"
#include "bl602_gpio.h"
Expand Down
1 change: 1 addition & 0 deletions arch/risc-v/src/esp32c3-legacy/esp32c3_lowputc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <nuttx/config.h>
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>

#include <sys/types.h>
#include <stdint.h>
Expand Down
1 change: 1 addition & 0 deletions arch/sparc/src/bm3803/bm3803-serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/serial/serial.h>
#include <nuttx/spinlock.h>

#include <arch/board/board.h>

Expand Down
1 change: 1 addition & 0 deletions arch/x86_64/src/intel64/intel64_cpustart.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <arch/arch.h>
#include <arch/irq.h>
#include <nuttx/arch.h>
#include <nuttx/spinlock.h>

#include "init/init.h"

Expand Down
1 change: 1 addition & 0 deletions drivers/serial/uart_16550.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <nuttx/serial/serial.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/serial/uart_16550.h>
#include <nuttx/spinlock.h>

#include <arch/board/board.h>

Expand Down
19 changes: 10 additions & 9 deletions fs/inode/fs_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <nuttx/mutex.h>
#include <nuttx/sched.h>
#include <nuttx/spawn.h>
#include <nuttx/spinlock.h>

#ifdef CONFIG_FDSAN
# include <android/fdsan.h>
Expand All @@ -66,11 +67,11 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list,
FAR struct file *filep;
irqstate_t flags;

flags = spin_lock_irqsave(&list->fl_lock);
flags = spin_lock_irqsave(NULL);

filep = &list->fl_files[l1][l2];

spin_unlock_irqrestore(&list->fl_lock, flags);
spin_unlock_irqrestore(NULL, flags);

return filep;
}
Expand Down Expand Up @@ -125,7 +126,7 @@ static int files_extend(FAR struct filelist *list, size_t row)
}
while (++i < row);

flags = spin_lock_irqsave(&list->fl_lock);
flags = spin_lock_irqsave(NULL);

/* To avoid race condition, if the file list is updated by other threads
* and list rows is greater or equal than temp list,
Expand All @@ -134,7 +135,7 @@ static int files_extend(FAR struct filelist *list, size_t row)

if (orig_rows != list->fl_rows && list->fl_rows >= row)
{
spin_unlock_irqrestore(&list->fl_lock, flags);
spin_unlock_irqrestore(NULL, flags);

for (j = orig_rows; j < i; j++)
{
Expand All @@ -156,7 +157,7 @@ static int files_extend(FAR struct filelist *list, size_t row)
list->fl_files = files;
list->fl_rows = row;

spin_unlock_irqrestore(&list->fl_lock, flags);
spin_unlock_irqrestore(NULL, flags);

if (tmp != NULL && tmp != &list->fl_prefile)
{
Expand Down Expand Up @@ -484,21 +485,21 @@ int file_allocate_from_tcb(FAR struct tcb_s *tcb, FAR struct inode *inode,

/* Find free file */

flags = spin_lock_irqsave(&list->fl_lock);
flags = spin_lock_irqsave(NULL);

for (; ; i++, j = 0)
{
if (i >= list->fl_rows)
{
spin_unlock_irqrestore(&list->fl_lock, flags);
spin_unlock_irqrestore(NULL, flags);

ret = files_extend(list, i + 1);
if (ret < 0)
{
return ret;
}

flags = spin_lock_irqsave(&list->fl_lock);
flags = spin_lock_irqsave(NULL);
}

do
Expand All @@ -518,7 +519,7 @@ int file_allocate_from_tcb(FAR struct tcb_s *tcb, FAR struct inode *inode,
}

found:
spin_unlock_irqrestore(&list->fl_lock, flags);
spin_unlock_irqrestore(NULL, flags);

if (addref)
{
Expand Down
2 changes: 0 additions & 2 deletions include/nuttx/fs/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/spinlock.h>
#include <nuttx/mm/map.h>
#include <nuttx/spawn.h>
#include <nuttx/queue.h>
Expand Down Expand Up @@ -490,7 +489,6 @@ struct file

struct filelist
{
spinlock_t fl_lock; /* Manage access to the file list */
uint8_t fl_rows; /* The number of rows of fl_files array */
FAR struct file **fl_files; /* The pointer of two layer file descriptors array */

Expand Down
Loading

0 comments on commit 2e15099

Please sign in to comment.