1 /* $Xorg: sync.h,v 1.4 2001/02/09 02:03:24 xorgcvs Exp $ */ 2 /* 3 4 Copyright 1991, 1993, 1994, 1998 The Open Group 5 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 10 documentation. 11 12 The above copyright notice and this permission notice shall be included in 13 all copies or substantial portions of the Software. 14 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. 21 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. 25 26 */ 27 28 /*********************************************************** 29 Copyright 1991,1993 by Digital Equipment Corporation, Maynard, Massachusetts, 30 and Olivetti Research Limited, Cambridge, England. 31 32 All Rights Reserved 33 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. 41 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. 49 50 ******************************************************************/ 51 /* $XFree86: xc/include/extensions/sync.h,v 1.4 2001/12/20 19:40:59 tsi Exp $ */ 52 53 #ifndef _SYNC_H_ 54 #define _SYNC_H_ 55 56 #include <X11/Xfuncproto.h> 57 58 _XFUNCPROTOBEGIN 59 60 #define SYNC_NAME "SYNC" 61 62 #define SYNC_MAJOR_VERSION 3 63 #define SYNC_MINOR_VERSION 0 64 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 72 #define X_SyncAwait 7 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 79 80 #define XSyncCounterNotify 0 81 #define XSyncAlarmNotify 1 82 #define XSyncAlarmNotifyMask (1L << XSyncAlarmNotify) 83 84 #define XSyncNumberEvents 2L 85 86 #define XSyncBadCounter 0L 87 #define XSyncBadAlarm 1L 88 #define XSyncNumberErrors (XSyncBadAlarm + 1) 89 90 /* 91 * Flags for Alarm Attributes 92 */ 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) 99 100 /* 101 * Constants for the value_type argument of various requests 102 */ 103 typedef enum { 104 XSyncAbsolute, 105 XSyncRelative 106 } XSyncValueType; 107 108 /* 109 * Alarm Test types 110 */ 111 typedef enum { 112 XSyncPositiveTransition, 113 XSyncNegativeTransition, 114 XSyncPositiveComparison, 115 XSyncNegativeComparison 116 } XSyncTestType; 117 118 /* 119 * Alarm state constants 120 */ 121 typedef enum { 122 XSyncAlarmActive, 123 XSyncAlarmInactive, 124 XSyncAlarmDestroyed 125 } XSyncAlarmState; 126 127 128 typedef XID XSyncCounter; 129 typedef XID XSyncAlarm; 130 typedef struct _XSyncValue { 131 int hi; 132 unsigned int lo; 133 } XSyncValue; 134 135 /* 136 * Macros/functions for manipulating 64 bit values 137 */ 138 139 /* have to put these prototypes before the corresponding macro definitions */ 140 141 extern void XSyncIntToValue( 142 XSyncValue* /*pv*/, 143 int /*i*/ 144 ); 145 146 extern void XSyncIntsToValue( 147 XSyncValue* /*pv*/, 148 unsigned int /*l*/, 149 int /*h*/ 150 ); 151 152 extern Bool XSyncValueGreaterThan( 153 XSyncValue /*a*/, 154 XSyncValue /*b*/ 155 ); 156 157 extern Bool XSyncValueLessThan( 158 XSyncValue /*a*/, 159 XSyncValue /*b*/ 160 ); 161 162 extern Bool XSyncValueGreaterOrEqual( 163 XSyncValue /*a*/, 164 XSyncValue /*b*/ 165 ); 166 167 extern Bool XSyncValueLessOrEqual( 168 XSyncValue /*a*/, 169 XSyncValue /*b*/ 170 ); 171 172 extern Bool XSyncValueEqual( 173 XSyncValue /*a*/, 174 XSyncValue /*b*/ 175 ); 176 177 extern Bool XSyncValueIsNegative( 178 XSyncValue /*v*/ 179 ); 180 181 extern Bool XSyncValueIsZero( 182 XSyncValue /*a*/ 183 ); 184 185 extern Bool XSyncValueIsPositive( 186 XSyncValue /*v*/ 187 ); 188 189 extern unsigned int XSyncValueLow32( 190 XSyncValue /*v*/ 191 ); 192 193 extern int XSyncValueHigh32( 194 XSyncValue /*v*/ 195 ); 196 197 extern void XSyncValueAdd( 198 XSyncValue* /*presult*/, 199 XSyncValue /*a*/, 200 XSyncValue /*b*/, 201 int* /*poverflow*/ 202 ); 203 204 extern void XSyncValueSubtract( 205 XSyncValue* /*presult*/, 206 XSyncValue /*a*/, 207 XSyncValue /*b*/, 208 int* /*poverflow*/ 209 ); 210 211 extern void XSyncMaxValue( 212 XSyncValue* /*pv*/ 213 ); 214 215 extern void XSyncMinValue( 216 XSyncValue* /*pv*/ 217 ); 218 219 _XFUNCPROTOEND 220 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. 224 */ 225 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) {\ 243 int t = (a).lo;\ 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)));\ 250 } 251 #define _XSyncValueSubtract(presult,a,b,poverflow) {\ 252 int t = (a).lo;\ 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)));\ 259 } 260 #define _XSyncMaxValue(pv) ((pv)->hi = 0x7fffffff, (pv)->lo = 0xffffffff) 261 #define _XSyncMinValue(pv) ((pv)->hi = 0x80000000, (pv)->lo = 0) 262 263 /* 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.) 267 */ 268 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) 285 286 #ifndef _SYNC_SERVER 287 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; 293 294 295 typedef struct { 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 */ 300 } XSyncTrigger; 301 302 typedef struct { 303 XSyncTrigger trigger; /* trigger for await */ 304 XSyncValue event_threshold; /* send event if past threshold */ 305 } XSyncWaitCondition; 306 307 308 typedef struct { 309 XSyncTrigger trigger; 310 XSyncValue delta; 311 Bool events; 312 XSyncAlarmState state; 313 } XSyncAlarmAttributes; 314 315 /* 316 * Events 317 */ 318 319 typedef struct { 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; 331 332 typedef struct { 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; 343 344 /* 345 * Errors 346 */ 347 348 typedef struct { 349 int type; 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 */ 356 } XSyncAlarmError; 357 358 typedef struct { 359 int type; 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 */ 366 } XSyncCounterError; 367 368 /* 369 * Prototypes 370 */ 371 372 _XFUNCPROTOBEGIN 373 374 extern Status XSyncQueryExtension( 375 Display* /*dpy*/, 376 int* /*event_base_return*/, 377 int* /*error_base_return*/ 378 ); 379 380 extern Status XSyncInitialize( 381 Display* /*dpy*/, 382 int* /*major_version_return*/, 383 int* /*minor_version_return*/ 384 ); 385 386 extern XSyncSystemCounter *XSyncListSystemCounters( 387 Display* /*dpy*/, 388 int* /*n_counters_return*/ 389 ); 390 391 extern void XSyncFreeSystemCounterList( 392 XSyncSystemCounter* /*list*/ 393 ); 394 395 extern XSyncCounter XSyncCreateCounter( 396 Display* /*dpy*/, 397 XSyncValue /*initial_value*/ 398 ); 399 400 extern Status XSyncSetCounter( 401 Display* /*dpy*/, 402 XSyncCounter /*counter*/, 403 XSyncValue /*value*/ 404 ); 405 406 extern Status XSyncChangeCounter( 407 Display* /*dpy*/, 408 XSyncCounter /*counter*/, 409 XSyncValue /*value*/ 410 ); 411 412 extern Status XSyncDestroyCounter( 413 Display* /*dpy*/, 414 XSyncCounter /*counter*/ 415 ); 416 417 extern Status XSyncQueryCounter( 418 Display* /*dpy*/, 419 XSyncCounter /*counter*/, 420 XSyncValue* /*value_return*/ 421 ); 422 423 extern Status XSyncAwait( 424 Display* /*dpy*/, 425 XSyncWaitCondition* /*wait_list*/, 426 int /*n_conditions*/ 427 ); 428 429 extern XSyncAlarm XSyncCreateAlarm( 430 Display* /*dpy*/, 431 unsigned long /*values_mask*/, 432 XSyncAlarmAttributes* /*values*/ 433 ); 434 435 extern Status XSyncDestroyAlarm( 436 Display* /*dpy*/, 437 XSyncAlarm /*alarm*/ 438 ); 439 440 extern Status XSyncQueryAlarm( 441 Display* /*dpy*/, 442 XSyncAlarm /*alarm*/, 443 XSyncAlarmAttributes* /*values_return*/ 444 ); 445 446 extern Status XSyncChangeAlarm( 447 Display* /*dpy*/, 448 XSyncAlarm /*alarm*/, 449 unsigned long /*values_mask*/, 450 XSyncAlarmAttributes* /*values*/ 451 ); 452 453 extern Status XSyncSetPriority( 454 Display* /*dpy*/, 455 XID /*client_resource_id*/, 456 int /*priority*/ 457 ); 458 459 extern Status XSyncGetPriority( 460 Display* /*dpy*/, 461 XID /*client_resource_id*/, 462 int* /*return_priority*/ 463 ); 464 465 #endif /* _SYNC_SERVER */ 466 467 _XFUNCPROTOEND 468 469 #endif /* _SYNC_H_ */ 470