35#include <sys/select.h>
47 static int thread_count = 0;
49#if tskKERNEL_VERSION_MAJOR >= 9
51 (OSEventType)pvTaskGetThreadLocalStoragePointer(
52 nullptr, TLS_INDEX_SELECT_EVENT_BIT);
55 (OSEventType)xTaskGetApplicationTaskTag(
nullptr);
60 if(thread_count >= OSEvent::number_of_bits())
64 event = 0x1 << thread_count;
65#if defined (TLS_INDEX_SELECT_EVENT_BIT)
67 vTaskSetThreadLocalStoragePointer(
nullptr, TLS_INDEX_SELECT_EVENT_BIT,
71 vTaskSetApplicationTaskTag(
nullptr, (
void*)event);
97 fd_set *exceptfds,
long long timeout)
109 fd_set *in_set[3] = {readfds, writefds, exceptfds};
110 fd_set *out_set[3] = {&rd_result, &wr_result, &ex_result};
117 portENTER_CRITICAL();
126 for (
int mode = 0; mode < 3; ++mode)
131 for (
int i = 0; i < nfds; ++i)
133 if (FD_ISSET(i, in_set[mode]))
141 if (file->
dev->
select(file, mode_type[mode]))
144 FD_SET(i, out_set[mode]);
157 *readfds = rd_result;
161 *writefds = wr_result;
165 *exceptfds = ex_result;
184 wakeup.timedwait(event, NULL,
true, OSEvent::WAIT_ANY, until - now);
189 wakeup.wait(event, NULL,
true, OSEvent::WAIT_ANY);
202 portENTER_CRITICAL();
212 portENTER_CRITICAL();
213 if (info->
event != 0)
226 if (info->
event != 0)
234 portYIELD_FROM_ISR(*woken);
235#elif defined(THUMB_INTERWORK)
238 portYIELD_FROM_ISR();
241 os_isr_exit_yield_test(*woken);
static OSEventType get_event()
Returns an event bit unique to the current thread.
static OSEvent wakeup
event used to wakeup select calls
static File * file_lookup(int fd)
Looks up a reference to a File corresponding to a given file descriptor.
virtual bool select(File *file, int mode)
Device select method.
static long long get_monotonic()
Get the monotonic time since the system started.
#define FWRITE
Workaround for missing header defines on some newlib versions.
#define FREAD
Workaround for missing header defines on some newlib versions.
Select wakeup information.
OSEventType event
bit mask of clients that need woken
static void select_wakeup_from_isr(SelectInfo *info, int *woken)
Wakeup the list of clients needing woken.
static void select_insert(SelectInfo *info)
Add client to list of clients needing woken.
static Device * first
first device in linked list
static void select_wakeup(SelectInfo *info)
Wakeup the list of clients needing woken.
static int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, long long timeout)
POSIX select().
static void select_clear()
Clears the current thread's select bits.
FileIO * dev
file operations