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
Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 committed Jul 1, 2024
1 parent 09146be commit 3efd6ae
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 596 deletions.
19 changes: 10 additions & 9 deletions fs/inode/fs_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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 @@ -63,11 +64,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 @@ -122,7 +123,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 @@ -131,7 +132,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 @@ -153,7 +154,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 @@ -420,21 +421,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 @@ -454,7 +455,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 @@ -493,7 +492,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 3efd6ae

Please sign in to comment.