6
6
* Change Logs:
7
7
* Date Author Notes
8
8
* 2023-07-20 zmq810150896 first version
9
+ * 2024-03-28 TroyMitchell Add comments for all functions
9
10
*/
10
11
11
12
#include <rtthread.h>
@@ -58,6 +59,11 @@ static const struct dfs_file_ops eventfd_fops =
58
59
.write = eventfd_write ,
59
60
};
60
61
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
+ */
61
67
static int eventfd_close (struct dfs_file * file )
62
68
{
63
69
struct eventfd_ctx * ctx = file -> vnode -> data ;
@@ -71,6 +77,12 @@ static int eventfd_close(struct dfs_file *file)
71
77
return 0 ;
72
78
}
73
79
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
+ */
74
86
static int eventfd_poll (struct dfs_file * file , struct rt_pollreq * req )
75
87
{
76
88
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)
94
106
}
95
107
96
108
#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
+ */
97
116
static ssize_t eventfd_read (struct dfs_file * file , void * buf , size_t count )
98
117
#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
+ */
99
126
static ssize_t eventfd_read (struct dfs_file * file , void * buf , size_t count , off_t * pos )
100
127
#endif
101
128
{
@@ -146,8 +173,23 @@ static ssize_t eventfd_read(struct dfs_file *file, void *buf, size_t count, off_
146
173
}
147
174
148
175
#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
+ */
149
183
static ssize_t eventfd_write (struct dfs_file * file , const void * buf , size_t count )
150
184
#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
+ */
151
193
static ssize_t eventfd_write (struct dfs_file * file , const void * buf , size_t count , off_t * pos )
152
194
#endif
153
195
{
@@ -198,7 +240,13 @@ static ssize_t eventfd_write(struct dfs_file *file, const void *buf, size_t coun
198
240
199
241
return ret ;
200
242
}
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
+ */
202
250
static int rt_eventfd_create (struct dfs_file * df , unsigned int count , int flags )
203
251
{
204
252
struct eventfd_ctx * ctx = RT_NULL ;
@@ -243,6 +291,12 @@ static int rt_eventfd_create(struct dfs_file *df, unsigned int count, int flags)
243
291
return ret ;
244
292
}
245
293
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
+ */
246
300
static int do_eventfd (unsigned int count , int flags )
247
301
{
248
302
struct dfs_file * file ;
@@ -279,6 +333,12 @@ static int do_eventfd(unsigned int count, int flags)
279
333
return ret ;
280
334
}
281
335
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
+ */
282
342
int eventfd (unsigned int count , int flags )
283
343
{
284
344
return do_eventfd (count , flags );
0 commit comments