|
@@ -6,6 +6,7 @@
|
|
* Change Logs:
|
|
* Change Logs:
|
|
* Date Author Notes
|
|
* Date Author Notes
|
|
* 2023-07-20 zmq810150896 first version
|
|
* 2023-07-20 zmq810150896 first version
|
|
|
|
+ * 2024-03-28 TroyMitchell Add comments for all functions
|
|
*/
|
|
*/
|
|
|
|
|
|
#include <rtthread.h>
|
|
#include <rtthread.h>
|
|
@@ -58,6 +59,11 @@ static const struct dfs_file_ops eventfd_fops =
|
|
.write = eventfd_write,
|
|
.write = eventfd_write,
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * @brief Closes an event file descriptor.
|
|
|
|
+ * @param file Pointer to the file descriptor structure.
|
|
|
|
+ * @return 0 on success, otherwise an error code.
|
|
|
|
+ */
|
|
static int eventfd_close(struct dfs_file *file)
|
|
static int eventfd_close(struct dfs_file *file)
|
|
{
|
|
{
|
|
struct eventfd_ctx *ctx = file->vnode->data;
|
|
struct eventfd_ctx *ctx = file->vnode->data;
|
|
@@ -71,6 +77,12 @@ static int eventfd_close(struct dfs_file *file)
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * @brief Polls an event file descriptor for events.
|
|
|
|
+ * @param file Pointer to the file descriptor structure.
|
|
|
|
+ * @param req Pointer to the poll request structure.
|
|
|
|
+ * @return Events that occurred on the file descriptor.
|
|
|
|
+ */
|
|
static int eventfd_poll(struct dfs_file *file, struct rt_pollreq *req)
|
|
static int eventfd_poll(struct dfs_file *file, struct rt_pollreq *req)
|
|
{
|
|
{
|
|
struct eventfd_ctx *ctx = (struct eventfd_ctx *)file->vnode->data;
|
|
struct eventfd_ctx *ctx = (struct eventfd_ctx *)file->vnode->data;
|
|
@@ -94,8 +106,23 @@ static int eventfd_poll(struct dfs_file *file, struct rt_pollreq *req)
|
|
}
|
|
}
|
|
|
|
|
|
#ifndef RT_USING_DFS_V2
|
|
#ifndef RT_USING_DFS_V2
|
|
|
|
+/**
|
|
|
|
+ * @brief Reads data from an event file descriptor.
|
|
|
|
+ * @param file Pointer to the file descriptor structure.
|
|
|
|
+ * @param buf Pointer to the buffer to read data into.
|
|
|
|
+ * @param count Maximum number of bytes to read.
|
|
|
|
+ * @return Number of bytes read on success, otherwise an error code.
|
|
|
|
+ */
|
|
static ssize_t eventfd_read(struct dfs_file *file, void *buf, size_t count)
|
|
static ssize_t eventfd_read(struct dfs_file *file, void *buf, size_t count)
|
|
#else
|
|
#else
|
|
|
|
+/**
|
|
|
|
+ * @brief Reads data from an event file descriptor.
|
|
|
|
+ * @param file Pointer to the file descriptor structure.
|
|
|
|
+ * @param buf Pointer to the buffer to read data into.
|
|
|
|
+ * @param count Maximum number of bytes to read.
|
|
|
|
+ * @param pos Pointer to the file position (not used).
|
|
|
|
+ * @return Number of bytes read on success, otherwise an error code.
|
|
|
|
+ */
|
|
static ssize_t eventfd_read(struct dfs_file *file, void *buf, size_t count, off_t *pos)
|
|
static ssize_t eventfd_read(struct dfs_file *file, void *buf, size_t count, off_t *pos)
|
|
#endif
|
|
#endif
|
|
{
|
|
{
|
|
@@ -146,8 +173,23 @@ static ssize_t eventfd_read(struct dfs_file *file, void *buf, size_t count, off_
|
|
}
|
|
}
|
|
|
|
|
|
#ifndef RT_USING_DFS_V2
|
|
#ifndef RT_USING_DFS_V2
|
|
|
|
+/**
|
|
|
|
+ * @brief Writes data to an event file descriptor.
|
|
|
|
+ * @param file Pointer to the file descriptor structure.
|
|
|
|
+ * @param buf Pointer to the buffer containing data to write.
|
|
|
|
+ * @param count Number of bytes to write.
|
|
|
|
+ * @return Number of bytes written on success, otherwise an error code.
|
|
|
|
+ */
|
|
static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t count)
|
|
static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t count)
|
|
#else
|
|
#else
|
|
|
|
+/**
|
|
|
|
+ * @brief Writes data to an event file descriptor.
|
|
|
|
+ * @param file Pointer to the file descriptor structure.
|
|
|
|
+ * @param buf Pointer to the buffer containing data to write.
|
|
|
|
+ * @param count Number of bytes to write.
|
|
|
|
+ * @param pos Pointer to the file position (not used).
|
|
|
|
+ * @return Number of bytes written on success, otherwise an error code.
|
|
|
|
+ */
|
|
static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t count, off_t *pos)
|
|
static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t count, off_t *pos)
|
|
#endif
|
|
#endif
|
|
{
|
|
{
|
|
@@ -198,7 +240,13 @@ static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t coun
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+/**
|
|
|
|
+ * @brief Creates an event file descriptor.
|
|
|
|
+ * @param df Pointer to the file descriptor structure.
|
|
|
|
+ * @param count Initial value of the event counter.
|
|
|
|
+ * @param flags Flags for the event file descriptor.
|
|
|
|
+ * @return 0 on success, otherwise an error code.
|
|
|
|
+ */
|
|
static int rt_eventfd_create(struct dfs_file *df, unsigned int count, int flags)
|
|
static int rt_eventfd_create(struct dfs_file *df, unsigned int count, int flags)
|
|
{
|
|
{
|
|
struct eventfd_ctx *ctx = RT_NULL;
|
|
struct eventfd_ctx *ctx = RT_NULL;
|
|
@@ -243,6 +291,12 @@ static int rt_eventfd_create(struct dfs_file *df, unsigned int count, int flags)
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * @brief Internal function to create an event file descriptor.
|
|
|
|
+ * @param count Initial value of the event counter.
|
|
|
|
+ * @param flags Flags for the event file descriptor.
|
|
|
|
+ * @return File descriptor on success, otherwise an error code.
|
|
|
|
+ */
|
|
static int do_eventfd(unsigned int count, int flags)
|
|
static int do_eventfd(unsigned int count, int flags)
|
|
{
|
|
{
|
|
struct dfs_file *file;
|
|
struct dfs_file *file;
|
|
@@ -279,6 +333,12 @@ static int do_eventfd(unsigned int count, int flags)
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * @brief Creates an event file descriptor with the specified count and flags.
|
|
|
|
+ * @param count Initial value of the event counter.
|
|
|
|
+ * @param flags Flags for the event file descriptor.
|
|
|
|
+ * @return File descriptor on success, otherwise an error code.
|
|
|
|
+ */
|
|
int eventfd(unsigned int count, int flags)
|
|
int eventfd(unsigned int count, int flags)
|
|
{
|
|
{
|
|
return do_eventfd(count, flags);
|
|
return do_eventfd(count, flags);
|