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
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 #ifdef HAVE_DIX_CONFIG_H
31 #include <dix-config.h>
34 #include "sleepuntil.h"
38 #include "windowstr.h"
39 #include "dixstruct.h"
40 #include "pixmapstr.h"
41 #include "scrnintstr.h"
43 typedef struct _Sertafied
{
44 struct _Sertafied
*next
;
48 void (*notifyFunc
) (ClientPtr
/* client */ ,
53 } SertafiedRec
, *SertafiedPtr
;
55 static SertafiedPtr pPending
;
56 static RESTYPE SertafiedResType
;
57 static Bool BlockHandlerRegistered
;
58 static int SertafiedGeneration
;
60 static void ClientAwaken(ClientPtr
/* client */ ,
63 static int SertafiedDelete(pointer
/* value */ ,
66 static void SertafiedBlockHandler(pointer
/* data */ ,
68 pointer
/* LastSelectMask */
70 static void SertafiedWakeupHandler(pointer
/* data */ ,
72 pointer
/* LastSelectMask */
76 ClientSleepUntil(ClientPtr client
,
78 void (*notifyFunc
) (ClientPtr
, pointer
), pointer closure
)
80 SertafiedPtr pRequest
, pReq
, pPrev
;
82 if (SertafiedGeneration
!= serverGeneration
) {
83 SertafiedResType
= CreateNewResourceType(SertafiedDelete
,
85 if (!SertafiedResType
)
87 SertafiedGeneration
= serverGeneration
;
88 BlockHandlerRegistered
= FALSE
;
90 pRequest
= malloc(sizeof(SertafiedRec
));
93 pRequest
->pClient
= client
;
94 pRequest
->revive
= *revive
;
95 pRequest
->id
= FakeClientID(client
->index
);
96 pRequest
->closure
= closure
;
97 if (!BlockHandlerRegistered
) {
98 if (!RegisterBlockAndWakeupHandlers(SertafiedBlockHandler
,
99 SertafiedWakeupHandler
,
104 BlockHandlerRegistered
= TRUE
;
106 pRequest
->notifyFunc
= 0;
107 if (!AddResource(pRequest
->id
, SertafiedResType
, (pointer
) pRequest
))
110 notifyFunc
= ClientAwaken
;
111 pRequest
->notifyFunc
= notifyFunc
;
112 /* Insert into time-ordered queue, with earliest activation time coming first. */
114 for (pReq
= pPending
; pReq
; pReq
= pReq
->next
) {
115 if (CompareTimeStamps(pReq
->revive
, *revive
) == LATER
)
120 pPrev
->next
= pRequest
;
123 pRequest
->next
= pReq
;
124 IgnoreClient(client
);
129 ClientAwaken(ClientPtr client
, pointer closure
)
131 if (!client
->clientGone
)
132 AttendClient(client
);
136 SertafiedDelete(pointer value
, XID id
)
138 SertafiedPtr pRequest
= (SertafiedPtr
) value
;
139 SertafiedPtr pReq
, pPrev
;
142 for (pReq
= pPending
; pReq
; pPrev
= pReq
, pReq
= pReq
->next
)
143 if (pReq
== pRequest
) {
145 pPrev
->next
= pReq
->next
;
147 pPending
= pReq
->next
;
150 if (pRequest
->notifyFunc
)
151 (*pRequest
->notifyFunc
) (pRequest
->pClient
, pRequest
->closure
);
157 SertafiedBlockHandler(pointer data
, OSTimePtr wt
, pointer LastSelectMask
)
159 SertafiedPtr pReq
, pNext
;
165 now
.milliseconds
= GetTimeInMillis();
166 now
.months
= currentTime
.months
;
167 if ((int) (now
.milliseconds
- currentTime
.milliseconds
) < 0)
169 for (pReq
= pPending
; pReq
; pReq
= pNext
) {
171 if (CompareTimeStamps(pReq
->revive
, now
) == LATER
)
173 FreeResource(pReq
->id
, RT_NONE
);
175 /* AttendClient() may have been called via the resource delete
176 * function so a client may have input to be processed and so
177 * set delay to 0 to prevent blocking in WaitForSomething().
179 AdjustWaitForDelay(wt
, 0);
184 delay
= pReq
->revive
.milliseconds
- now
.milliseconds
;
185 AdjustWaitForDelay(wt
, delay
);
189 SertafiedWakeupHandler(pointer data
, int i
, pointer LastSelectMask
)
191 SertafiedPtr pReq
, pNext
;
194 now
.milliseconds
= GetTimeInMillis();
195 now
.months
= currentTime
.months
;
196 if ((int) (now
.milliseconds
- currentTime
.milliseconds
) < 0)
198 for (pReq
= pPending
; pReq
; pReq
= pNext
) {
200 if (CompareTimeStamps(pReq
->revive
, now
) == LATER
)
202 FreeResource(pReq
->id
, RT_NONE
);
205 RemoveBlockAndWakeupHandlers(SertafiedBlockHandler
,
206 SertafiedWakeupHandler
, (pointer
) 0);
207 BlockHandlerRegistered
= FALSE
;