1 /* $Xorg: sync.h,v 1.4 2001/02/09 02:03:24 xorgcvs Exp $ */
4 Copyright 1991, 1993, 1994, 1998 The Open Group
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from The Open Group.
28 /***********************************************************
29 Copyright 1991,1993 by Digital Equipment Corporation, Maynard, Massachusetts,
30 and Olivetti Research Limited, Cambridge, England.
34 Permission to use, copy, modify, and distribute this software and its
35 documentation for any purpose and without fee is hereby granted,
36 provided that the above copyright notice appear in all copies and that
37 both that copyright notice and this permission notice appear in
38 supporting documentation, and that the names of Digital or Olivetti
39 not be used in advertising or publicity pertaining to distribution of the
40 software without specific, written prior permission.
42 DIGITAL AND OLIVETTI DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
43 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
44 FITNESS, IN NO EVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
45 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
46 USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
47 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
48 PERFORMANCE OF THIS SOFTWARE.
50 ******************************************************************/
51 /* $XFree86: xc/include/extensions/sync.h,v 1.4 2001/12/20 19:40:59 tsi Exp $ */
56 #include <X11/Xfuncproto.h>
60 #define SYNC_NAME "SYNC"
62 #define SYNC_MAJOR_VERSION 3
63 #define SYNC_MINOR_VERSION 0
65 #define X_SyncInitialize 0
66 #define X_SyncListSystemCounters 1
67 #define X_SyncCreateCounter 2
68 #define X_SyncSetCounter 3
69 #define X_SyncChangeCounter 4
70 #define X_SyncQueryCounter 5
71 #define X_SyncDestroyCounter 6
73 #define X_SyncCreateAlarm 8
74 #define X_SyncChangeAlarm 9
75 #define X_SyncQueryAlarm 10
76 #define X_SyncDestroyAlarm 11
77 #define X_SyncSetPriority 12
78 #define X_SyncGetPriority 13
80 #define XSyncCounterNotify 0
81 #define XSyncAlarmNotify 1
82 #define XSyncAlarmNotifyMask (1L << XSyncAlarmNotify)
84 #define XSyncNumberEvents 2L
86 #define XSyncBadCounter 0L
87 #define XSyncBadAlarm 1L
88 #define XSyncNumberErrors (XSyncBadAlarm + 1)
91 * Flags for Alarm Attributes
93 #define XSyncCACounter (1L<<0)
94 #define XSyncCAValueType (1L<<1)
95 #define XSyncCAValue (1L<<2)
96 #define XSyncCATestType (1L<<3)
97 #define XSyncCADelta (1L<<4)
98 #define XSyncCAEvents (1L<<5)
101 * Constants for the value_type argument of various requests
112 XSyncPositiveTransition
,
113 XSyncNegativeTransition
,
114 XSyncPositiveComparison
,
115 XSyncNegativeComparison
119 * Alarm state constants
128 typedef XID XSyncCounter
;
129 typedef XID XSyncAlarm
;
130 typedef struct _XSyncValue
{
136 * Macros/functions for manipulating 64 bit values
139 /* have to put these prototypes before the corresponding macro definitions */
141 extern void XSyncIntToValue(
146 extern void XSyncIntsToValue(
152 extern Bool
XSyncValueGreaterThan(
157 extern Bool
XSyncValueLessThan(
162 extern Bool
XSyncValueGreaterOrEqual(
167 extern Bool
XSyncValueLessOrEqual(
172 extern Bool
XSyncValueEqual(
177 extern Bool
XSyncValueIsNegative(
181 extern Bool
XSyncValueIsZero(
185 extern Bool
XSyncValueIsPositive(
189 extern unsigned int XSyncValueLow32(
193 extern int XSyncValueHigh32(
197 extern void XSyncValueAdd(
198 XSyncValue
* /*presult*/,
204 extern void XSyncValueSubtract(
205 XSyncValue
* /*presult*/,
211 extern void XSyncMaxValue(
215 extern void XSyncMinValue(
221 /* The _XSync macros below are for library internal use only. They exist
222 * so that if we have to make a fix, we can change it in this one place
223 * and have both the macro and function variants inherit the fix.
226 #define _XSyncIntToValue(pv, i) ((pv)->hi=((i<0)?~0:0),(pv)->lo=(i))
227 #define _XSyncIntsToValue(pv, l, h) ((pv)->lo = (l), (pv)->hi = (h))
228 #define _XSyncValueGreaterThan(a, b)\
229 ((a).hi>(b).hi || ((a).hi==(b).hi && (a).lo>(b).lo))
230 #define _XSyncValueLessThan(a, b)\
231 ((a).hi<(b).hi || ((a).hi==(b).hi && (a).lo<(b).lo))
232 #define _XSyncValueGreaterOrEqual(a, b)\
233 ((a).hi>(b).hi || ((a).hi==(b).hi && (a).lo>=(b).lo))
234 #define _XSyncValueLessOrEqual(a, b)\
235 ((a).hi<(b).hi || ((a).hi==(b).hi && (a).lo<=(b).lo))
236 #define _XSyncValueEqual(a, b) ((a).lo==(b).lo && (a).hi==(b).hi)
237 #define _XSyncValueIsNegative(v) (((v).hi & 0x80000000) ? 1 : 0)
238 #define _XSyncValueIsZero(a) ((a).lo==0 && (a).hi==0)
239 #define _XSyncValueIsPositive(v) (((v).hi & 0x80000000) ? 0 : 1)
240 #define _XSyncValueLow32(v) ((v).lo)
241 #define _XSyncValueHigh32(v) ((v).hi)
242 #define _XSyncValueAdd(presult,a,b,poverflow) {\
244 Bool signa = XSyncValueIsNegative(a);\
245 Bool signb = XSyncValueIsNegative(b);\
246 ((presult)->lo = (a).lo + (b).lo);\
247 ((presult)->hi = (a).hi + (b).hi);\
248 if (t>(presult)->lo) (presult)->hi++;\
249 *poverflow = ((signa == signb) && !(signa == XSyncValueIsNegative(*presult)));\
251 #define _XSyncValueSubtract(presult,a,b,poverflow) {\
253 Bool signa = XSyncValueIsNegative(a);\
254 Bool signb = XSyncValueIsNegative(b);\
255 ((presult)->lo = (a).lo - (b).lo);\
256 ((presult)->hi = (a).hi - (b).hi);\
257 if (t>(presult)->lo) (presult)->hi--;\
258 *poverflow = ((signa == signb) && !(signa == XSyncValueIsNegative(*presult)));\
260 #define _XSyncMaxValue(pv) ((pv)->hi = 0x7fffffff, (pv)->lo = 0xffffffff)
261 #define _XSyncMinValue(pv) ((pv)->hi = 0x80000000, (pv)->lo = 0)
264 * These are the publically usable macros. If you want the function version
265 * of one of these, just #undef the macro to uncover the function.
266 * (This is the same convention that the ANSI C library uses.)
269 #define XSyncIntToValue(pv, i) _XSyncIntToValue(pv, i)
270 #define XSyncIntsToValue(pv, l, h) _XSyncIntsToValue(pv, l, h)
271 #define XSyncValueGreaterThan(a, b) _XSyncValueGreaterThan(a, b)
272 #define XSyncValueLessThan(a, b) _XSyncValueLessThan(a, b)
273 #define XSyncValueGreaterOrEqual(a, b) _XSyncValueGreaterOrEqual(a, b)
274 #define XSyncValueLessOrEqual(a, b) _XSyncValueLessOrEqual(a, b)
275 #define XSyncValueEqual(a, b) _XSyncValueEqual(a, b)
276 #define XSyncValueIsNegative(v) _XSyncValueIsNegative(v)
277 #define XSyncValueIsZero(a) _XSyncValueIsZero(a)
278 #define XSyncValueIsPositive(v) _XSyncValueIsPositive(v)
279 #define XSyncValueLow32(v) _XSyncValueLow32(v)
280 #define XSyncValueHigh32(v) _XSyncValueHigh32(v)
281 #define XSyncValueAdd(presult,a,b,poverflow) _XSyncValueAdd(presult,a,b,poverflow)
282 #define XSyncValueSubtract(presult,a,b,poverflow) _XSyncValueSubtract(presult,a,b,poverflow)
283 #define XSyncMaxValue(pv) _XSyncMaxValue(pv)
284 #define XSyncMinValue(pv) _XSyncMinValue(pv)
288 typedef struct _XSyncSystemCounter
{
289 char *name
; /* null-terminated name of system counter */
290 XSyncCounter counter
; /* counter id of this system counter */
291 XSyncValue resolution
; /* resolution of this system counter */
292 } XSyncSystemCounter
;
296 XSyncCounter counter
; /* counter to trigger on */
297 XSyncValueType value_type
; /* absolute/relative */
298 XSyncValue wait_value
; /* value to compare counter to */
299 XSyncTestType test_type
; /* pos/neg comparison/transtion */
303 XSyncTrigger trigger
; /* trigger for await */
304 XSyncValue event_threshold
; /* send event if past threshold */
305 } XSyncWaitCondition
;
309 XSyncTrigger trigger
;
312 XSyncAlarmState state
;
313 } XSyncAlarmAttributes
;
320 int type
; /* event base + XSyncCounterNotify */
321 unsigned long serial
; /* # of last request processed by server */
322 Bool send_event
; /* true if this came from a SendEvent request */
323 Display
*display
; /* Display the event was read from */
324 XSyncCounter counter
; /* counter involved in await */
325 XSyncValue wait_value
; /* value being waited for */
326 XSyncValue counter_value
; /* counter value when this event was sent */
327 Time time
; /* milliseconds */
328 int count
; /* how many more events to come */
329 Bool destroyed
; /* True if counter was destroyed */
330 } XSyncCounterNotifyEvent
;
333 int type
; /* event base + XSyncCounterNotify */
334 unsigned long serial
; /* # of last request processed by server */
335 Bool send_event
; /* true if this came from a SendEvent request */
336 Display
*display
; /* Display the event was read from */
337 XSyncAlarm alarm
; /* alarm that triggered */
338 XSyncValue counter_value
; /* value that triggered the alarm */
339 XSyncValue alarm_value
; /* test value of trigger in alarm */
340 Time time
; /* milliseconds */
341 XSyncAlarmState state
; /* new state of alarm */
342 } XSyncAlarmNotifyEvent
;
350 Display
*display
; /* Display the event was read from */
351 XSyncAlarm alarm
; /* resource id */
352 unsigned long serial
; /* serial number of failed request */
353 unsigned char error_code
; /* error base + XSyncBadAlarm */
354 unsigned char request_code
; /* Major op-code of failed request */
355 unsigned char minor_code
; /* Minor op-code of failed request */
360 Display
*display
; /* Display the event was read from */
361 XSyncCounter counter
; /* resource id */
362 unsigned long serial
; /* serial number of failed request */
363 unsigned char error_code
; /* error base + XSyncBadCounter */
364 unsigned char request_code
; /* Major op-code of failed request */
365 unsigned char minor_code
; /* Minor op-code of failed request */
374 extern Status
XSyncQueryExtension(
376 int* /*event_base_return*/,
377 int* /*error_base_return*/
380 extern Status
XSyncInitialize(
382 int* /*major_version_return*/,
383 int* /*minor_version_return*/
386 extern XSyncSystemCounter
*XSyncListSystemCounters(
388 int* /*n_counters_return*/
391 extern void XSyncFreeSystemCounterList(
392 XSyncSystemCounter
* /*list*/
395 extern XSyncCounter
XSyncCreateCounter(
397 XSyncValue
/*initial_value*/
400 extern Status
XSyncSetCounter(
402 XSyncCounter
/*counter*/,
406 extern Status
XSyncChangeCounter(
408 XSyncCounter
/*counter*/,
412 extern Status
XSyncDestroyCounter(
414 XSyncCounter
/*counter*/
417 extern Status
XSyncQueryCounter(
419 XSyncCounter
/*counter*/,
420 XSyncValue
* /*value_return*/
423 extern Status
XSyncAwait(
425 XSyncWaitCondition
* /*wait_list*/,
429 extern XSyncAlarm
XSyncCreateAlarm(
431 unsigned long /*values_mask*/,
432 XSyncAlarmAttributes
* /*values*/
435 extern Status
XSyncDestroyAlarm(
440 extern Status
XSyncQueryAlarm(
442 XSyncAlarm
/*alarm*/,
443 XSyncAlarmAttributes
* /*values_return*/
446 extern Status
XSyncChangeAlarm(
448 XSyncAlarm
/*alarm*/,
449 unsigned long /*values_mask*/,
450 XSyncAlarmAttributes
* /*values*/
453 extern Status
XSyncSetPriority(
455 XID
/*client_resource_id*/,
459 extern Status
XSyncGetPriority(
461 XID
/*client_resource_id*/,
462 int* /*return_priority*/
465 #endif /* _SYNC_SERVER */
469 #endif /* _SYNC_H_ */