fslock:Optimize the performance overhead caused by frequent close
Summary: Indicate whether the file is currently locked by adding a new field locked to filep. 0 - Unlocked 1 - Locked The status of the filep at close is used to determine whether to continue with the following procedure. Optimizing performance: Before Time taken to close the file: 33984 nsec After Time taken to close the file: 23744 nsec Improvement of about 10 msec Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
This commit is contained in:
parent
c528244f19
commit
dba77ff043
|
@ -30,6 +30,7 @@
|
|||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/lib/lib.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/mutex.h>
|
||||
|
@ -715,6 +716,10 @@ retry:
|
|||
goto out;
|
||||
}
|
||||
|
||||
/* Update filep lock state */
|
||||
|
||||
filep->locked = true;
|
||||
|
||||
/* When there is a lock change, we need to wake up the blocking lock */
|
||||
|
||||
if (bucket->nwaiter > 0)
|
||||
|
@ -751,6 +756,11 @@ void file_closelk(FAR struct file *filep)
|
|||
bool deleted = false;
|
||||
int ret;
|
||||
|
||||
if (filep->locked == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
path = lib_get_pathbuffer();
|
||||
if (path == NULL)
|
||||
{
|
||||
|
@ -784,6 +794,7 @@ void file_closelk(FAR struct file *filep)
|
|||
{
|
||||
deleted = true;
|
||||
file_lock_delete(file_lock);
|
||||
filep->locked = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -480,6 +480,10 @@ struct file
|
|||
#if CONFIG_FS_BACKTRACE > 0
|
||||
FAR void *f_backtrace[CONFIG_FS_BACKTRACE]; /* Backtrace to while file opens */
|
||||
#endif
|
||||
|
||||
#if CONFIG_FS_LOCK_BUCKET_SIZE > 0
|
||||
bool locked; /* Filelock state: false - unlocked, true - locked */
|
||||
#endif
|
||||
};
|
||||
|
||||
/* This defines a two layer array of files indexed by the file descriptor.
|
||||
|
|
Loading…
Reference in New Issue