mirror of
https://github.com/apache/nuttx.git
synced 2026-05-25 18:27:56 +08:00
fs/vfs: Add file descriptor based events support
This commit is contained in:
+28
@@ -53,6 +53,34 @@ config PSEUDOFS_SOFTLINKS
|
||||
to link a directory in the pseudo-file system, such as /bin, to
|
||||
to a directory in a mounted volume, say /mnt/sdcard/bin.
|
||||
|
||||
config EVENT_FD
|
||||
bool "EventFD"
|
||||
default n
|
||||
---help---
|
||||
Create a file descriptor for event notification
|
||||
|
||||
if EVENT_FD
|
||||
|
||||
config EVENT_FD_VFS_PATH
|
||||
string "Path to eventfd storage"
|
||||
default "/var/event"
|
||||
---help---
|
||||
The path to where eventfd will exist in the VFS namespace.
|
||||
|
||||
config EVENT_FD_POLL
|
||||
bool "EventFD poll support"
|
||||
default y
|
||||
---help---
|
||||
Poll support for file descriptor based events
|
||||
|
||||
config EVENT_FD_NPOLLWAITERS
|
||||
int "Number of eventFD poll waiters"
|
||||
default 2
|
||||
---help---
|
||||
Maximum number of threads that can be waiting on poll()
|
||||
|
||||
endif # EVENT_FD
|
||||
|
||||
source fs/aio/Kconfig
|
||||
source fs/semaphore/Kconfig
|
||||
source fs/mqueue/Kconfig
|
||||
|
||||
@@ -66,6 +66,12 @@ ifeq ($(CONFIG_NET_SENDFILE),y)
|
||||
CSRCS += fs_sendfile.c
|
||||
endif
|
||||
|
||||
# Support for eventfd
|
||||
|
||||
ifeq ($(CONFIG_EVENT_FD),y)
|
||||
CSRCS += fs_eventfd.c
|
||||
endif
|
||||
|
||||
# Include vfs build support
|
||||
|
||||
DEPPATH += --dep-path vfs
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -121,6 +121,10 @@
|
||||
|
||||
/* Terminal I/O IOCTL definitions are retained in tioctl.h */
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/serial/tioctl.h>
|
||||
|
||||
/* Watchdog driver ioctl commands *******************************************/
|
||||
@@ -176,6 +180,10 @@
|
||||
* int value.
|
||||
* OUT: Origin option.
|
||||
*/
|
||||
#define FIOC_MINOR _FIOC(0x000c) /* IN: None
|
||||
* OUT: Integer that contains device
|
||||
* minor number
|
||||
*/
|
||||
|
||||
/* NuttX file system ioctl definitions **************************************/
|
||||
|
||||
@@ -309,6 +317,7 @@
|
||||
#define _PWMIOC(nr) _IOC(_PWMIOCBASE,nr)
|
||||
|
||||
/* NuttX USB CDC/ACM serial driver ioctl definitions ************************/
|
||||
|
||||
/* (see nuttx/usb/cdcacm.h) */
|
||||
|
||||
#define _CAIOCVALID(c) (_IOC_TYPE(c)==_CAIOCBASE)
|
||||
@@ -322,6 +331,7 @@
|
||||
#define _BATIOC(nr) _IOC(_BATIOCBASE,nr)
|
||||
|
||||
/* NuttX Quadrature Encoder driver ioctl definitions ************************/
|
||||
|
||||
/* (see nuttx/power/battery.h) */
|
||||
|
||||
#define _QEIOCVALID(c) (_IOC_TYPE(c)==_QEIOCBASE)
|
||||
@@ -349,6 +359,7 @@
|
||||
#define _SLCDIOC(nr) _IOC(_SLCDIOCBASE,nr)
|
||||
|
||||
/* Wireless driver character driver ioctl definitions ***********************/
|
||||
|
||||
/* (see nuttx/include/wireless/ioctl.h */
|
||||
|
||||
#define _WLCIOCVALID(c) (_IOC_TYPE(c)==_WLCIOCBASE)
|
||||
@@ -368,7 +379,7 @@
|
||||
#define _TCIOCVALID(c) (_IOC_TYPE(c)==_TCIOCBASE)
|
||||
#define _TCIOC(nr) _IOC(_TCIOCBASE,nr)
|
||||
|
||||
/* Joystick driver ioctl definitions ***************************************/
|
||||
/* Joystick driver ioctl definitions ****************************************/
|
||||
|
||||
/* Discrete Joystick (see nuttx/include/input/djoystick.h */
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/****************************************************************************
|
||||
* include/sys/eventfd.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_SYS_EVENTFD_H
|
||||
#define __INCLUDE_SYS_EVENTFD_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define EFD_NONBLOCK O_NONBLOCK
|
||||
#define EFD_SEMAPHORE O_BINARY
|
||||
#define EFD_CLOEXEC O_CLOEXEC
|
||||
|
||||
/* Get device minor number */
|
||||
|
||||
#define EFD_FIOC_MINOR FIOC_MINOR
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
/* Type for event counter */
|
||||
|
||||
typedef uint32_t eventfd_t;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
int eventfd(unsigned int count, int flags);
|
||||
|
||||
int eventfd_read(int fd, FAR eventfd_t *value);
|
||||
int eventfd_write(int fd, eventfd_t value);
|
||||
|
||||
int eventfd_get_minor(int fd);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_SYS_EVENTFD_H */
|
||||
@@ -208,6 +208,9 @@ SYSCALL_LOOKUP(pwrite, 4)
|
||||
SYSCALL_LOOKUP(select, 5)
|
||||
SYSCALL_LOOKUP(ppoll, 4)
|
||||
SYSCALL_LOOKUP(pselect, 6)
|
||||
#ifdef CONFIG_EVENT_FD
|
||||
SYSCALL_LOOKUP(eventfd, 2)
|
||||
#endif
|
||||
#ifdef CONFIG_NETDEV_IFINDEX
|
||||
SYSCALL_LOOKUP(if_indextoname, 2)
|
||||
SYSCALL_LOOKUP(if_nametoindex, 1)
|
||||
|
||||
@@ -28,6 +28,7 @@ include dirent/Make.defs
|
||||
include dlfcn/Make.defs
|
||||
include endian/Make.defs
|
||||
include errno/Make.defs
|
||||
include eventfd/Make.defs
|
||||
include fixedmath/Make.defs
|
||||
include grp/Make.defs
|
||||
include hex2bin/Make.defs
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
############################################################################
|
||||
# libs/libc/eventfd/Make.defs
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_EVENT_FD),y)
|
||||
CSRCS += lib_eventfd.c
|
||||
|
||||
DEPPATH += --dep-path eventfd
|
||||
VPATH += :eventfd
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/lib_eventfd.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
int eventfd_read(int fd, FAR eventfd_t *value)
|
||||
{
|
||||
return read(fd, value, sizeof (eventfd_t)) != sizeof (eventfd_t) ? -1 : 0;
|
||||
}
|
||||
|
||||
int eventfd_write(int fd, eventfd_t value)
|
||||
{
|
||||
return write(fd, &value,
|
||||
sizeof (eventfd_t)) != sizeof (eventfd_t) ? -1 : 0;
|
||||
}
|
||||
|
||||
int eventfd_get_minor(int fd)
|
||||
{
|
||||
int ret;
|
||||
int minor;
|
||||
|
||||
ret = ioctl(fd, EFD_FIOC_MINOR, &minor);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
return minor;
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
"connect","sys/socket.h","defined(CONFIG_NET)","int","int","FAR const struct sockaddr *","socklen_t"
|
||||
"dup","unistd.h","","int","int"
|
||||
"dup2","unistd.h","","int","int","int"
|
||||
"eventfd","sys/eventfd.h","defined(CONFIG_EVENT_FD)","unsigned int","int"
|
||||
"exec","nuttx/binfmt/binfmt.h","!defined(CONFIG_BINFMT_DISABLE) && !defined(CONFIG_BUILD_KERNEL)","int","FAR const char *","FAR char * const *","FAR const struct symtab_s *","int"
|
||||
"execv","unistd.h","!defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_LIBC_EXECFUNCS)","int","FAR const char *","FAR char * const []|FAR char * const *"
|
||||
"exit","stdlib.h","","void","int"
|
||||
|
||||
|
Reference in New Issue
Block a user