-
Notifications
You must be signed in to change notification settings - Fork 1.5k
filep Reference count #13217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
filep Reference count #13217
Conversation
include/nuttx/fs/fs.h
Outdated
| struct file | ||
| { | ||
| int f_oflags; /* Open mode flags */ | ||
| int f_refs; /* Reference count */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let us add a kconfig option to support disable this feature to save the code size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this add a lot of code size?It's not good to add too many restriction macros to code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can consider resolving similar issues in a more elegant way, eg:
#ifdef CONFIG_FS_REFCOUNT
int fs_putfilep(FAR struct file *filep)
#else
# define fs_putfilep(f)
#endif
and also, any changes you need to consider the situation of resource-constrained devices. If you think this feature must exist and cannot be restricted by kconfig, then you should choose linux instead of nuttx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Let me think about how to optimize。thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can consider resolving similar issues in a more elegant way, eg:
#ifdef CONFIG_FS_REFCOUNT int fs_putfilep(FAR struct file *filep) #else # define fs_putfilep(f) #endifand also, any changes you need to consider the situation of resource-constrained devices. If you think this feature must exist and cannot be restricted by kconfig, then you should choose linux instead of nuttx
but fs_putfilep need free filep if it's the last reference. Without reference count, it' hard to determine whether fs_putfilep should free or not free filep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could keep the orignal free point with a special name(maybe fs_freefilep?), eg:
#ifdef CONFIG_FS_REFCOUNT
int fs_putfilep(FAR struct file *filep);
# define fs_freefilep fs_putfilep
#else
int fs_freefilep(FAR struct file *filep);
# define fs_putfilep(f)
#endif

Summary
Increase the reference count of filep,fs_getfilep adds +1 to the reference count. After the call is complete, run the fs_putfilep command to release the reference count.When the reference count reaches 0, the file is actually closed.
Impact
This prevents the file from being closed while it is being read or written
Testing