xwayland/glamor: Disable GLAMOR after GBM cleanup
[xserver.git] / Xext / sleepuntil.c
blob0fbfab10a17b37a672e8ba22951ebb35cf215357
1 /*
3 Copyright 1992, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
25 * Author: Keith Packard, MIT X Consortium
28 /* dixsleep.c - implement millisecond timeouts for X clients */
30 #include <dix-config.h>
32 #include "sleepuntil.h"
33 #include <X11/X.h>
34 #include <X11/Xmd.h>
35 #include "misc.h"
36 #include "windowstr.h"
37 #include "dixstruct.h"
38 #include "pixmapstr.h"
39 #include "scrnintstr.h"
41 typedef struct _Sertafied {
42 struct _Sertafied *next;
43 TimeStamp revive;
44 ClientPtr pClient;
45 XID id;
46 void (*notifyFunc) (ClientPtr /* client */ ,
47 void * /* closure */
50 void *closure;
51 } SertafiedRec, *SertafiedPtr;
53 static SertafiedPtr pPending;
54 static RESTYPE SertafiedResType;
55 static Bool BlockHandlerRegistered;
56 static int SertafiedGeneration;
58 static void ClientAwaken(ClientPtr /* client */ ,
59 void * /* closure */
61 static int SertafiedDelete(void * /* value */ ,
62 XID /* id */
64 static void SertafiedBlockHandler(void *data,
65 void *timeout);
67 static void SertafiedWakeupHandler(void *data,
68 int i);
70 int
71 ClientSleepUntil(ClientPtr client,
72 TimeStamp *revive,
73 void (*notifyFunc) (ClientPtr, void *), void *closure)
75 SertafiedPtr pRequest, pReq, pPrev;
77 if (SertafiedGeneration != serverGeneration) {
78 SertafiedResType = CreateNewResourceType(SertafiedDelete,
79 "ClientSleep");
80 if (!SertafiedResType)
81 return FALSE;
82 SertafiedGeneration = serverGeneration;
83 BlockHandlerRegistered = FALSE;
85 pRequest = malloc(sizeof(SertafiedRec));
86 if (!pRequest)
87 return FALSE;
88 pRequest->pClient = client;
89 pRequest->revive = *revive;
90 pRequest->id = FakeClientID(client->index);
91 pRequest->closure = closure;
92 if (!BlockHandlerRegistered) {
93 if (!RegisterBlockAndWakeupHandlers(SertafiedBlockHandler,
94 SertafiedWakeupHandler,
95 (void *) 0)) {
96 free(pRequest);
97 return FALSE;
99 BlockHandlerRegistered = TRUE;
101 pRequest->notifyFunc = 0;
102 if (!AddResource(pRequest->id, SertafiedResType, (void *) pRequest))
103 return FALSE;
104 if (!notifyFunc)
105 notifyFunc = ClientAwaken;
106 pRequest->notifyFunc = notifyFunc;
107 /* Insert into time-ordered queue, with earliest activation time coming first. */
108 pPrev = 0;
109 for (pReq = pPending; pReq; pReq = pReq->next) {
110 if (CompareTimeStamps(pReq->revive, *revive) == LATER)
111 break;
112 pPrev = pReq;
114 if (pPrev)
115 pPrev->next = pRequest;
116 else
117 pPending = pRequest;
118 pRequest->next = pReq;
119 IgnoreClient(client);
120 return TRUE;
123 static void
124 ClientAwaken(ClientPtr client, void *closure)
126 AttendClient(client);
129 static int
130 SertafiedDelete(void *value, XID id)
132 SertafiedPtr pRequest = (SertafiedPtr) value;
133 SertafiedPtr pReq, pPrev;
135 pPrev = 0;
136 for (pReq = pPending; pReq; pPrev = pReq, pReq = pReq->next)
137 if (pReq == pRequest) {
138 if (pPrev)
139 pPrev->next = pReq->next;
140 else
141 pPending = pReq->next;
142 break;
144 if (pRequest->notifyFunc)
145 (*pRequest->notifyFunc) (pRequest->pClient, pRequest->closure);
146 free(pRequest);
147 return TRUE;
150 static void
151 SertafiedBlockHandler(void *data, void *wt)
153 SertafiedPtr pReq, pNext;
154 unsigned long delay;
155 TimeStamp now;
157 if (!pPending)
158 return;
159 now.milliseconds = GetTimeInMillis();
160 now.months = currentTime.months;
161 if ((int) (now.milliseconds - currentTime.milliseconds) < 0)
162 now.months++;
163 for (pReq = pPending; pReq; pReq = pNext) {
164 pNext = pReq->next;
165 if (CompareTimeStamps(pReq->revive, now) == LATER)
166 break;
167 FreeResource(pReq->id, X11_RESTYPE_NONE);
169 /* AttendClient() may have been called via the resource delete
170 * function so a client may have input to be processed and so
171 * set delay to 0 to prevent blocking in WaitForSomething().
173 AdjustWaitForDelay(wt, 0);
175 pReq = pPending;
176 if (!pReq)
177 return;
178 delay = pReq->revive.milliseconds - now.milliseconds;
179 AdjustWaitForDelay(wt, delay);
182 static void
183 SertafiedWakeupHandler(void *data, int i)
185 SertafiedPtr pReq, pNext;
186 TimeStamp now;
188 now.milliseconds = GetTimeInMillis();
189 now.months = currentTime.months;
190 if ((int) (now.milliseconds - currentTime.milliseconds) < 0)
191 now.months++;
192 for (pReq = pPending; pReq; pReq = pNext) {
193 pNext = pReq->next;
194 if (CompareTimeStamps(pReq->revive, now) == LATER)
195 break;
196 FreeResource(pReq->id, X11_RESTYPE_NONE);
198 if (!pPending) {
199 RemoveBlockAndWakeupHandlers(SertafiedBlockHandler,
200 SertafiedWakeupHandler, (void *) 0);
201 BlockHandlerRegistered = FALSE;