1 /*
2  * Copyright (c) 2020 Tobias Svehagen
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_INCLUDE_POSIX_SYS_EVENTFD_H_
8 #define ZEPHYR_INCLUDE_POSIX_SYS_EVENTFD_H_
9 
10 #include <stdint.h>
11 
12 #include <zephyr/kernel.h>
13 #include <zephyr/posix/fcntl.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 #define EFD_IN_USE    0x1 __DEPRECATED_MACRO
20 #define EFD_SEMAPHORE 0x2
21 #define EFD_NONBLOCK  O_NONBLOCK
22 #define EFD_FLAGS_SET (EFD_SEMAPHORE | EFD_NONBLOCK) __DEPRECATED_MACRO
23 
24 typedef uint64_t eventfd_t;
25 
26 /**
27  * @brief Create a file descriptor for event notification
28  *
29  * The returned file descriptor can be used with POSIX read/write calls or
30  * with the eventfd_read/eventfd_write functions.
31  *
32  * It also supports polling and by including an eventfd in a call to poll,
33  * it is possible to signal and wake the polling thread by simply writing to
34  * the eventfd.
35  *
36  * When using read() and write() on an eventfd, the size must always be at
37  * least 8 bytes or the operation will fail with EINVAL.
38  *
39  * @return New eventfd file descriptor on success, -1 on error
40  */
41 int eventfd(unsigned int initval, int flags);
42 
43 /**
44  * @brief Read from an eventfd
45  *
46  * If call is successful, the value parameter will have the value 1
47  *
48  * @param fd File descriptor
49  * @param value Pointer for storing the read value
50  *
51  * @return 0 on success, -1 on error
52  */
53 int eventfd_read(int fd, eventfd_t *value);
54 
55 /**
56  * @brief Write to an eventfd
57  *
58  * @param fd File descriptor
59  * @param value Value to write
60  *
61  * @return 0 on success, -1 on error
62  */
63 int eventfd_write(int fd, eventfd_t value);
64 
65 #ifdef __cplusplus
66 }
67 #endif
68 
69 #endif /* ZEPHYR_INCLUDE_POSIX_SYS_EVENTFD_H_ */
70