Skip to content

Commit 7e492fc

Browse files
TroyMitchell911mysterywolf
authored andcommitted
Add comments for all functions in components/libc/posix/io/eventfd/eventfd.c
1 parent 83e95bd commit 7e492fc

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

components/libc/posix/io/eventfd/eventfd.c

+61-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2023-07-20 zmq810150896 first version
9+
* 2024-03-28 TroyMitchell Add comments for all functions
910
*/
1011

1112
#include <rtthread.h>
@@ -58,6 +59,11 @@ static const struct dfs_file_ops eventfd_fops =
5859
.write = eventfd_write,
5960
};
6061

62+
/**
63+
* @brief Closes an event file descriptor.
64+
* @param file Pointer to the file descriptor structure.
65+
* @return 0 on success, otherwise an error code.
66+
*/
6167
static int eventfd_close(struct dfs_file *file)
6268
{
6369
struct eventfd_ctx *ctx = file->vnode->data;
@@ -71,6 +77,12 @@ static int eventfd_close(struct dfs_file *file)
7177
return 0;
7278
}
7379

80+
/**
81+
* @brief Polls an event file descriptor for events.
82+
* @param file Pointer to the file descriptor structure.
83+
* @param req Pointer to the poll request structure.
84+
* @return Events that occurred on the file descriptor.
85+
*/
7486
static int eventfd_poll(struct dfs_file *file, struct rt_pollreq *req)
7587
{
7688
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)
94106
}
95107

96108
#ifndef RT_USING_DFS_V2
109+
/**
110+
* @brief Reads data from an event file descriptor.
111+
* @param file Pointer to the file descriptor structure.
112+
* @param buf Pointer to the buffer to read data into.
113+
* @param count Maximum number of bytes to read.
114+
* @return Number of bytes read on success, otherwise an error code.
115+
*/
97116
static ssize_t eventfd_read(struct dfs_file *file, void *buf, size_t count)
98117
#else
118+
/**
119+
* @brief Reads data from an event file descriptor.
120+
* @param file Pointer to the file descriptor structure.
121+
* @param buf Pointer to the buffer to read data into.
122+
* @param count Maximum number of bytes to read.
123+
* @param pos Pointer to the file position (not used).
124+
* @return Number of bytes read on success, otherwise an error code.
125+
*/
99126
static ssize_t eventfd_read(struct dfs_file *file, void *buf, size_t count, off_t *pos)
100127
#endif
101128
{
@@ -146,8 +173,23 @@ static ssize_t eventfd_read(struct dfs_file *file, void *buf, size_t count, off_
146173
}
147174

148175
#ifndef RT_USING_DFS_V2
176+
/**
177+
* @brief Writes data to an event file descriptor.
178+
* @param file Pointer to the file descriptor structure.
179+
* @param buf Pointer to the buffer containing data to write.
180+
* @param count Number of bytes to write.
181+
* @return Number of bytes written on success, otherwise an error code.
182+
*/
149183
static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t count)
150184
#else
185+
/**
186+
* @brief Writes data to an event file descriptor.
187+
* @param file Pointer to the file descriptor structure.
188+
* @param buf Pointer to the buffer containing data to write.
189+
* @param count Number of bytes to write.
190+
* @param pos Pointer to the file position (not used).
191+
* @return Number of bytes written on success, otherwise an error code.
192+
*/
151193
static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t count, off_t *pos)
152194
#endif
153195
{
@@ -198,7 +240,13 @@ static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t coun
198240

199241
return ret;
200242
}
201-
243+
/**
244+
* @brief Creates an event file descriptor.
245+
* @param df Pointer to the file descriptor structure.
246+
* @param count Initial value of the event counter.
247+
* @param flags Flags for the event file descriptor.
248+
* @return 0 on success, otherwise an error code.
249+
*/
202250
static int rt_eventfd_create(struct dfs_file *df, unsigned int count, int flags)
203251
{
204252
struct eventfd_ctx *ctx = RT_NULL;
@@ -243,6 +291,12 @@ static int rt_eventfd_create(struct dfs_file *df, unsigned int count, int flags)
243291
return ret;
244292
}
245293

294+
/**
295+
* @brief Internal function to create an event file descriptor.
296+
* @param count Initial value of the event counter.
297+
* @param flags Flags for the event file descriptor.
298+
* @return File descriptor on success, otherwise an error code.
299+
*/
246300
static int do_eventfd(unsigned int count, int flags)
247301
{
248302
struct dfs_file *file;
@@ -279,6 +333,12 @@ static int do_eventfd(unsigned int count, int flags)
279333
return ret;
280334
}
281335

336+
/**
337+
* @brief Creates an event file descriptor with the specified count and flags.
338+
* @param count Initial value of the event counter.
339+
* @param flags Flags for the event file descriptor.
340+
* @return File descriptor on success, otherwise an error code.
341+
*/
282342
int eventfd(unsigned int count, int flags)
283343
{
284344
return do_eventfd(count, flags);

0 commit comments

Comments
 (0)