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