[pulseaudio-commits] 3 commits - src/daemon src/pulsecore

Tanu Kaskinen tanuk at kemper.freedesktop.org
Fri Jun 6 06:03:38 PDT 2014


 src/daemon/main.c          |   34 -------------------------
 src/pulsecore/poll-win32.c |   60 +++++++++++++++++++++++----------------------
 2 files changed, 31 insertions(+), 63 deletions(-)

New commits:
commit 6f4e08140fd048a21cadf12e7bb6cd9877617c80
Author: Pierre Ossman <ossman at cendio.se>
Date:   Fri Sep 20 10:28:20 2013 +0200

    daemon: get rid of win32 message timer
    
    We don't need a timer to check for Windows messages anymore
    now that our fancy new poll() implementation does that for us.

diff --git a/src/daemon/main.c b/src/daemon/main.c
index 02a8ea6..c5a7d28 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -114,27 +114,6 @@ int deny_severity = LOG_WARNING;
 int __padsp_disabled__ = 7;
 #endif
 
-#ifdef OS_IS_WIN32
-
-static void message_cb(pa_mainloop_api*a, pa_time_event*e, const struct timeval *tv, void *userdata) {
-    MSG msg;
-    struct timeval tvnext;
-
-    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
-        if (msg.message == WM_QUIT)
-            raise(SIGTERM);
-        else {
-            TranslateMessage(&msg);
-            DispatchMessage(&msg);
-        }
-    }
-
-    pa_timeval_add(pa_gettimeofday(&tvnext), 100000);
-    a->time_restart(e, &tvnext);
-}
-
-#endif
-
 static void signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig, void *userdata) {
     pa_log_info(_("Got signal %s."), pa_sig2str(sig));
 
@@ -410,10 +389,6 @@ int main(int argc, char *argv[]) {
     int daemon_pipe[2] = { -1, -1 };
     int daemon_pipe2[2] = { -1, -1 };
 #endif
-#ifdef OS_IS_WIN32
-    pa_time_event *win32_timer;
-    struct timeval win32_tv;
-#endif
     int autospawn_fd = -1;
     bool autospawn_locked = false;
 #ifdef HAVE_DBUS
@@ -1071,10 +1046,6 @@ int main(int argc, char *argv[]) {
     pa_signal_new(SIGHUP, signal_callback, c);
 #endif
 
-#ifdef OS_IS_WIN32
-    win32_timer = pa_mainloop_get_api(mainloop)->time_new(pa_mainloop_get_api(mainloop), pa_gettimeofday(&win32_tv), message_cb, NULL);
-#endif
-
     if (!conf->no_cpu_limit)
         pa_assert_se(pa_cpu_limit_init(pa_mainloop_get_api(mainloop)) == 0);
 
@@ -1169,11 +1140,6 @@ finish:
         pa_autospawn_lock_done(false);
     }
 
-#ifdef OS_IS_WIN32
-    if (mainloop && win32_timer)
-        pa_mainloop_get_api(mainloop)->time_free(win32_timer);
-#endif
-
     if (c) {
         /* Ensure all the modules/samples are unloaded when the core is still ref'ed,
          * as unlink callback hooks in modules may need the core to be ref'ed */
diff --git a/src/pulsecore/poll-win32.c b/src/pulsecore/poll-win32.c
index 169a1ec..c927e53 100644
--- a/src/pulsecore/poll-win32.c
+++ b/src/pulsecore/poll-win32.c
@@ -46,6 +46,7 @@ typedef unsigned long nfds_t;
 # include <io.h>
 # include <stdio.h>
 # include <conio.h>
+# include <signal.h>
 # if 0
 # include "msvc-nothrow.h"
 # endif
@@ -568,8 +569,13 @@ restart:
           BOOL bRet;
           while ((bRet = PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) != 0)
             {
-              TranslateMessage (&msg);
-              DispatchMessage (&msg);
+              if (msg.message == WM_QUIT)
+                  raise(SIGTERM);
+              else
+                {
+                  TranslateMessage (&msg);
+                  DispatchMessage (&msg);
+                }
             }
         }
       else

commit f70ec2776aefe706c8ee510f1c6c44c637c02b64
Author: Pierre Ossman <ossman at cendio.se>
Date:   Mon Sep 23 14:56:38 2013 +0200

    poll: don't let select() block on Windows
    
    We cannot let select() block as we won't wake up on the other
    things that MsgWaitForMultipleObjects() can monitor.

diff --git a/src/pulsecore/poll-win32.c b/src/pulsecore/poll-win32.c
index 25c9860..169a1ec 100644
--- a/src/pulsecore/poll-win32.c
+++ b/src/pulsecore/poll-win32.c
@@ -350,8 +350,9 @@ int
 pa_poll (struct pollfd *pfd, nfds_t nfd, int timeout)
 {
   struct timeval tv;
-  struct timeval *ptv;
+
 #ifndef WINDOWS_NATIVE
+  struct timeval *ptv;
   fd_set rfds, wfds, efds;
   int maxfd, rc;
   nfds_t i;
@@ -376,17 +377,6 @@ pa_poll (struct pollfd *pfd, nfds_t nfd, int timeout)
     }
 #  endif /* OPEN_MAX -- else, no check is needed */
 # endif /* !_SC_OPEN_MAX */
-#else /* WINDOWS_NATIVE*/
-  HANDLE hEvent;
-  WSANETWORKEVENTS ev;
-  HANDLE h, handle_array[FD_SETSIZE + 2];
-  DWORD ret, wait_timeout, nhandles;
-  fd_set rfds, wfds, xfds;
-  BOOL poll_again;
-  MSG msg;
-  int rc = 0;
-  nfds_t i;
-#endif
 
   /* EFAULT is not necessary to implement, but let's do it in the
      simplest case. */
@@ -418,7 +408,6 @@ pa_poll (struct pollfd *pfd, nfds_t nfd, int timeout)
       return -1;
     }
 
-#ifndef WINDOWS_NATIVE
   /* create fd sets and determine max fd */
   maxfd = -1;
   FD_ZERO (&rfds);
@@ -475,7 +464,16 @@ pa_poll (struct pollfd *pfd, nfds_t nfd, int timeout)
       }
 
   return rc;
