This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 23e5e1b86ec mtd/nvs: Save events if not waited
23e5e1b86ec is described below
commit 23e5e1b86ecc17d38f96fcee4dcdc867a267c7da
Author: wangjianyu3 <[email protected]>
AuthorDate: Tue Sep 9 17:16:44 2025 +0800
mtd/nvs: Save events if not waited
This patch will report events in the following scenarios:
1. Events that have changed but not been waited for before being added to
the interest list.
2. Events that occur after `epoll_wait()` returns and before it is called
again.
Signed-off-by: wangjianyu3 <[email protected]>
---
drivers/mtd/mtd_config_fs.c | 50 ++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 45 insertions(+), 5 deletions(-)
diff --git a/drivers/mtd/mtd_config_fs.c b/drivers/mtd/mtd_config_fs.c
index cd869519b8a..0b895206489 100644
--- a/drivers/mtd/mtd_config_fs.c
+++ b/drivers/mtd/mtd_config_fs.c
@@ -100,6 +100,7 @@ struct nvs_fs
uint32_t step_addr; /* For traverse */
mutex_t nvs_lock;
FAR struct pollfd *fds;
+ pollevent_t events;
};
/* Allocation Table Entry */
@@ -1095,6 +1096,8 @@ static int nvs_startup(FAR struct nvs_fs *fs)
fs->ate_wra = 0;
fs->data_wra = 0;
+ fs->events = 0;
+ fs->fds = NULL;
/* Get the device geometry. (Casting to uintptr_t first eliminates
* complaints on some architectures where the sizeof long is different
@@ -1989,6 +1992,43 @@ static int nvs_next(FAR struct nvs_fs *fs,
return OK;
}
+/****************************************************************************
+ * Name: mtdconfig_notify
+ *
+ * Description:
+ * Notify the poll if any waiter, or save events for next setup.
+ *
+ * Input Parameters:
+ * fs - Pointer to file system.
+ * eventset - List of events to check for activity
+ *
+ * Returned Value:
+ * None.
+ *
+ ****************************************************************************/
+
+static void mtdconfig_notify(FAR struct nvs_fs *fs, pollevent_t eventset)
+{
+ /* Handle events in two possible ways:
+ * 1. Notify waters directly if any exist(`fs->fds` is not NULL)
+ * 2. Save events for the following scenarios:
+ * a. Events that have changed but weren't waited for
+ * before being added to the interest list
+ * b. Events occurring after `epoll_wait()` returns and
+ * before it's called again
+ */
+
+ if (fs->fds)
+ {
+ poll_notify(&fs->fds, 1, eventset | fs->events);
+ fs->events = 0;
+ }
+ else
+ {
+ fs->events |= eventset;
+ }
+}
+
/****************************************************************************
* Name: mtdconfig_open
****************************************************************************/
@@ -2049,9 +2089,9 @@ static int mtdconfig_ioctl(FAR struct file *filep, int
cmd,
/* Write a nvs item. */
ret = nvs_write(fs, pdata);
- if (ret >= 0 && fs->fds)
+ if (ret >= 0)
{
- poll_notify(&fs->fds, 1, POLLPRI);
+ mtdconfig_notify(fs, POLLPRI);
}
break;
@@ -2061,9 +2101,9 @@ static int mtdconfig_ioctl(FAR struct file *filep, int
cmd,
/* Delete a nvs item. */
ret = nvs_delete(fs, pdata);
- if (ret >= 0 && fs->fds)
+ if (ret >= 0)
{
- poll_notify(&fs->fds, 1, POLLPRI);
+ mtdconfig_notify(fs, POLLPRI);
}
break;
@@ -2119,7 +2159,7 @@ static int mtdconfig_poll(FAR struct file *filep, FAR
struct pollfd *fds,
if (setup)
{
fs->fds = fds;
- poll_notify(&fds, 1, POLLIN | POLLOUT);
+ mtdconfig_notify(fs, POLLIN | POLLOUT);
}
else
{