Initial integration of poll()

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1266 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2008-11-17 20:27:26 +00:00
parent e4922667b2
commit acbefdbb30
2 changed files with 24 additions and 8 deletions

View File

@ -48,6 +48,7 @@
#include <nuttx/fs.h> #include <nuttx/fs.h>
#include <nuttx/sched.h> #include <nuttx/sched.h>
#include <nuttx/clock.h>
#include "fs_internal.h" #include "fs_internal.h"
@ -195,6 +196,7 @@ static inline int poll_teardown(FAR struct pollfd *fds, nfds_t nfds, int *count)
/* Process each descriptor in the list */ /* Process each descriptor in the list */
*count = 0;
for (i = 0; i < nfds; i++) for (i = 0; i < nfds; i++)
{ {
/* Teardown the poll */ /* Teardown the poll */
@ -228,7 +230,7 @@ static inline int poll_teardown(FAR struct pollfd *fds, nfds_t nfds, int *count)
* *
****************************************************************************/ ****************************************************************************/
static void poll_timeout(int argc, uint32 isem) static void poll_timeout(int argc, uint32 isem, ...)
{ {
/* Wake up the poller */ /* Wake up the poller */
@ -284,16 +286,19 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
{ {
if (timeout >= 0) if (timeout >= 0)
{ {
/* Wait for the poll event with a timeout */ /* Wait for the poll event with a timeout. Note that the
* millisecond timeout has to be converted to system clock
* ticks for wd_start
*/
wdog = wd_create(); wdog = wd_create();
wd_start(wdog, poll_timeout, 1, (uint32)&sem); wd_start(wdog, MSEC2TICK(timeout), poll_timeout, 1, (uint32)&sem);
poll_semtake(&sem); poll_semtake(&sem);
wd_delete(wdog); wd_delete(wdog);
} }
else else
{ {
/* Wait for the poll event with not timeout */ /* Wait for the poll event with no timeout */
poll_semtake(&sem); poll_semtake(&sem);
} }

View File

@ -89,14 +89,25 @@
* Public Type Definitions * Public Type Definitions
****************************************************************************/ ****************************************************************************/
/* The number of poll descriptors (required by poll() specification */
typedef unsigned int nfds_t; typedef unsigned int nfds_t;
/* In the standard poll() definition, the size of the event set is 'short'.
* Here we pick the smallest storage element that will contain all of the
* poll events.
*/
typedef ubyte pollevent_t;
/* This is the Nuttx variant of the standard pollfd structure. */
struct pollfd struct pollfd
{ {
int fd; /* The descriptor being polled */ int fd; /* The descriptor being polled */
sem_t *sem; /* Pointer to semaphore used to post output event */ sem_t *sem; /* Pointer to semaphore used to post output event */
ubyte events; /* The input event flags */ pollevent_t events; /* The input event flags */
ubyte revents; /* The output event flags */ pollevent_t revents; /* The output event flags */
}; };
/**************************************************************************** /****************************************************************************