34#ifndef _OS_OSSELECTWAKEUP_HXX_
35#define _OS_OSSELECTWAKEUP_HXX_
43#if OPENMRN_FEATURE_DEVICE_SELECT
47#if OPENMRN_HAVE_PSELECT
53#elif OPENMRN_HAVE_SELECT
54#include <sys/select.h>
60#ifdef CONFIG_VFS_SUPPORT_TERMIOS
87 esp_deallocate_vfs_fd();
104 esp_allocate_vfs_fd();
106#if OPENMRN_FEATURE_DEVICE_SELECT
108#elif OPENMRN_HAVE_PSELECT
111 HASSERT(!sigemptyset(&usrmask));
112 HASSERT(!sigaddset(&usrmask, WAKEUP_SIG));
113 HASSERT(!sigprocmask(SIG_BLOCK, &usrmask, &origMask_));
114 HASSERT(!sigdelset(&origMask_, WAKEUP_SIG));
115 struct sigaction action;
117 HASSERT(!sigemptyset(&action.sa_mask));
119 HASSERT(!sigaction(WAKEUP_SIG, &action,
nullptr));
126 bool need_wakeup =
false;
137#if OPENMRN_FEATURE_DEVICE_SELECT
142#elif OPENMRN_HAVE_PSELECT
143 pthread_kill(
thread_, WAKEUP_SIG);
144#elif defined(ESP_PLATFORM)
146#elif !defined(OPENMRN_FEATURE_SINGLE_THREADED)
147 DIE(
"need wakeup code");
159#if OPENMRN_FEATURE_RTOS_FROM_ISR
160 void wakeup_from_isr()
162#if defined(ESP_PLATFORM)
169#if OPENMRN_FEATURE_DEVICE_SELECT
174 os_isr_exit_yield_test(woken);
178#elif defined(ESP_PLATFORM)
179 esp_wakeup_from_isr();
181 DIE(
"need wakeup code");
201 int select(
int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
202 long long deadline_nsec);
206 void esp_allocate_vfs_fd();
207 void esp_deallocate_vfs_fd();
209 void esp_wakeup_from_isr();
211 void esp_start_select(fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
212 esp_vfs_select_sem_t signal_sem);
213 void esp_end_select();
221 esp_vfs_select_sem_t espSem_;
230 fd_set exceptFdsOrig_;
234#if OPENMRN_HAVE_PSELECT
236 static const int WAKEUP_SIG = SIGUSR1;
244#if OPENMRN_FEATURE_DEVICE_SELECT
247#if OPENMRN_HAVE_PSELECT
void empty_signal_handler(int sig)
Signal handler that does nothing.
See OSMutexLock in os/OS.hxx.
Lightweight locking class for protecting small critical sections.
Helper class that allows a select to be asynchronously woken up.
void wakeup()
Wakes up the select in the locked thread.
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, long long deadline_nsec)
Portable call to a select that can be woken up asynchronously from a different thread or an ISR conte...
os_thread_t thread_
ID of the main thread we are engaged upon.
bool pendingWakeup_
True if there was a wakeup call since the previous select finished.
os_thread_t main_thread()
bool inSelect_
True during the duration of a select operation.
void clear_wakeup()
Called from the main thread after being woken up.
void lock_to_thread()
Prepares the current thread for asynchronous wakeups.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define DIE(MSG)
Unconditionally terminates the current process with a message.
OS_INLINE os_thread_t os_thread_self(void)
Return a handle to the calling thread.
Select wakeup information.
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 void select_wakeup(SelectInfo *info)
Wakeup the list of clients needing woken.