Unverified Commit f24767b3 authored by Mike Gabriel's avatar Mike Gabriel

Merge branch 'uli42-pr/improve_wait_events' into 3.6.x

parents 7f4b50de 62573abf
...@@ -400,7 +400,7 @@ void nxagentWaitWakeupBySplit(ClientPtr client) ...@@ -400,7 +400,7 @@ void nxagentWaitWakeupBySplit(ClientPtr client)
fprintf(stderr, "++++++nxagentWaitWakeupBySplit: Yielding control to the NX transport.\n"); fprintf(stderr, "++++++nxagentWaitWakeupBySplit: Yielding control to the NX transport.\n");
#endif #endif
nxagentWaitEvents(nxagentDisplay, NULL); nxagentWaitEvents(nxagentDisplay, 0);
} }
} }
......
...@@ -3309,7 +3309,6 @@ int nxagentHandleConfigureNotify(XEvent* X) ...@@ -3309,7 +3309,6 @@ int nxagentHandleConfigureNotify(XEvent* X)
ScreenPtr pScreen = nxagentScreen(X -> xconfigure.window); ScreenPtr pScreen = nxagentScreen(X -> xconfigure.window);
Bool doRandR = False; Bool doRandR = False;
struct timeval timeout;
if (X -> xconfigure.window == nxagentDefaultWindows[pScreen -> myNum]) if (X -> xconfigure.window == nxagentDefaultWindows[pScreen -> myNum])
{ {
...@@ -3345,10 +3344,7 @@ int nxagentHandleConfigureNotify(XEvent* X) ...@@ -3345,10 +3344,7 @@ int nxagentHandleConfigureNotify(XEvent* X)
{ {
newEvents = False; newEvents = False;
timeout.tv_sec = 0; nxagentWaitEvents(nxagentDisplay, 500);
timeout.tv_usec = 500 * 1000;
nxagentWaitEvents(nxagentDisplay, &timeout);
/* /*
* This should also flush the NX link for us. * This should also flush the NX link for us.
...@@ -3827,7 +3823,7 @@ int nxagentWaitForResource(GetResourceFuncPtr pGetResource, PredicateFuncPtr pPr ...@@ -3827,7 +3823,7 @@ int nxagentWaitForResource(GetResourceFuncPtr pGetResource, PredicateFuncPtr pPr
while ((resource = (*pGetResource)(nxagentDisplay)) == -1) while ((resource = (*pGetResource)(nxagentDisplay)) == -1)
{ {
if (nxagentWaitEvents(nxagentDisplay, NULL) == -1) if (nxagentWaitEvents(nxagentDisplay, 0) == -1)
{ {
return -1; return -1;
} }
...@@ -4511,14 +4507,11 @@ int nxagentPendingEvents(Display *dpy) ...@@ -4511,14 +4507,11 @@ int nxagentPendingEvents(Display *dpy)
} }
/* /*
* Blocks until an event becomes * Blocks until an event becomes available.
* available.
*/ */
int nxagentWaitEvents(Display *dpy, struct timeval *tm) int nxagentWaitEvents(Display *dpy, useconds_t msec)
{ {
XEvent ev;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentWaitEvents called.\n"); fprintf(stderr, "nxagentWaitEvents called.\n");
#endif #endif
...@@ -4526,33 +4519,41 @@ int nxagentWaitEvents(Display *dpy, struct timeval *tm) ...@@ -4526,33 +4519,41 @@ int nxagentWaitEvents(Display *dpy, struct timeval *tm)
NXFlushDisplay(dpy, NXFlushLink); NXFlushDisplay(dpy, NXFlushLink);
/* /*
* If the transport is not running we * If the transport is not running we have to rely on Xlib to wait
* have to rely on Xlib to wait for an * for an event. In this case the timeout is ignored.
* event. In this case the timeout is
* ignored.
*/ */
if (NXTransRunning(NX_FD_ANY) == 1) if (NXTransRunning(NX_FD_ANY) == 1)
{ {
NXTransContinue(tm); if (msec > 0)
{
struct timeval tm = {
.tv_sec = 0,
.tv_usec = msec * 1000
};
NXTransContinue(&tm);
}
else
{
NXTransContinue(NULL);
}
} }
else else
{ {
XEvent ev;
XPeekEvent(dpy, &ev); XPeekEvent(dpy, &ev);
} }
/* /*
* Check if we encountered a display * Check if we encountered a display error. If we did, wait for the
* error. If we did, wait for the
* time requested by the caller. * time requested by the caller.
*/ */
if (NXDisplayError(dpy) == 1) if (NXDisplayError(dpy) == 1)
{ {
if (tm != NULL) if (msec > 0)
{ {
usleep(tm -> tv_sec * 1000 * 1000 + usleep(msec * 1000);
tm -> tv_usec);
} }
return -1; return -1;
......
...@@ -232,6 +232,6 @@ Bool nxagentPendingEvents(Display *dpy); ...@@ -232,6 +232,6 @@ Bool nxagentPendingEvents(Display *dpy);
#define nxagentCheckEvents(display, event, predicate, argument) \ #define nxagentCheckEvents(display, event, predicate, argument) \
XCheckIfEventNoFlush((display), (event), (predicate), (argument)) XCheckIfEventNoFlush((display), (event), (predicate), (argument))
int nxagentWaitEvents(Display *, struct timeval *); int nxagentWaitEvents(Display *, useconds_t msec);
#endif /* __Events_H__ */ #endif /* __Events_H__ */
...@@ -1255,7 +1255,7 @@ void nxagentDispatchHandler(ClientPtr client, int in, int out) ...@@ -1255,7 +1255,7 @@ void nxagentDispatchHandler(ClientPtr client, int in, int out)
while (nxagentTokens.pending == TOKENS_PENDING_LIMIT) while (nxagentTokens.pending == TOKENS_PENDING_LIMIT)
{ {
if (nxagentWaitEvents(nxagentDisplay, NULL) == -1) if (nxagentWaitEvents(nxagentDisplay, 0) == -1)
{ {
nxagentTokens.pending = 0; nxagentTokens.pending = 0;
......
...@@ -365,7 +365,6 @@ FIXME: We'll check for ReparentNotify and LeaveNotify events after ...@@ -365,7 +365,6 @@ FIXME: We'll check for ReparentNotify and LeaveNotify events after
for (int i = 0; i < 100 && nxagentWMIsRunning; i++) for (int i = 0; i < 100 && nxagentWMIsRunning; i++)
{ {
struct timeval timeout;
XEvent e; XEvent e;
#ifdef TEST #ifdef TEST
...@@ -379,10 +378,7 @@ FIXME: We'll check for ReparentNotify and LeaveNotify events after ...@@ -379,10 +378,7 @@ FIXME: We'll check for ReparentNotify and LeaveNotify events after
XSync(nxagentDisplay, 0); XSync(nxagentDisplay, 0);
timeout.tv_sec = 0; nxagentWaitEvents(nxagentDisplay, 50);
timeout.tv_usec = 50 * 1000;
nxagentWaitEvents(nxagentDisplay, &timeout);
} }
} }
else else
......
...@@ -804,7 +804,7 @@ void nxagentWaitDrawable(DrawablePtr pDrawable) ...@@ -804,7 +804,7 @@ void nxagentWaitDrawable(DrawablePtr pDrawable)
fprintf(stderr, "nxagentWaitDrawable: Yielding control to the NX transport.\n"); fprintf(stderr, "nxagentWaitDrawable: Yielding control to the NX transport.\n");
#endif #endif
nxagentWaitEvents(nxagentDisplay, NULL); nxagentWaitEvents(nxagentDisplay, 0);
} }
} }
......
...@@ -849,7 +849,6 @@ void nxagentSwitchAllScreens(ScreenPtr pScreen, Bool switchOn) ...@@ -849,7 +849,6 @@ void nxagentSwitchAllScreens(ScreenPtr pScreen, Bool switchOn)
* Change to fullscreen mode. * Change to fullscreen mode.
*/ */
struct timeval timeout;
int i; int i;
XEvent e; XEvent e;
...@@ -874,10 +873,7 @@ void nxagentSwitchAllScreens(ScreenPtr pScreen, Bool switchOn) ...@@ -874,10 +873,7 @@ void nxagentSwitchAllScreens(ScreenPtr pScreen, Bool switchOn)
XSync(nxagentDisplay, 0); XSync(nxagentDisplay, 0);
timeout.tv_sec = 0; nxagentWaitEvents(nxagentDisplay, 50);
timeout.tv_usec = 50 * 1000;
nxagentWaitEvents(nxagentDisplay, &timeout);
} }
if (i < 100) if (i < 100)
......
...@@ -1565,6 +1565,10 @@ int NXTransRunning(int fd) ...@@ -1565,6 +1565,10 @@ int NXTransRunning(int fd)
return (control != NULL); return (control != NULL);
} }
//
// FIXME: why timeval? Passing milliseconds would be more convenient,
// the timeval struct/T_timestamp could be built on demand.
//
int NXTransContinue(struct timeval *selectTs) int NXTransContinue(struct timeval *selectTs)
{ {
if (control != NULL) if (control != NULL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment