emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/android c02a7b2ff4 7/7: Fix android_select


From: Po Lu
Subject: feature/android c02a7b2ff4 7/7: Fix android_select
Date: Sat, 14 Jan 2023 09:48:54 -0500 (EST)

branch: feature/android
commit c02a7b2ff48746fab891db16f58ccdc11d161745
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Fix android_select
    
    * src/android.c (android_run_select_thread, android_select):
    Handle EINTR in sem_wait and fix sigsets.
---
 src/android.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/android.c b/src/android.c
index e4022501f9..5e5e28c60c 100644
--- a/src/android.c
+++ b/src/android.c
@@ -246,13 +246,23 @@ android_run_select_thread (void *data)
                         "pthread_sigmask: %s",
                         strerror (errno));
 
+  sigdelset (&signals, SIGUSR1);
+
   while (true)
     {
       /* Wait for the thread to be released.  */
-      sem_wait (&android_pselect_start_sem);
+      while (sem_wait (&android_pselect_start_sem) < 0)
+       ;;
 
       /* Get the select lock and call pselect.  */
       pthread_mutex_lock (&event_queue.select_mutex);
+
+      /* Make sure SIGUSR1 can always wake pselect up.  */
+      if (android_pselect_sigset)
+       sigdelset (android_pselect_sigset, SIGUSR1);
+      else
+       android_pselect_sigset = &signals;
+
       rc = pselect (android_pselect_nfds,
                    android_pselect_readfds,
                    android_pselect_writefds,
@@ -436,6 +446,7 @@ android_select (int nfds, fd_set *readfds, fd_set *writefds,
   /* Release the select thread.  */
   sem_post (&android_pselect_start_sem);
 
+  /* Start waiting for the event queue condition to be set.  */
   pthread_cond_wait (&event_queue.read_var, &event_queue.mutex);
 
   /* Interrupt the select thread now, in case it's still in
@@ -443,7 +454,8 @@ android_select (int nfds, fd_set *readfds, fd_set *writefds,
   pthread_kill (event_queue.select_thread, SIGUSR1);
 
   /* Wait for pselect to return in any case.  */
-  sem_wait (&android_pselect_sem);
+  while (sem_wait (&android_pselect_sem) < 0)
+    ;;
 
   /* If there are now events in the queue, return 1.  */
   if (event_queue.num_events)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]