1 /* $XConsortium: sync.h,v 1.6 94/04/17 20:11:26 dpw Exp $ */
4 Copyright (c) 1991, 1993, 1994 X Consortium
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of the X Consortium shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from the X Consortium.
29 /***********************************************************
30 Copyright 1991,1993 by Digital Equipment Corporation, Maynard, Massachusetts,
31 and Olivetti Research Limited, Cambridge, England.
35 Permission to use, copy, modify, and distribute this software and its
36 documentation for any purpose and without fee is hereby granted,
37 provided that the above copyright notice appear in all copies and that
38 both that copyright notice and this permission notice appear in
39 supporting documentation, and that the names of Digital or Olivetti
40 not be used in advertising or publicity pertaining to distribution of the
41 software without specific, written prior permission.
43 DIGITAL AND OLIVETTI DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
44 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
45 FITNESS, IN NO EVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
46 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
47 USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
48 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
49 PERFORMANCE OF THIS SOFTWARE.
51 ******************************************************************/
56 #define SYNC_NAME "SYNC"
58 #define SYNC_MAJOR_VERSION 3
59 #define SYNC_MINOR_VERSION 0
61 #define X_SyncInitialize 0
62 #define X_SyncListSystemCounters 1
63 #define X_SyncCreateCounter 2
64 #define X_SyncSetCounter 3
65 #define X_SyncChangeCounter 4
66 #define X_SyncQueryCounter 5
67 #define X_SyncDestroyCounter 6
69 #define X_SyncCreateAlarm 8
70 #define X_SyncChangeAlarm 9
71 #define X_SyncQueryAlarm 10
72 #define X_SyncDestroyAlarm 11
73 #define X_SyncSetPriority 12
74 #define X_SyncGetPriority 13
76 #define XSyncCounterNotify 0
77 #define XSyncAlarmNotify 1
78 #define XSyncAlarmNotifyMask (1L << XSyncAlarmNotify)
80 #define XSyncNumberEvents 2L
82 #define XSyncBadCounter 0L
83 #define XSyncBadAlarm 1L
84 #define XSyncNumberErrors (XSyncBadAlarm + 1)
87 * Flags for Alarm Attributes
89 #define XSyncCACounter (1L<<0)
90 #define XSyncCAValueType (1L<<1)
91 #define XSyncCAValue (1L<<2)
92 #define XSyncCATestType (1L<<3)
93 #define XSyncCADelta (1L<<4)
94 #define XSyncCAEvents (1L<<5)
97 * Constants for the value_type argument of various requests
108 XSyncPositiveTransition,
109 XSyncNegativeTransition,
110 XSyncPositiveComparison,
111 XSyncNegativeComparison
115 * Alarm state constants
124 typedef XID XSyncCounter;
125 typedef XID XSyncAlarm;
126 typedef struct _XSyncValue {
132 * Macros/functions for manipulating 64 bit values
135 /* have to put these prototypes before the corresponding macro definitions */
137 extern void XSyncIntToValue(
138 #if NeedFunctionPrototypes
144 extern void XSyncIntsToValue(
145 #if NeedFunctionPrototypes
152 extern Bool XSyncValueGreaterThan(
153 #if NeedFunctionPrototypes
159 extern Bool XSyncValueLessThan(
160 #if NeedFunctionPrototypes
166 extern Bool XSyncValueGreaterOrEqual(
167 #if NeedFunctionPrototypes
173 extern Bool XSyncValueLessOrEqual(
174 #if NeedFunctionPrototypes
180 extern Bool XSyncValueEqual(
181 #if NeedFunctionPrototypes
187 extern Bool XSyncValueIsNegative(
188 #if NeedFunctionPrototypes
193 extern Bool XSyncValueIsZero(
194 #if NeedFunctionPrototypes
199 extern Bool XSyncValueIsPositive(
200 #if NeedFunctionPrototypes
205 extern unsigned int XSyncValueLow32(
206 #if NeedFunctionPrototypes
211 extern int XSyncValueHigh32(
212 #if NeedFunctionPrototypes
217 extern void XSyncValueAdd(
218 #if NeedFunctionPrototypes
219 XSyncValue* /*presult*/,
226 extern void XSyncValueSubtract(
227 #if NeedFunctionPrototypes
228 XSyncValue* /*presult*/,
235 extern void XSyncMaxValue(
236 #if NeedFunctionPrototypes
241 extern void XSyncMinValue(
242 #if NeedFunctionPrototypes
247 /* The _XSync macros below are for library internal use only. They exist
248 * so that if we have to make a fix, we can change it in this one place
249 * and have both the macro and function variants inherit the fix.
252 #define _XSyncIntToValue(pv, i) ((pv)->hi=((i<0)?~0:0),(pv)->lo=(i))
253 #define _XSyncIntsToValue(pv, l, h) ((pv)->lo = (l), (pv)->hi = (h))
254 #define _XSyncValueGreaterThan(a, b)\
255 ((a).hi>(b).hi || ((a).hi==(b).hi && (a).lo>(b).lo))
256 #define _XSyncValueLessThan(a, b)\
257 ((a).hi<(b).hi || ((a).hi==(b).hi && (a).lo<(b).lo))
258 #define _XSyncValueGreaterOrEqual(a, b)\
259 ((a).hi>(b).hi || ((a).hi==(b).hi && (a).lo>=(b).lo))
260 #define _XSyncValueLessOrEqual(a, b)\
261 ((a).hi<(b).hi || ((a).hi==(b).hi && (a).lo<=(b).lo))
262 #define _XSyncValueEqual(a, b) ((a).lo==(b).lo && (a).hi==(b).hi)
263 #define _XSyncValueIsNegative(v) (((v).hi & 0x80000000) ? 1 : 0)
264 #define _XSyncValueIsZero(a) ((a).lo==0 && (a).hi==0)
265 #define _XSyncValueIsPositive(v) (((v).hi & 0x80000000) ? 0 : 1)
266 #define _XSyncValueLow32(v) ((v).lo)
267 #define _XSyncValueHigh32(v) ((v).hi)
268 #define _XSyncValueAdd(presult,a,b,poverflow) {\
270 Bool signa = XSyncValueIsNegative(a);\
271 Bool signb = XSyncValueIsNegative(b);\
272 ((presult)->lo = (a).lo + (b).lo);\
273 ((presult)->hi = (a).hi + (b).hi);\
274 if (t>(presult)->lo) (presult)->hi++;\
275 *poverflow = ((signa == signb) && !(signa == XSyncValueIsNegative(*presult)));\
277 #define _XSyncValueSubtract(presult,a,b,poverflow) {\
279 Bool signa = XSyncValueIsNegative(a);\
280 Bool signb = XSyncValueIsNegative(b);\
281 ((presult)->lo = (a).lo - (b).lo);\
282 ((presult)->hi = (a).hi - (b).hi);\
283 if (t>(presult)->lo) (presult)->hi--;\
284 *poverflow = ((signa == signb) && !(signa == XSyncValueIsNegative(*presult)));\
286 #define _XSyncMaxValue(pv) ((pv)->hi = 0x7fffffff, (pv)->lo = 0xffffffff)
287 #define _XSyncMinValue(pv) ((pv)->hi = 0x80000000, (pv)->lo = 0)
290 * These are the publically usable macros. If you want the function version
291 * of one of these, just #undef the macro to uncover the function.
292 * (This is the same convention that the ANSI C library uses.)
295 #define XSyncIntToValue(pv, i) _XSyncIntToValue(pv, i)
296 #define XSyncIntsToValue(pv, l, h) _XSyncIntsToValue(pv, l, h)
297 #define XSyncValueGreaterThan(a, b) _XSyncValueGreaterThan(a, b)
298 #define XSyncValueLessThan(a, b) _XSyncValueLessThan(a, b)
299 #define XSyncValueGreaterOrEqual(a, b) _XSyncValueGreaterOrEqual(a, b)
300 #define XSyncValueLessOrEqual(a, b) _XSyncValueLessOrEqual(a, b)
301 #define XSyncValueEqual(a, b) _XSyncValueEqual(a, b)
302 #define XSyncValueIsNegative(v) _XSyncValueIsNegative(v)
303 #define XSyncValueIsZero(a) _XSyncValueIsZero(a)
304 #define XSyncValueIsPositive(v) _XSyncValueIsPositive(v)
305 #define XSyncValueLow32(v) _XSyncValueLow32(v)
306 #define XSyncValueHigh32(v) _XSyncValueHigh32(v)
307 #define XSyncValueAdd(presult,a,b,poverflow) _XSyncValueAdd(presult,a,b,poverflow)
308 #define XSyncValueSubtract(presult,a,b,poverflow) _XSyncValueSubtract(presult,a,b,poverflow)
309 #define XSyncMaxValue(pv) _XSyncMaxValue(pv)
310 #define XSyncMinValue(pv) _XSyncMinValue(pv)
314 typedef struct _XSyncSystemCounter {
315 char *name; /* null-terminated name of system counter */
316 XSyncCounter counter; /* counter id of this system counter */
317 XSyncValue resolution; /* resolution of this system counter */
318 } XSyncSystemCounter;
322 XSyncCounter counter; /* counter to trigger on */
323 XSyncValueType value_type; /* absolute/relative */
324 XSyncValue wait_value; /* value to compare counter to */
325 XSyncTestType test_type; /* pos/neg comparison/transtion */
329 XSyncTrigger trigger; /* trigger for await */
330 XSyncValue event_threshold; /* send event if past threshold */
331 } XSyncWaitCondition;
335 XSyncTrigger trigger;
338 XSyncAlarmState state;
339 } XSyncAlarmAttributes;
346 int type; /* event base + XSyncCounterNotify */
347 unsigned long serial; /* # of last request processed by server */
348 Bool send_event; /* true if this came from a SendEvent request */
349 Display *display; /* Display the event was read from */
350 XSyncCounter counter; /* counter involved in await */
351 XSyncValue wait_value; /* value being waited for */
352 XSyncValue counter_value; /* counter value when this event was sent */
353 Time time; /* milliseconds */
354 int count; /* how many more events to come */
355 Bool destroyed; /* True if counter was destroyed */
356 } XSyncCounterNotifyEvent;
359 int type; /* event base + XSyncCounterNotify */
360 unsigned long serial; /* # of last request processed by server */
361 Bool send_event; /* true if this came from a SendEvent request */
362 Display *display; /* Display the event was read from */
363 XSyncAlarm alarm; /* alarm that triggered */
364 XSyncValue counter_value; /* value that triggered the alarm */
365 XSyncValue alarm_value; /* test value of trigger in alarm */
366 Time time; /* milliseconds */
367 XSyncAlarmState state; /* new state of alarm */
368 } XSyncAlarmNotifyEvent;
376 Display *display; /* Display the event was read from */
377 XSyncAlarm alarm; /* resource id */
378 unsigned long serial; /* serial number of failed request */
379 unsigned char error_code; /* error base + XSyncBadAlarm */
380 unsigned char request_code; /* Major op-code of failed request */
381 unsigned char minor_code; /* Minor op-code of failed request */
386 Display *display; /* Display the event was read from */
387 XSyncCounter counter; /* resource id */
388 unsigned long serial; /* serial number of failed request */
389 unsigned char error_code; /* error base + XSyncBadCounter */
390 unsigned char request_code; /* Major op-code of failed request */
391 unsigned char minor_code; /* Minor op-code of failed request */
398 extern Status XSyncQueryExtension(
399 #if NeedFunctionPrototypes
401 int* /*event_base_return*/,
402 int* /*error_base_return*/
406 extern Status XSyncInitialize(
407 #if NeedFunctionPrototypes
409 int* /*major_version_return*/,
410 int* /*minor_version_return*/
414 extern XSyncSystemCounter *XSyncListSystemCounters(
415 #if NeedFunctionPrototypes
417 int* /*n_counters_return*/
421 extern void XSyncFreeSystemCounterList(
422 #if NeedFunctionPrototypes
423 XSyncSystemCounter* /*list*/
427 extern XSyncCounter XSyncCreateCounter(
428 #if NeedFunctionPrototypes
430 XSyncValue /*initial_value*/
434 extern Status XSyncSetCounter(
435 #if NeedFunctionPrototypes
437 XSyncCounter /*counter*/,
442 extern Status XSyncChangeCounter(
443 #if NeedFunctionPrototypes
445 XSyncCounter /*counter*/,
450 extern Status XSyncDestroyCounter(
451 #if NeedFunctionPrototypes
453 XSyncCounter /*counter*/
457 extern Status XSyncQueryCounter(
458 #if NeedFunctionPrototypes
460 XSyncCounter /*counter*/,
461 XSyncValue* /*value_return*/
465 extern Status XSyncAwait(
466 #if NeedFunctionPrototypes
468 XSyncWaitCondition* /*wait_list*/,
473 extern XSyncAlarm XSyncCreateAlarm(
474 #if NeedFunctionPrototypes
476 unsigned long /*values_mask*/,
477 XSyncAlarmAttributes* /*values*/
481 extern Status XSyncDestroyAlarm(
482 #if NeedFunctionPrototypes
488 extern Status XSyncQueryAlarm(
489 #if NeedFunctionPrototypes
491 XSyncAlarm /*alarm*/,
492 XSyncAlarmAttributes* /*values_return*/
496 extern Status XSyncChangeAlarm(
497 #if NeedFunctionPrototypes
499 XSyncAlarm /*alarm*/,
500 unsigned long /*values_mask*/,
501 XSyncAlarmAttributes* /*values*/
505 extern Status XSyncSetPriority(
506 #if NeedFunctionPrototypes
508 XID /*client_resource_id*/,
513 extern Status XSyncGetPriority(
514 #if NeedFunctionPrototypes
516 XID /*client_resource_id*/,
517 int* /*return_priority*/
521 #endif /* _SYNC_SERVER */
523 #endif /* _SYNC_H_ */