Git init
[framework/uifw/xorg/proto/x11proto-xext.git] / specs / sync.xml
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3                    "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
4
5 <!--translated from sync.tex, on 2010-06-29 10:52:00,
6 by TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/) xhtml,docbook,html,refcaption -->
7
8
9 <book id="sync">
10
11 <bookinfo>
12    <title>X Synchronization Extention Protocol</title>
13    <subtitle>X Consortium Standard</subtitle>
14    <releaseinfo>X Version 11, Release 6.6.84</releaseinfo>
15    <authorgroup>
16      <author>
17        <firstname>Tim</firstname><surname>Glauert</surname>
18        <affiliation><orgname>Olivetti Research/MultiWorks</orgname></affiliation>
19      </author>
20      <othercredit>
21         <firstname>Dave</firstname>
22         <surname>Carver</surname>
23         <affiliation><orgname>Digital EquipmentCorporation, MIT/Project Athena</orgname></affiliation>
24      </othercredit>
25      <othercredit>
26        <firstname>Jim</firstname>
27        <surname>Gettys</surname>
28        <affiliation><orgname>Digital EquipmentCorporation, Cambridge Research Laboratory</orgname></affiliation>
29      </othercredit>
30      <othercredit>
31        <firstname>David</firstname>
32        <surname>Wiggins</surname>
33        <affiliation><orgname>X Consortium, Inc.</orgname></affiliation>
34      </othercredit>
35    </authorgroup>
36    <corpname>X Consortium Standard</corpname>
37
38    <copyright>
39      <year>1991</year>
40        <holder>
41 Olivetti Research Limited, Cambridge England and
42 Digital Equipment Corporation, Maynard, Massachusetts
43        </holder>
44    </copyright>
45    <copyright><year>1991</year><holder>X Consortium</holder></copyright>
46
47    <releaseinfo>Version 3.0</releaseinfo>
48    <affiliation><orgname>X Consortium</orgname></affiliation>
49    <productnumber>X Version 11, Release 6.8</productnumber>
50
51 <legalnotice>
52 <para>
53 Permission to use, copy, modify, and distribute this documentation for any
54 purpose and without fee is hereby granted, provided that the above
55 copyright notice appear in all copies. Olivetti, Digital, MIT, and the
56 X Consortium make no representations about the suitability for any purpose
57 of the information in this document. This documentation is provided as
58 is without express or implied warranty.
59 </para>
60
61 <para>
62 Permission is hereby granted, free of charge, to any person obtaining
63 a copy of this software and associated documentation files
64 (the "Software"), to deal in the Software without
65 restriction, including without limitation the rights to use, copy,
66 modify, merge, publish, distribute, sublicense, and/or sell copies of
67 the Software, and to permit persons to whom the Software is furnished
68 to do so, subject to the following conditions:
69 </para>
70
71 <para>The above copyright notice and this permission notice shall be included
72 in all copies or substantial portions of the Software.</para>
73
74 <para>THE SOFTWARE IS PROVIDED &ldquo;AS IS&rdquo;, WITHOUT WARRANTY OF ANY
75 KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
76 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO
77 EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
78 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
79 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
80 SOFTWARE.</para>
81
82 <para>Except as contained in this notice, the name of the X Consortium shall
83 not be used in advertising or otherwise to promote the sale, use or other
84 dealings in this Software without prior written authorization from the X
85 Consortium.</para>
86 </legalnotice>
87
88 </bookinfo>
89
90 <chapter id="synchronization_protocol">
91 <title>Synchronization Protocol</title>
92 <para>
93 The core X protocol makes no guarantees about the relative order of execution
94 of requests for different clients. This means that any synchronization between
95 clients must be done at the client level in an operating system-dependent and
96 network-dependent manner. Even if there was an accepted standard for such
97 synchronization, the use of a network introduces unpredictable delays between
98 the synchronization of the clients and the delivery of the resulting requests
99 to the X server.
100 </para>
101
102 <para>
103 The core X protocol also makes no guarantees about the time at which requests
104 are executed, which means that all clients with real-time constraints must
105 implement their timing on the host computer. Any such timings are subject to
106 error introduced by delays within the operating system and network and are
107 inefficient because of the need for round-trip requests that keep the client
108 and server synchronized.
109 </para>
110
111 <para>
112 The synchronization extension provides primitives that allow synchronization
113 between clients to take place entirely within the X server. This removes any
114 error introduced by the network and makes it possible to synchronize clients
115 on different hosts running different operating systems. This is important for
116 multimedia applications, where audio, video, and graphics data streams are
117 being synchronized.  The extension also provides internal timers within the
118 X server to which client requests can be synchronized. This allows simple
119 animation applications to be implemented without any round-trip requests and
120 makes best use of buffering within the client, network, and server.
121 </para>
122
123 <sect1 id="description">
124 <title>Description</title>
125 <para>
126 The mechanism used by this extension for synchronization within the X
127 server is to block the processing of requests from a client until a
128 specific synchronization condition occurs. When the condition occurs, the
129 client is released and processing of requests continues. Multiple clients
130 may block on the same condition to give inter-client synchronization.
131 Alternatively, a single client may block on a condition such as an animation
132 frame marker.
133 </para>
134
135 <para>
136 The extension adds <function>Counter</function> and
137 <function>Alarm</function> to the set of resources managed by the
138 server. A counter has a 64-bit integer value that may be increased or
139 decreased by client requests or by the server internally. A client can block
140 by sending an Await request that waits until one of a set of synchronization
141 conditions, called TRIGGERs, becomes TRUE.
142 </para>
143
144 <para>
145 The <function>CreateCounter</function> request allows a client to create a
146 <function>Counter</function> that can be changed by explicit
147 <function>SetCounter</function> and <function>ChangeCounter</function>
148 requests. These can be used to implement synchronization between different
149 clients.
150 </para>
151
152 <para>
153 There are some counters, called <function>System Counters</function>, that
154 are changed by the server internally rather than by client requests. The
155 effect of any change to a system counter is not visible until the server
156 has finished processing the current request. In other words, system
157 counters are apparently updated in the gaps between the execution of
158 requests rather than during the actual execution of a request. The extension
159 provides a system counter that advances with the server time as defined by
160 the core protocol, and it may also provide counters that advance with the
161 real-world time or that change each time the CRT screen is refreshed.
162 Other extensions may provide their own extension-specific system counters.
163 </para>
164
165 <para>
166 The extension provides an <function>Alarm</function> mechanism that allows
167 clients to receive an event on a regular basis when a particular counter
168 is changed.
169 </para>
170
171 </sect1>
172 <sect1 id="types">
173 <title>Types</title>
174 <para>
175 Please refer to the X11 Protocol specification as this document uses
176 syntactic conventions established there and references types defined there.
177 </para>
178
179 <para>The following new types are used by the extension.</para>
180
181 <literallayout class="monospaced">
182 INT64:                 64-bit signed integer
183 COUNTER:               XID
184 VALUETYPE:             {Absolute,Relative};
185 TESTTYPE:              {PositiveTransition,NegativeTransition,
186                         PositiveComparison,NegativeComparison}
187 TRIGGER:               [
188                         counter:COUNTER,
189                         value-type:VALUETYPE,
190                         wait-value:INT64,
191                         test-type:TESTTYPE
192                        ]
193 WAITCONDITION:         [
194                         trigger:TRIGGER,
195                         event-threshold:INT64
196                        ]
197 SYSTEMCOUNTER:         [
198                         name:STRING8,
199                         counter:COUNTER,
200                         resolution:INT64
201                        ]
202 ALARM:                 XID
203 ALARMSTATE:            {Active,Inactive,Destroyed}
204 </literallayout>
205
206 <para>
207 The COUNTER type defines the client-side handle on a server
208 <function>Counter</function>. The value of a counter is an INT64.
209 </para>
210
211 <para>
212 The TRIGGER type defines a test on a counter that is either TRUE or FALSE. The
213 value of the test is determined by the combination of a test value, the value
214 of the counter, and the specified test-type.
215 </para>
216
217 <para>
218 The test value for a trigger is calculated using the value-type and
219 wait-value fields when the trigger is initialized. If the value-type field
220 is not one of the named VALUETYPE constants, the request that initialized the
221 trigger will return a <function>Value</function> error. If the value-type
222 field is <function>Absolute</function>, the test value is given by the
223 wait-value field. If the value-type field is <function>Relative</function>,
224 the test value is obtained by adding the wait-value field to the value of the
225 counter. If the resulting test value would lie outside the range for an
226 INT64, the request that initialized the trigger will return a
227 <function>Value</function> error. If counter is <function>None</function>
228 and the value-type is <function>Relative</function>, the request that
229 initialized the trigger will return a <function>Match</function> error. If
230 counter is not None and does not name a valid counter, a Counter error is
231 generated.
232 </para>
233
234 <para>
235 If the test-type is <function>PositiveTransition</function>, the trigger is
236 initialized to FALSE, and it will become TRUE when the counter changes from
237 a value less than the test value to a value greater than or equal to the
238 test value. If the test-type is <function>NegativeTransition</function>,
239 the trigger is initialize to FALSE, and it will become TRUE when the counter
240 changes from a value greater than the test value to a value less than or
241 equal to the test value. If the test-type is
242 <function>PositiveComparison</function>, the trigger is TRUE if the
243 counter is greater than or equal to the test value and FALSE otherwise. If the
244 test-type is <function>NegativeComparison</function>, the trigger is TRUE
245 if the counter is less than or equal to the test value and FALSE otherwise.
246 If the test-type is not one of the named TESTTYPE constants, the request that
247 initialized the trigger will return a Value error. A trigger with a counter
248 value of <function>None</function> and a valid test-type is always TRUE.
249 </para>
250
251 <para>
252 The WAITCONDITION type is simply a trigger with an associated event-threshold.
253 The event threshold is used by the <function>Await</function> request to
254 decide whether or not to generate an event to the client after the trigger has
255 become TRUE. By setting the event-threshold to an appropriate value, it is
256 possible to detect the situation where an <function>Await</function> request
257 was processed after the TRIGGER became TRUE, which usually indicates that
258 the server is not processing requests as fast as the client expects.
259 </para>
260
261 <para>
262 The SYSTEMCOUNTER type provides the client with information about a
263 <function>System</function>Counter. The name field is the textual name of
264 the counter that identifies the counter to the client. The counter field
265 is the client-side handle that should be used in requests that require a
266 counter. The resolution field gives the approximate step size of the system
267 counter. This is a hint to the client
268 that the extension may not be able to resolve two wait conditions with test
269 values that differ by less than this step size. A microsecond clock, for
270 example, may advance in steps of 64 microseconds, so a counter based on this
271 clock would have a resolution of 64.
272 </para>
273
274 <para>
275 The only system counter that is guaranteed to be present is called SERVERTIME,
276 which counts milliseconds from some arbitrary starting point. The least
277 significant 32 bits of this counter track the value of Time used by the
278 server in Events and Requests. Other system counters may be provided by
279 different implementations of the extension. The X Consortium will maintain a
280 registry of system counter names to avoid collisions in the name space.
281 </para>
282
283 <para>
284 An ALARM is the client-side handle on an <function>Alarm</function> resource.
285 </para>
286 </sect1>
287
288 <sect1 id="errors">
289 <title>Errors</title>
290
291 <variablelist>
292   <varlistentry>
293     <term>Counter</term>
294     <listitem>
295       <para>
296 This error is generated if the value for a COUNTER argument in a request
297 does not name a defined COUNTER.
298       </para>
299     </listitem>
300   </varlistentry>
301   <varlistentry>
302     <term>Alarm</term>
303     <listitem>
304       <para>
305 This error is generated if the value for an ALARM argument in a request
306 does not name a defined ALARM.
307       </para>
308     </listitem>
309   </varlistentry>
310 </variablelist>
311
312 </sect1>
313 <sect1 id="requests">
314
315 <title>Requests</title>
316
317 <variablelist>
318   <varlistentry>
319     <term>Initialize</term>
320     <listitem>
321 <literallayout class="monospaced">
322 version-major,version-minor: CARD8
323 =>
324 version-major,version-minor: CARD8
325 </literallayout>
326
327      <para>
328 This request must be executed before any other requests for this extension. If a
329 client violates this rule, the results of all SYNC requests that it issues are
330 undefined. The request takes the version number of the extension that the
331 client wishes to use and returns the actual version number being implemented
332 by the extension for this client. The extension may return different
333 version numbers to a client depending of the version number supplied by
334 that client. This request should be executed only once for each client
335 connection.
336      </para>
337      <para>
338 Given two different versions of the SYNC protocol, v1 and v2, v1 is
339 compatible with v2 if and only if v1.version_major = v2.version_major
340 and v1.version_minor &lt;= v2.version_minor.  Compatible means that the
341 functionality is fully supported in an identical fashion in the two versions.
342      </para>
343      <para>
344 This document describes major version 3, minor version 0 of the SYNC protocol.
345      </para>
346    </listitem>
347   </varlistentry>
348   <varlistentry>
349     <term>ListSystemCounters</term>
350     <listitem>
351 <literallayout class="monospaced">
352 =>
353 system-counters: LISTofSYSTEMCOUNTER
354 Errors: Alloc
355 </literallayout>
356       <para>
357 This request returns a list of all the system counters that are available at
358 the time the request is executed, which includes the system counters
359 that are maintained by other extensions. The list returned by this
360 request may change as counters are created and destroyed by other extensions.
361       </para>
362     </listitem>
363   </varlistentry>
364   <varlistentry>
365   <term>CreateCounter</term>
366   <listitem>
367 <literallayout class="monospaced">
368 id: COUNTER
369 initial-value: INT64
370 Errors: IDChoice,Alloc
371 </literallayout>
372       <para>
373 This request creates a counter and assigns the specified id to it. The counter
374 value is initialized to the specified initial-value and there are no clients
375 waiting on the counter.
376       </para>
377     </listitem>
378   </varlistentry>
379   <varlistentry>
380     <term>DestroyCounter</term>
381     <listitem>
382 <literallayout class="monospaced">
383 counter: COUNTER
384 Errors: Counter,Access
385 </literallayout>
386       <para>
387 This request destroys the given counter and sets the counter fields for all
388 triggers that specify this counter to <function>None</function>. All clients
389 waiting on the counter are released and a <function>CounterNotify</function>
390 event with the destroyed field set to TRUE is sent to each waiting client,
391 regardless of the event-threshold. All alarms specifying the counter become
392 <function>Inactive</function> and an <function>AlarmNotify</function>
393 event with a state field of <function>Inactive</function> is generated. A
394 counter is destroyed automatically when the connection to the creating client
395 is closed down if the close-down mode is Destroy. An
396 <function>Access</function> error is generated if counter is a system
397 counter. A <function>Counter</function> error is generated if counter does
398 not name a valid counter.
399       </para>
400     </listitem>
401   </varlistentry>
402   <varlistentry>
403     <term>QueryCounter</term>
404     <listitem>
405 <literallayout class="monospaced">
406 counter: COUNTER
407 =>
408 value: INT64
409 Errors: <function>Counter</function>
410 </literallayout>
411       <para>
412 This request returns the current value of the given counter or a generates
413 Counter error if counter does not name a valid counter.
414       </para>
415     </listitem>
416   </varlistentry>
417   <varlistentry>
418     <term>Await</term>
419     <listitem>
420 <literallayout class="monospaced">
421 wait-list: LISTofWAITCONDITION
422 Errors: Counter,Alloc,Value
423 </literallayout>
424       <para>
425 When this request is executed, the triggers in the wait-list are initialized
426 using the wait-value and value-type fields, as described in the definition of
427 TRIGGER above. The processing of further requests for the client is blocked
428 until one or more of the triggers becomes TRUE. This may happen immediately,
429 as a result of the initialization, or at some later time, as a result of
430 a subsequent <function>SetCounter</function>,
431 <function>ChangeCounter</function> or
432 <function>DestroyCounter</function> request.
433       </para>
434       <para>
435 A Value error is generated if wait-list is empty.
436       </para>
437       <para>
438 When the client becomes unblocked, each trigger is checked to determine
439 whether a <function>CounterNotify</function> event should be generated.
440 The difference between the counter and the test value is calculated by
441 subtracting the test value from the value of the counter. If the test-type
442 is <function>PositiveTransition</function> or
443 <function>PositiveComparison</function>, a
444 <function>CounterNotify</function> event is generated if the difference is
445 at least event-threshold. If the test-type is
446 <function>NegativeTransition</function> or
447 <function>NegativeComparison</function>, a
448 <function>CounterNotify</function> event is generated if the difference
449 is at most event-threshold. If the difference lies outside the range for an
450 INT64, an event is not generated.
451       </para>
452       <para>
453 This threshold check is made for each trigger in the list and a
454 <function>CounterNotify</function> event is generated for every trigger for
455 which the check succeeds. The check for
456 <function>CounterNotify</function> events is performed even if one of the
457 triggers is TRUE when the request is first executed. Note that a
458 <function>CounterNotify</function> event may be generated for a trigger
459 that is FALSE if there are multiple triggers in the request. A
460 <function>CounterNotify</function> event with the destroyed flag set to
461 TRUE is always generated if the counter for one of the triggers is
462 destroyed.
463       </para>
464     </listitem>
465   </varlistentry>
466   <varlistentry>
467     <term>ChangeCounter</term>
468     <listitem>
469 <literallayout class="monospaced">
470 counter: COUNTER
471 amount: INT64
472 Errors: <function>Counter,Access,Value</function>
473 </literallayout>
474       <para>
475 This request changes the given counter by adding amount to the current
476 counter value. If the change to this counter satisfies a trigger for which a client
477 is waiting, that client is unblocked and one or more
478 <function>CounterNotify</function> events may be generated. If the change to
479 the counter satisfies the trigger for an alarm, an
480 <function>AlarmNotify</function> event is generated and the
481 alarm is updated. An <function>Access</function> error is generated if
482 counter is a system counter. A <function>Counter</function> error is
483 generated if counter does not name a valid counter. If the resulting value
484 for the counter would be outside the range for an INT64, a
485 <function>Value</function> error is generated and the counter is not changed.
486       </para>
487       <para>
488 It should be noted that all the clients whose triggers are satisfied by this
489 change are unblocked, so this request cannot be used to implement mutual
490 exclusion.
491       </para>
492     </listitem>
493   </varlistentry>
494   <varlistentry>
495     <term>SetCounter</term>
496     <listitem>
497 <literallayout class="monospaced">
498 counter: COUNTER
499 value: INT64
500 Errors: <function>Counter,Access</function>
501 </literallayout>
502       <para>
503 This request sets the value of the given counter to value. The effect is
504 equivalent to executing the appropriate ChangeCounter request to change
505 the counter value to value. An Access error is generated if counter names a
506 system counter. A Counter error is generated if counter does not name a valid
507 counter.
508       </para>
509     </listitem>
510   </varlistentry>
511   <varlistentry>
512     <term>CreateAlarm</term>
513     <listitem>
514 <literallayout class="monospaced">
515 id: ALARM
516 values-mask: CARD32
517 values-list: LISTofVALUE
518 left">Errors: IDChoice,Counter,Match,Value,Alloc
519 </literallayout>
520       <para>
521 This request creates an alarm and assigns the identifier id to it. The
522 values-mask and values-list specify the attributes that are to be explicitly
523 initialized. The attributes for an Alarm and their defaults are:
524       </para>
525       <informaltable>
526         <tgroup cols="4">
527           <colspec colname="c1"/>
528           <colspec colname="c2"/>
529           <colspec colname="c3"/>
530           <colspec colname="c4"/>
531           <tbody>
532             <row>
533               <entry align="left">Attribute</entry>
534               <entry align="left">Type</entry>
535               <entry align="left">Default</entry>
536             </row>
537             <row role="hline">
538               <entry rowsep="1"></entry>
539               <entry rowsep="1"></entry>
540               <entry rowsep="1"></entry>
541               <entry rowsep="1"></entry>
542             </row>
543             <row>
544               <entry align="left">trigger</entry>
545               <entry align="left">TRIGGER</entry>
546               <entry align="left">counter</entry>
547               <entry align="left">None</entry>
548             </row>
549             <row>
550               <entry align="left"></entry>
551               <entry align="left"></entry>
552               <entry align="left">value-type</entry>
553               <entry align="left">Absolute</entry>
554             </row>
555             <row>
556               <entry align="left"></entry>
557               <entry align="left"></entry>
558               <entry align="left">value</entry>
559               <entry align="left">0</entry>
560             </row>
561             <row>
562               <entry align="left"></entry>
563               <entry align="left"></entry>
564               <entry align="left">test-type</entry>
565               <entry align="left">PositiveComparison</entry>
566             </row>
567             <row>
568               <entry align="left">delta</entry>
569               <entry align="left">INT64</entry>
570               <entry align="left">1</entry>
571             </row>
572             <row>
573               <entry align="left">events</entry>
574               <entry align="left">BOOL</entry>
575               <entry align="left">TRUE</entry>
576             </row>
577           </tbody>
578         </tgroup>
579       </informaltable>
580       <para>
581 The trigger is initialized as described in the definition of TRIGGER, with an
582 error being generated if necessary.
583       </para>
584       <para>
585 If the counter is <function>None</function>, the state of the alarm is set
586 to <function>Inactive</function>, else it is set to Active.
587       </para>
588       <para>
589 Whenever the trigger becomes TRUE, either as a result of this request or as the
590 result of a <function>SetCounter</function>,
591 <function>ChangeCounter</function>, <function>DestroyCounter</function>, or
592 <function>ChangeAlarm</function> request, an
593 <function>AlarmNotify</function> event is generated and the alarm is
594 updated. The alarm is updated by repeatedly adding delta to the value of the
595 trigger and reinitializing it until it becomes FALSE. If this update would
596 cause value to fall outside the range for an INT64, or if the counter
597 value is <function>None</function>, or if the delta is 0 and test-type
598 is <function>PositiveComparison</function> or
599 <function>NegativeComparison</function>, no change is made to value and
600 the alarm state is changed to <function>Inactive</function> before the
601 event is generated. No further events are generated by an
602 <function>Inactive</function> alarm until a <function>ChangeAlarm</function>
603 or <function>DestroyAlarm </function> request is executed.
604       </para>
605       <para>
606 If the test-type is <function>PositiveComparison</function> or
607 <function>PositiveTransition and</function> delta is less than zero, or
608 if the test-type is <function>NegativeComparison</function> or
609 <function>NegativeTransition</function> and delta is greater than zero,
610 a <function>Match</function> error is generated.
611       </para>
612       <para>
613 The events value enables or disables delivery of
614 <function>AlarmNotify</function> events
615 to the requesting client. The alarm keeps a separate event flag for
616 each client so that other clients may select to receive events from this
617 alarm.
618       </para>
619       <para>
620 An <function>AlarmNotify</function> event is always generated at some time
621 after the execution of a <function>CreateAlarm</function> request. This
622 will happen immediately if the trigger is TRUE, or it will happen later
623 when the trigger becomes TRUE or the Alarm is destroyed.
624       </para>
625     </listitem>
626   </varlistentry>
627   <varlistentry>
628     <term>ChangeAlarm</term>
629     <listitem>
630 <literallayout class="monospaced">
631 id: ALARM
632 values-mask: CARD32
633 values-list: LISTofVALUE
634 Errors: Alarm,Counter,Value,Match
635 </literallayout>
636       <para>
637 This request changes the parameters of an Alarm. All of the parameters
638 specified for the <function>CreateAlarm</function> request may be changed
639 using this request.  The trigger is reinitialized and an
640 <function>AlarmNotify</function> event is generated if appropriate, as
641 explained in the description of the <function>CreateAlarm</function> request.
642       </para>
643       <para>
644 Changes to the events flag affect the event delivery to the requesting
645 client only and may be used by a client to select or deselect event delivery
646 from an alarm created by another client.
647       </para>
648       <para>
649 The order in which attributes are verified and altered is server-dependent.
650 If an error is generated, a subset of the attributes may have been altered.
651       </para>
652     </listitem>
653   </varlistentry>
654   <varlistentry>
655     <term>DestroyAlarm</term>
656     <listitem>
657 <literallayout class="monospaced">
658 alarm: ALARM
659 Errors: Alarm
660 </literallayout>
661       <para>
662 This request destroys an alarm. An alarm is automatically destroyed when the
663 creating client is closed down if the close-down mode is
664 <function>Destroy</function>. When an alarm is destroyed, an
665 <function>AlarmNotify</function> event is generated with a state value of
666 <function>Destroyed</function>.
667       </para>
668     </listitem>
669   </varlistentry>
670   <varlistentry>
671     <term>QueryAlarm</term>
672     <listitem>
673 <literallayout class="monospaced">
674 alarm: ALARM
675 =>
676 trigger: TRIGGER
677 delta: INT64
678 events: ALARMEVENTMASK
679 state: ALARMSTATE
680 Errors: <function>Alarm</function>
681 </literallayout>
682       <para>This request retrieves the current parameters for an Alarm.</para>
683     </listitem>
684   </varlistentry>
685   <varlistentry>
686     <term>SetPriority</term>
687     <listitem>
688 <literallayout class="monospaced">
689 client-resource: XID
690 priority: INT32
691 Errors: <function>Match</function>
692 </literallayout>
693       <para>
694 This request changes the scheduling priority of the client that created
695 client-resource. If client-resource is <function>None</function>, then
696 the priority for the client making the request is changed. A
697 <function>Match</function> error is generated if client-resource is not
698 <function>None</function> and does not name an existing resource in the
699 server. For any two priority values, A and B, A is higher priority if
700 and only if A is greater than B.
701       </para>
702       <para>
703 The priority of a client is set to 0 when the initial client connection is
704  made.
705       </para>
706       <para>
707 The effect of different client priorities depends on the particular
708 implementation of the extension, and in some cases it may have no effect at
709 all. However, the intention is that higher priority clients will have
710 their requests executed before those of lower priority clients.
711       </para>
712       <para>
713 For most animation applications, it is desirable that animation clients be
714 given priority over nonrealtime clients. This improves the smoothness of the
715 animation on a loaded server. Because a server is free to implement very strict
716 priorities, processing requests for the highest priority client to the
717 exclusion of all others, it is important that a client that may potentially
718 monopolize the whole server, such as an animation that produces continuous
719 output as fast as it can with no rate control, is run at low rather than high
720 priority.
721       </para>
722     </listitem>
723   </varlistentry>
724   <varlistentry>
725     <term>GetPriority</term>
726     <listitem>
727 <literallayout class="monospaced">
728 client-resource: XID
729 =>
730 priority: INT32
731 Errors: <function>Match</function>
732 </literallayout>
733       <para>
734 This request returns the scheduling priority of the client that created
735 client-resource. If client-resource is <function>None</function>, then the
736 priority for the client making the request is returned. A
737 <function>Match</function> error is generated if client-resource is
738 not <function>None</function> and does not name an existing resource in the
739 server.
740       </para>
741     </listitem>
742   </varlistentry>
743 </variablelist>
744 </sect1>
745
746 <sect1 id="events">
747 <title>Events</title>
748
749 <variablelist>
750   <varlistentry>
751     <term>CounterNotify</term>
752     <listitem>
753 <literallayout class="monospaced">
754 counter: COUNTER
755 wait-value: INT64
756 counter-value: INT64
757 time: TIME
758 count: CARD16
759 destroyed: BOOL
760 </literallayout>
761       <para>
762 <function>CounterNotify</function> events may be generated when a client
763 becomes unblocked after an <function>Await</function> request has been
764 processed. The wait-value is the value being waited for, and counter-value
765 is the actual value of the counter at the time the event was generated.
766 The destroyed flag is TRUE if this request was generated as the result of
767 the destruction of the counter and FALSE otherwise. The time is the server
768 time at which the event was generated.
769       </para>
770       <para>
771 When a client is unblocked, all the <function>CounterNotify</function>
772 events for the Await request are generated contiguously. If count is 0,
773 there are no more events to follow for this request. If count is n,
774 there are at least n more events to follow.
775       </para>
776     </listitem>
777   </varlistentry>
778   <varlistentry>
779     <term>AlarmNotify</term>
780     <listitem>
781 <literallayout class="monospaced">
782 alarm: ALARM
783 counter-value: INT64
784 alarm-value: INT64
785 state: ALARMSTATE
786 time: TIME
787 </literallayout>
788       <para>
789 An <function>AlarmNotify</function> event is generated when an alarm is
790 triggered. alarm-value is the test value of the trigger in the alarm when
791 it was triggered, counter-value is the value of the counter that triggered
792 the alarm, and time is the server time at which the event was generated.
793 The state is the new state of the alarm. If state is
794 <function>Inactive</function>, no more events will be generated by this
795 alarm until a <function>ChangeAlarm</function> request is executed, the alarm
796 is destroyed, or the counter for the alarm is destroyed.
797       </para>
798     </listitem>
799   </varlistentry>
800 </variablelist>
801 </sect1>
802 </chapter>
803
804 <chapter id="encoding">
805 <title>Encoding</title>
806 <para>
807 Please refer to the X11 Protocol Encoding document as this section uses
808 syntactic conventions established there and references types defined there.
809 </para>
810 <para>The name of this extension is "SYNC".</para>
811
812 <sect1 id="encoding_new_types">
813 <title>Encoding New Types</title>
814 <para>
815 The following new types are used by the extension.
816 </para>
817
818 <literallayout class="monospaced">
819 ALARM: CARD32
820 ALARMSTATE:
821        0         Active
822        1         Inactive
823        2         Destroyed
824 COUNTER: CARD32
825 INT64: 64-bit signed integer
826 SYSTEMCOUNTER:
827        4         COUNTER                 counter
828        8         INT64                   resolution
829        2         n                       length of name in bytes
830        n         STRING8                 name
831        p                                 pad,p=pad(n+2)
832 TESTTYPE:
833        0         PositiveTransition
834        1         NegativeTransition
835        2         PositiveComparison
836        3         NegativeComparison
837 TRIGGER:
838        4         COUNTER                 counter
839        4         VALUETYPE               wait-type
840        8         INT64                   wait-value
841        4         TESTTYPE                test-type  VALUETYPE:
842        0         Absolute
843        1         Relative
844 WAITCONDITION:
845        20        TRIGGER                 trigger
846        8         INT64                   event threshold
847 </literallayout>
848
849 <para>
850 An INT64 is encoded in 8 bytes with the most significant 4 bytes
851 first followed by the least significant 4 bytes. Within these 4-byte
852 groups, the byte ordering determined during connection setup is used.
853 </para>
854 </sect1>
855
856 <sect1 id="encoding_errors">
857 <title>Encoding Errors</title>
858 <literallayout class="monospaced">
859 <function>Counter</function>
860         1    0            Error
861         1    Base + 0     code
862         2    CARD16       sequence number
863         4    CARD32       bad counter
864         2    CARD16       minor opcode
865         1    CARD8        major opcode
866         21                unused
867 <function>Alarm</function>
868         1    0            Error
869         1    Base + 1     code
870         2    CARD16       sequence number
871         4    CARD32       bad alarm
872         2    CARD16       minor opcode
873         1    CARD8        major opcode
874         21                unused
875 </literallayout>
876
877 </sect1>
878
879 <sect1 id="encoding_requests">
880 <title>Encoding Requests</title>
881
882 <literallayout class="monospaced">
883 <function>Initialize</function>
884         1    CARD8        major opcode
885         1    0            minor opcode
886         2    2            request length
887         1    CARD8        major version
888         1    CARD8        minor version
889         2                 unused
890 =>
891         1    1            Reply
892         1                 unused
893         2    CARD16       sequence number
894         4    0            reply length
895         1    CARD8        major version
896         1    CARD8        minor version
897         2                 unused
898         20                unused
899
900 <function>ListSystemCounters</function>
901         1    CARD8                  major opcode
902         1    1                      minor opcode
903         2    1                      request length
904 =>
905         1    1                      Reply
906         1                           unused
907         2    CARD16                 sequence number
908         4    0                      reply length
909         4    INT32                  list length
910         20                          unused
911         4n   list of SYSTEMCOUNTER  system counters
912
913 <function>CreateCounter</function>
914         1    CARD8                  major opcode
915         1    2                      minor opcode
916         2    4                      request length
917         4    COUNTER                id
918         8    INT64                  initial value
919
920 <function>DestroyCounter</function>
921         1    CARD8                  major opcode
922         1    6                      minor opcode<footnote><para>A previous version of this document gave an incorrect minor opcode</para></footnote>
923         2    2                      request length
924         4    COUNTER                counter
925 =>
926         1    1                      Reply
927         1                           unused
928         2    CARD16                 sequence number
929         4    0                      reply length
930         8    INT64                  counter value
931         16                          unused
932
933 Await
934         1    CARD8                  major opcode
935         1    7                      minor opcode<footnote><para>A previous version of this document gave an incorrect minor opcode.</para></footnote>
936         2    1 + 7*n                request length
937         28n  LISTofWAITCONDITION    wait conditions
938
939 ChangeCounter
940         1    CARD8                  major opcode
941         1    4                      minor opcode<footnote><para>A previous version of this document gave an incorrect minor opcode.</para></footnote>
942         2    4                      request length
943         4    COUNTER                counter
944         8    INT64                  amount
945
946 SetCounter
947         1    CARD8                  major opcode
948         1    3                      minor opcode<footnote><para>A previous version of this document gave an incorrect minor opcode.</para></footnote>
949         2    4                      request length
950         4    COUNTER                counter
951         8    INT64                  value
952
953 CreateAlarm
954         1    CARD8                  major opcode
955         1    8                      minor opcode
956         2    3+n                    request length
957         4    ALARM                  id
958         4    BITMASK                values mask
959
960              #x00000001             counter
961              #x00000002             value-type
962              #x00000004             value
963              #x00000008             test-type
964              #x00000010             delta
965              #x00000020             events
966
967         4n   LISTofVALUE            values
968
969 VALUES
970         4    COUNTER                counter
971         4    VALUETYPE              value-type
972         8    INT64                  value
973         4    TESTTYPE               test-type
974         8    INT64                  delta
975         4    BOOL                   events
976
977 ChangeAlarm
978         1    CARD8                  major opcode
979         1    9                      minor opcode
980         2    3+n                    request length
981         4    ALARM                  id
982         4    BITMASK                values mask
983              encodings as for <function>CreateAlarm</function>
984         4n   LISTofVALUE            values
985              encodings as for <function>CreateAlarm</function>
986
987 DestroyAlarm
988         1    CARD8        major opcode
989         1    11           minor opcode<footnote><para>A previous version of this document gave an incorrect minor opcode.</para></footnote>
990         2    2            request length
991         4    ALARM        alarm
992
993 QueryAlarm
994         1    CARD8        major opcode
995         1    10           minor opcode<footnote><para>A previous version of this document gave an incorrect minor opcode.</para></footnote>
996         2    2            request length
997         4    ALARM        alarm
998 =>
999         1    1            Reply
1000         1                 unused
1001         2    CARD16       sequence number
1002         4    2            reply length
1003         20   TRIGGER      trigger
1004         8    INT64        delta
1005         1    BOOL         events
1006         1    ALARMSTATE   state
1007         2                 unused
1008
1009 SetPriority
1010         1    CARD8        major opcode
1011         1    12           minor opcode
1012         2    3            request length
1013         4    CARD32       id
1014         4    INT32        priority
1015
1016 GetPriority
1017         1    CARD8        major opcode
1018         1    13           minor opcode
1019         2    1            request length
1020         4    CARD32       id
1021 =>
1022         1    1            Reply
1023         1                 unused
1024         2    CARD16       sequence number
1025         4    0            reply length
1026         4    INT32        priority
1027         20                unused
1028
1029 </literallayout>
1030
1031 </sect1>
1032
1033 <sect1 id="encoding_events">
1034 <title>Encoding Events</title>
1035
1036 <literallayout class="monospaced">
1037 <function>CounterNotify</function>
1038         1    Base + 0     code
1039         1    0            kind
1040         2    CARD16       sequence number
1041         4    COUNTER      counter
1042         8    INT64        wait value
1043         8    INT64        counter value
1044         4    TIME         timestamp
1045         2    CARD16       count
1046         1    BOOL         destroyed
1047         1                 unused
1048
1049 <function>AlarmNotify</function>
1050         1    Base + 1     code
1051         1    1            kind
1052         2    CARD16       sequence number
1053         4    ALARM        alarm
1054         8    INT64        counter value
1055         8    INT64        alarm value
1056         4    TIME         timestamp
1057         1    ALARMSTATE   state
1058         3                 unused
1059 </literallayout>
1060 </sect1>
1061 </chapter>
1062 </book>