diff options
author | Jon TURNEY <jon.turney@dronecode.org.uk> | 2012-02-24 17:01:18 +0000 |
---|---|---|
committer | Jon TURNEY <jon.turney@dronecode.org.uk> | 2012-03-31 19:23:21 +0100 |
commit | 475d248cef2c84e56458f9faa4d95157ed904f8b (patch) | |
tree | b704439a0fbfa9bf1da0814149504bf6126c0298 | |
parent | 71267654296e822c23bfbfa144432491bd53d272 (diff) |
Introduce winProcessXEventsTimeout() to the concept of fractions of a second
Oh this is terrible.
Currently we only compute the select timeout in whole seconds. This means if
we have less than 1 second remaining, we select with a timeout of 0 (i.e. poll)
which causes the task to spin, burning 100% CPU for the remaining timeout (and
possibly preventing the process we are waiting for from running :S)
-rw-r--r-- | hw/xwin/winclipboardwndproc.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/hw/xwin/winclipboardwndproc.c b/hw/xwin/winclipboardwndproc.c index 5b94c6f57..ea54ed269 100644 --- a/hw/xwin/winclipboardwndproc.c +++ b/hw/xwin/winclipboardwndproc.c @@ -76,10 +76,9 @@ winProcessXEventsTimeout (HWND hwnd, int iWindow, Display *pDisplay, int iConnNumber; struct timeval tv; int iReturn; - DWORD dwStopTime = (GetTickCount () / 1000) + iTimeoutSec; + DWORD dwStopTime = GetTickCount() + iTimeoutSec * 1000; - /* We need to ensure that all pending events are processed */ - XSync (pDisplay, FALSE); + winDebug("winProcessXEventsTimeout () - pumping X events for %d seconds\n", iTimeoutSec); /* Get our connection number */ iConnNumber = ConnectionNumber (pDisplay); @@ -88,17 +87,23 @@ winProcessXEventsTimeout (HWND hwnd, int iWindow, Display *pDisplay, while (1) { fd_set fdsRead; + long remainingTime; + + /* We need to ensure that all pending events are processed */ + XSync (pDisplay, FALSE); /* Setup the file descriptor set */ FD_ZERO (&fdsRead); FD_SET (iConnNumber, &fdsRead); /* Adjust timeout */ - tv.tv_sec = dwStopTime - (GetTickCount () / 1000); - tv.tv_usec = 0; + remainingTime = dwStopTime - GetTickCount(); + tv.tv_sec = remainingTime / 1000; + tv.tv_usec = (remainingTime % 1000) * 1000; + winDebug("winProcessXEventsTimeout () - %d milliseconds left\n", remainingTime); /* Break out if no time left */ - if (tv.tv_sec < 0) + if (remainingTime <= 0) return WIN_XEVENTS_SUCCESS; /* Wait for an X event */ @@ -106,7 +111,7 @@ winProcessXEventsTimeout (HWND hwnd, int iWindow, Display *pDisplay, &fdsRead, /* Read mask */ NULL, /* No write mask */ NULL, /* No exception mask */ - &tv); /* No timeout */ + &tv); /* Timeout */ if (iReturn < 0) { ErrorF ("winProcessXEventsTimeout - Call to select () failed: %d. " @@ -123,12 +128,19 @@ winProcessXEventsTimeout (HWND hwnd, int iWindow, Display *pDisplay, iWindow, pDisplay, fUseUnicode); + + winDebug("winProcessXEventsTimeout () - winClipboardFlushXEvents returned %d\n", iReturn); + if (WIN_XEVENTS_NOTIFY == iReturn) { /* Bail out if notify processed */ return iReturn; } } + else + { + winDebug("winProcessXEventsTimeout - Spurious wake\n"); + } } return WIN_XEVENTS_SUCCESS; |