summaryrefslogtreecommitdiff
path: root/x11/libX11/patches/patch-ah
blob: fbf72e43ae1efb553625cb11d0b7f0e68540d30e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
$NetBSD: patch-ah,v 1.3 2008/07/24 01:07:31 bjs Exp $

--- src/XlibInt.c.orig	2008-07-23 01:53:49.000000000 -0400
+++ src/XlibInt.c
@@ -206,8 +206,6 @@ static char *_XAsyncReply(
     Bool discard);
 #endif /* !USE_XCB */
 
-#define SEQLIMIT (65535 - (BUFSIZE / SIZEOF(xReq)) - 10)
-
 /*
  * The following routines are internal routines used by Xlib for protocol
  * packet transmission and reception.
@@ -570,24 +568,34 @@ _XWaitForReadable(
 }
 #endif /* !USE_XCB */
 
+static int sync_hazard(Display *dpy)
+{
+    unsigned long span = dpy->request - dpy->last_request_read;
+    unsigned long hazard = min((dpy->bufmax - dpy->buffer) / SIZEOF(xReq), 65535 - 10);
+    return span >= 65535 - hazard - 10;
+}
+
 static
 int _XSeqSyncFunction(
     register Display *dpy)
 {
     xGetInputFocusReply rep;
     register xReq *req;
+    int sent_sync = 0;
 
     LockDisplay(dpy);
-    if ((dpy->request - dpy->last_request_read) >= (BUFSIZE / SIZEOF(xReq))) {
+    if ((dpy->request - dpy->last_request_read) >= (65535 - BUFSIZE/SIZEOF(xReq))) {
 	GetEmptyReq(GetInputFocus, req);
 	(void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
+	sent_sync = 1;
     }
     /* could get XID handler while waiting for reply in MT env */
-    if (dpy->synchandler == _XSeqSyncFunction) {
+    if (dpy->synchandler == _XSeqSyncFunction && !sync_hazard(dpy)) {
 	dpy->synchandler = dpy->savedsynchandler;
 	dpy->flags &= ~XlibDisplayPrivSync;
     }
     UnlockDisplay(dpy);
+    if (sent_sync)
     SyncHandle();
     return 0;
 }
@@ -595,8 +603,7 @@ int _XSeqSyncFunction(
 void _XSetSeqSyncFunction(
     register Display *dpy)
 {
-    if ((dpy->request - dpy->last_request_read) >= SEQLIMIT &&
-	!(dpy->flags & XlibDisplayPrivSync)) {
+    if (!(dpy->flags & XlibDisplayPrivSync) && sync_hazard(dpy)) {
 	dpy->savedsynchandler = dpy->synchandler;
 	dpy->synchandler = _XSeqSyncFunction;
 	dpy->flags |= XlibDisplayPrivSync;