Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
eventfd.h
Go to the documentation of this file.
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 <zephyr.h>
11#include <sys/fdtable.h>
12#include <sys/types.h>
13
14#include <fcntl.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20#define EFD_IN_USE 0x1
21#define EFD_SEMAPHORE 0x2
22#define EFD_NONBLOCK O_NONBLOCK
23#define EFD_FLAGS_SET (EFD_SEMAPHORE | EFD_NONBLOCK)
24
26
42int eventfd(unsigned int initval, int flags);
43
54static inline int eventfd_read(int fd, eventfd_t *value)
55{
56 const struct fd_op_vtable *efd_vtable;
57 struct k_mutex *lock;
59 void *obj;
60
61 obj = z_get_fd_obj_and_vtable(fd, &efd_vtable, &lock);
62
64
65 ret = efd_vtable->read(obj, value, sizeof(*value));
66
68
69 return ret == sizeof(eventfd_t) ? 0 : -1;
70}
71
80static inline int eventfd_write(int fd, eventfd_t value)
81{
82 const struct fd_op_vtable *efd_vtable;
83 struct k_mutex *lock;
85 void *obj;
86
87 obj = z_get_fd_obj_and_vtable(fd, &efd_vtable, &lock);
88
90
91 ret = efd_vtable->write(obj, &value, sizeof(value));
92
94
95 return ret == sizeof(eventfd_t) ? 0 : -1;
96}
97
98#ifdef __cplusplus
99}
100#endif
101
102#endif /* ZEPHYR_INCLUDE_POSIX_SYS_EVENTFD_H_ */
void
Definition: eswifi_shell.c:15
static int eventfd_read(int fd, eventfd_t *value)
Read from an eventfd.
Definition: eventfd.h:54
static int eventfd_write(int fd, eventfd_t value)
Write to an eventfd.
Definition: eventfd.h:80
int eventfd(unsigned int initval, int flags)
Create a file descriptor for event notification.
uint64_t eventfd_t
Definition: eventfd.h:25
#define K_FOREVER
Generate infinite timeout delay.
Definition: kernel.h:1186
int k_mutex_unlock(struct k_mutex *mutex)
Unlock a mutex.
int k_mutex_lock(struct k_mutex *mutex, k_timeout_t timeout)
Lock a mutex.
flags
Definition: http_parser.h:131
static ZTEST_BMEM volatile int ret
Definition: k_float_disable.c:28
__SIZE_TYPE__ ssize_t
Definition: types.h:28
static struct k_spinlock lock
Definition: spinlock_error_case.c:12
__UINT64_TYPE__ uint64_t
Definition: stdint.h:61
Definition: fdtable.h:22
ssize_t(* read)(void *obj, void *buf, size_t sz)
Definition: fdtable.h:23
ssize_t(* write)(void *obj, const void *buf, size_t sz)
Definition: fdtable.h:24
Definition: kernel.h:2680