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 #include <dix-config.h>
32 #include "sleepuntil.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
;
46 void (*notifyFunc
) (ClientPtr
/* client */ ,
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 */ ,
61 static int SertafiedDelete(void * /* value */ ,
64 static void SertafiedBlockHandler(void *data
,
67 static void SertafiedWakeupHandler(void *data
,
71 ClientSleepUntil(ClientPtr client
,
73 void (*notifyFunc
) (ClientPtr
, void *), void *closure
)
75 SertafiedPtr pRequest
, pReq
, pPrev
;
77 if (SertafiedGeneration
!= serverGeneration
) {
78 SertafiedResType
= CreateNewResourceType(SertafiedDelete
,
80 if (!SertafiedResType
)
82 SertafiedGeneration
= serverGeneration
;
83 BlockHandlerRegistered
= FALSE
;
85 pRequest
= malloc(sizeof(SertafiedRec
));
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
,
99 BlockHandlerRegistered
= TRUE
;
101 pRequest
->notifyFunc
= 0;
102 if (!AddResource(pRequest
->id
, SertafiedResType
, (void *) pRequest
))
105 notifyFunc
= ClientAwaken
;
106 pRequest
->notifyFunc
= notifyFunc
;
107 /* Insert into time-ordered queue, with earliest activation time coming first. */
109 for (pReq
= pPending
; pReq
; pReq
= pReq
->next
) {
110 if (CompareTimeStamps(pReq
->revive
, *revive
) == LATER
)
115 pPrev
->next
= pRequest
;
118 pRequest
->next
= pReq
;
119 IgnoreClient(client
);
124 ClientAwaken(ClientPtr client
, void *closure
)
126 AttendClient(client
);
130 SertafiedDelete(void *value
, XID id
)
132 SertafiedPtr pRequest
= (SertafiedPtr
) value
;
133 SertafiedPtr pReq
, pPrev
;
136 for (pReq
= pPending
; pReq
; pPrev
= pReq
, pReq
= pReq
->next
)
137 if (pReq
== pRequest
) {
139 pPrev
->next
= pReq
->next
;
141 pPending
= pReq
->next
;
144 if (pRequest
->notifyFunc
)
145 (*pRequest
->notifyFunc
) (pRequest
->pClient
, pRequest
->closure
);
151 SertafiedBlockHandler(void *data
, void *wt
)
153 SertafiedPtr pReq
, pNext
;
159 now
.milliseconds
= GetTimeInMillis();
160 now
.months
= currentTime
.months
;
161 if ((int) (now
.milliseconds
- currentTime
.milliseconds
) < 0)
163 for (pReq
= pPending
; pReq
; pReq
= pNext
) {
165 if (CompareTimeStamps(pReq
->revive
, now
) == LATER
)
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);
178 delay
= pReq
->revive
.milliseconds
- now
.milliseconds
;
179 AdjustWaitForDelay(wt
, delay
);
183 SertafiedWakeupHandler(void *data
, int i
)
185 SertafiedPtr pReq
, pNext
;
188 now
.milliseconds
= GetTimeInMillis();
189 now
.months
= currentTime
.months
;
190 if ((int) (now
.milliseconds
- currentTime
.milliseconds
) < 0)
192 for (pReq
= pPending
; pReq
; pReq
= pNext
) {
194 if (CompareTimeStamps(pReq
->revive
, now
) == LATER
)
196 FreeResource(pReq
->id
, X11_RESTYPE_NONE
);
199 RemoveBlockAndWakeupHandlers(SertafiedBlockHandler
,
200 SertafiedWakeupHandler
, (void *) 0);
201 BlockHandlerRegistered
= FALSE
;