-#else
+#else /* WINDOWS_NATIVE*/
+  HANDLE hEvent;
+  WSANETWORKEVENTS ev;
+  HANDLE h, handle_array[FD_SETSIZE + 2];
+  DWORD ret, wait_timeout, nhandles;
+  fd_set rfds, wfds, xfds;
+  BOOL poll_again;
+  MSG msg;
+  int rc = 0;
+  nfds_t i;
 
   hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
 
@@ -534,19 +532,16 @@ restart:
             handle_array[nhandles++] = h;
           if (pfd[i].revents)
             timeout = 0;
-          else
-            {
-              if (!ptv)
-                ptv = &tv;
-              /* tune down to 0.25s. But don't touch smaller timeouts */
-              if (ptv->tv_usec > 250*1000 || ptv->tv_sec > 0)
-                ptv->tv_usec = 250*1000;
-              ptv->tv_sec = 0;
-            }
         }
     }
 
-  if (select (0, &rfds, &wfds, &xfds, ptv) > 0)
+  /* We poll current status using select(). It cannot be used to check
+     anything but sockets, so we still have to wait in
+     MsgWaitForMultipleObjects(). But that in turn cannot check existing
+     state, so we can't remove this select(). */
+  /* FIXME: MSDN states that we cannot give empty fd_set:s. */
+  tv.tv_sec = tv.tv_usec = 0;
+  if (select (0, &rfds, &wfds, &xfds, &tv) > 0)
     {
       /* Do MsgWaitForMultipleObjects anyway to dispatch messages, but
          no need to call select again.  */
@@ -582,7 +577,7 @@ restart:
     }
 
   if (poll_again)
-    select (0, &rfds, &wfds, &xfds, ptv);
+    select (0, &rfds, &wfds, &xfds, &tv);
 
   /* Place a sentinel at the end of the array.  */
   handle_array[nhandles] = NULL;

commit 7776a42be45016698f3f051ef7234f1aa5687621
Author: Pierre Ossman <ossman at cendio.se>
Date:   Mon Sep 23 14:53:02 2013 +0200

    poll: don't use shared event in Windows pa_poll()
    
    We call pa_poll concurrently from multiple threads, so we cannot
    have an event object that is reused.

diff --git a/src/pulsecore/poll-win32.c b/src/pulsecore/poll-win32.c
index 4a70171..25c9860 100644
--- a/src/pulsecore/poll-win32.c
+++ b/src/pulsecore/poll-win32.c
@@ -377,7 +377,7 @@ pa_poll (struct pollfd *pfd, nfds_t nfd, int timeout)
 #  endif /* OPEN_MAX -- else, no check is needed */
 # endif /* !_SC_OPEN_MAX */
 #else /* WINDOWS_NATIVE*/
-  static HANDLE hEvent;
+  HANDLE hEvent;
   WSANETWORKEVENTS ev;
   HANDLE h, handle_array[FD_SETSIZE + 2];
   DWORD ret, wait_timeout, nhandles;
@@ -477,8 +477,7 @@ pa_poll (struct pollfd *pfd, nfds_t nfd, int timeout)
   return rc;
 #else
 
-  if (!hEvent)
-    hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
+  hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
 
 restart:
   handle_array[0] = hEvent;
@@ -639,6 +638,8 @@ restart:
       goto restart;
     }
 
+  CloseHandle(hEvent);
+
   return rc;
 #endif
 }



More information about the pulseaudio-commits mailing list