Merge lp:~chasedouglas/grail/xsync-alarm into lp:grail
- xsync-alarm
- Merge into trunk
Proposed by
Chase Douglas
Status: | Merged |
---|---|
Merged at revision: | 223 |
Proposed branch: | lp:~chasedouglas/grail/xsync-alarm |
Merge into: | lp:grail |
Diff against target: |
423 lines (+98/-54) 8 files modified
test/x11/fixture.cpp (+24/-12) test/x11/fixture.h (+2/-1) tools/common/servertime.c (+44/-18) tools/common/servertime.h (+4/-3) tools/grail-test-3-1.c (+6/-5) tools/grail-test-atomic.c (+6/-5) tools/grail-test-edge.c (+6/-5) tools/grail-test-propagation.c (+6/-5) |
To merge this branch: | bzr merge lp:~chasedouglas/grail/xsync-alarm |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel d'Andrada (community) | Approve | ||
Review via email: mp+100226@code.launchpad.net |
Commit message
Description of the change
Fix up tests and tools for using xsync alarms. The tests now also use the
sync event times instead of querying the time (forgot to fix this).
To post a comment you must log in.
Revision history for this message
Daniel d'Andrada (dandrader) wrote : | # |
Revision history for this message
Daniel d'Andrada (dandrader) wrote : | # |
Other than that it looks ok
review:
Approve
- 224. By Chase Douglas
-
Don't try to set the alarm state, it won't work
Created alarms will be active, but with a trigger value of 0. It would
take 584,942,417 years to wrap around to 0, though, so I think we're
safe.
Revision history for this message
Chase Douglas (chasedouglas) wrote : | # |
> + attrs.state = XSyncAlarmInactive;
>
> Documentation says "client cannot set this"
I've removed the state setting. When you create or change an alarm is automatically sets the alarm to active. By default, the value is 0, so the counter would have to wrap around. This would take way too long in practice, so this shouldn't be a problem.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'test/x11/fixture.cpp' |
2 | --- test/x11/fixture.cpp 2012-02-20 12:53:55 +0000 |
3 | +++ test/x11/fixture.cpp 2012-03-30 20:02:18 +0000 |
4 | @@ -87,6 +87,19 @@ |
5 | XSyncFreeSystemCounterList(counters); |
6 | ASSERT_TRUE(found); |
7 | |
8 | + XSyncAlarmAttributes attrs; |
9 | + attrs.trigger.counter = server_time_counter_; |
10 | + attrs.trigger.value_type = XSyncAbsolute; |
11 | + attrs.trigger.test_type = XSyncPositiveComparison; |
12 | + attrs.delta = { 0, 0 }; |
13 | + attrs.events = True; |
14 | + |
15 | + alarm_ = XSyncCreateAlarm(Display(), |
16 | + XSyncCACounter | XSyncCAValueType | |
17 | + XSyncCATestType | XSyncCAEvents | XSyncCADelta, |
18 | + &attrs); |
19 | + ASSERT_NE(None, alarm_) << "failed to create XSync alarm"; |
20 | + |
21 | UFStatus frame_status = frame_x11_new(Display(), &frame_handle_); |
22 | ASSERT_EQ(UFStatusSuccess, frame_status); |
23 | |
24 | @@ -146,7 +159,7 @@ |
25 | |
26 | if (event.type != GenericEvent) { |
27 | /* If it's not an XI 2 event, it's probably a timer event */ |
28 | - UpdateTime(); |
29 | + UpdateTime(reinterpret_cast<XSyncAlarmNotifyEvent&>(event)); |
30 | continue; |
31 | } |
32 | |
33 | @@ -180,13 +193,12 @@ |
34 | return false; |
35 | } |
36 | |
37 | -void utouch::grail::x11::testing::Test::UpdateTime() { |
38 | +void utouch::grail::x11::testing::Test::UpdateTime( |
39 | + const XSyncAlarmNotifyEvent& event) { |
40 | /* Process any outstanding frames first */ |
41 | ProcessFrameEvents(); |
42 | |
43 | - XSyncValue time; |
44 | - EXPECT_TRUE(XSyncQueryCounter(Display(), server_time_counter_, &time)); |
45 | - |
46 | + XSyncValue time = event.counter_value; |
47 | uint64_t server_time = |
48 | (uint64_t)XSyncValueHigh32(time) << 32 | XSyncValueLow32(time); |
49 | EXPECT_GT(server_time, 0); |
50 | @@ -197,20 +209,20 @@ |
51 | void utouch::grail::x11::testing::Test::SetX11Timeout() { |
52 | uint64_t timeout = grail_next_timeout(grail_handle()); |
53 | if (timeout > 0) { |
54 | - XSyncWaitCondition condition; |
55 | + XSyncAlarmAttributes attrs; |
56 | |
57 | - condition.trigger.counter = server_time_counter_; |
58 | - condition.trigger.value_type = XSyncAbsolute; |
59 | - XSyncIntsToValue(&condition.trigger.wait_value, timeout & 0xffffffff, |
60 | + XSyncIntsToValue(&attrs.trigger.wait_value, timeout & 0xffffffff, |
61 | timeout & 0xffffffff00000000); |
62 | - condition.trigger.test_type = XSyncPositiveComparison; |
63 | - XSyncIntToValue(&condition.event_threshold, 0); |
64 | - EXPECT_TRUE(XSyncAwait(Display(), &condition, 1)); |
65 | + |
66 | + if (!XSyncChangeAlarm(Display(), alarm_, XSyncCAValue, &attrs)) |
67 | + fprintf(stderr, "Warning: failed to set XSync alarm\n"); |
68 | + |
69 | XFlush(Display()); |
70 | } |
71 | } |
72 | |
73 | void utouch::grail::x11::testing::Test::TearDown() { |
74 | + XSyncDestroyAlarm(Display(), alarm_); |
75 | grail_delete_v3(grail_handle_); |
76 | frame_x11_delete(frame_handle_); |
77 | xorg::testing::Test::TearDown(); |
78 | |
79 | === modified file 'test/x11/fixture.h' |
80 | --- test/x11/fixture.h 2012-01-31 22:27:05 +0000 |
81 | +++ test/x11/fixture.h 2012-03-30 20:02:18 +0000 |
82 | @@ -51,12 +51,13 @@ |
83 | UGHandle grail_handle() const { return grail_handle_; } |
84 | |
85 | private: |
86 | - void UpdateTime(); |
87 | + void UpdateTime(const XSyncAlarmNotifyEvent&); |
88 | void SetX11Timeout(); |
89 | |
90 | UFHandle frame_handle_; |
91 | UGHandle grail_handle_; |
92 | XSyncCounter server_time_counter_; |
93 | + XSyncAlarm alarm_; |
94 | }; |
95 | |
96 | } // namespace testing |
97 | |
98 | === modified file 'tools/common/servertime.c' |
99 | --- tools/common/servertime.c 2012-03-23 01:33:20 +0000 |
100 | +++ tools/common/servertime.c 2012-03-30 20:02:18 +0000 |
101 | @@ -24,13 +24,16 @@ |
102 | #include <stdio.h> |
103 | #include <string.h> |
104 | |
105 | -XSyncCounter get_server_time_counter(Display *display) { |
106 | +XSyncAlarm create_alarm(Display *display) { |
107 | int event_base; |
108 | int error_base; |
109 | int major_version; |
110 | int minor_version; |
111 | XSyncSystemCounter *counters; |
112 | int num_system_counters; |
113 | + XSyncCounter counter = -1; |
114 | + XSyncAlarmAttributes attrs; |
115 | + XSyncAlarm alarm; |
116 | int i; |
117 | |
118 | if (XSyncQueryExtension(display, &event_base, &error_base) != True) { |
119 | @@ -46,37 +49,60 @@ |
120 | counters = XSyncListSystemCounters(display, &num_system_counters); |
121 | for (i = 0; i < num_system_counters; ++i) { |
122 | if (strcmp(counters[i].name, "SERVERTIME") == 0) { |
123 | - XSyncCounter server_time_counter = counters[i].counter; |
124 | - XSyncFreeSystemCounterList(counters); |
125 | - return server_time_counter; |
126 | + counter = counters[i].counter; |
127 | + break; |
128 | } |
129 | } |
130 | |
131 | - fprintf(stderr, "Warning: failed to find SERVERTIME counter\n"); |
132 | XSyncFreeSystemCounterList(counters); |
133 | - return -1; |
134 | -} |
135 | - |
136 | -void update_time(UGHandle handle, XSyncCounterNotifyEvent *event) { |
137 | + |
138 | + if (i == num_system_counters) { |
139 | + fprintf(stderr, "Warning: failed to find SERVERTIME counter\n"); |
140 | + return None; |
141 | + } |
142 | + |
143 | + attrs.trigger.counter = counter; |
144 | + attrs.trigger.value_type = XSyncAbsolute; |
145 | + attrs.trigger.test_type = XSyncPositiveComparison; |
146 | + attrs.delta.hi = 0; |
147 | + attrs.delta.lo = 0; |
148 | + attrs.events = True; |
149 | + |
150 | + alarm = XSyncCreateAlarm(display, |
151 | + XSyncCACounter | XSyncCAValueType | XSyncCATestType | |
152 | + XSyncCAEvents | XSyncCADelta, &attrs); |
153 | + if (alarm == None) |
154 | + fprintf(stderr, "Warning: failed to create XSync alarm\n"); |
155 | + |
156 | + return alarm; |
157 | +} |
158 | + |
159 | +void destroy_alarm(Display *display, XSyncAlarm alarm) { |
160 | + if (alarm != None) |
161 | + XSyncDestroyAlarm(display, alarm); |
162 | +} |
163 | + |
164 | +void update_time(UGHandle handle, XSyncAlarmNotifyEvent *event) { |
165 | XSyncValue value = event->counter_value; |
166 | uint64_t grail_time = (uint64_t)value.hi << 32 | value.lo; |
167 | |
168 | grail_update_time(handle, grail_time); |
169 | } |
170 | |
171 | -void set_timeout(UGHandle handle, Display *display, XSyncCounter counter) { |
172 | +void set_timeout(UGHandle handle, Display *display, XSyncAlarm alarm) { |
173 | + if (alarm == None) |
174 | + return; |
175 | + |
176 | uint64_t timeout = grail_next_timeout(handle); |
177 | if (timeout) { |
178 | - XSyncWaitCondition condition; |
179 | + XSyncAlarmAttributes attrs; |
180 | |
181 | - condition.trigger.counter = counter; |
182 | - condition.trigger.value_type = XSyncAbsolute; |
183 | - XSyncIntsToValue(&condition.trigger.wait_value, timeout & 0xffffffff, |
184 | + XSyncIntsToValue(&attrs.trigger.wait_value, timeout & 0xffffffff, |
185 | timeout & 0xffffffff00000000); |
186 | - condition.trigger.test_type = XSyncPositiveComparison; |
187 | - XSyncIntToValue(&condition.event_threshold, 0); |
188 | - if (!XSyncAwait(display, &condition, 1)) |
189 | - fprintf(stderr, "Warning: failed to set wait trigger\n"); |
190 | + |
191 | + if (!XSyncChangeAlarm(display, alarm, XSyncCAValue, &attrs)) |
192 | + fprintf(stderr, "Warning: failed to set XSync alarm\n"); |
193 | + |
194 | XFlush(display); |
195 | } |
196 | } |
197 | |
198 | === modified file 'tools/common/servertime.h' |
199 | --- tools/common/servertime.h 2012-03-23 01:33:20 +0000 |
200 | +++ tools/common/servertime.h 2012-03-30 20:02:18 +0000 |
201 | @@ -26,6 +26,7 @@ |
202 | |
203 | #include <utouch/grail.h> |
204 | |
205 | -XSyncCounter get_server_time_counter(Display *display); |
206 | -void update_time(UGHandle handle, XSyncCounterNotifyEvent *event); |
207 | -void set_timeout(UGHandle handle, Display *display, XSyncCounter counter); |
208 | +XSyncAlarm create_alarm(Display *display); |
209 | +void destroy_alarm(Display *display, XSyncAlarm alarm); |
210 | +void update_time(UGHandle handle, XSyncAlarmNotifyEvent *event); |
211 | +void set_timeout(UGHandle handle, Display *display, XSyncAlarm alarm); |
212 | |
213 | === modified file 'tools/grail-test-3-1.c' |
214 | --- tools/grail-test-3-1.c 2012-03-23 01:33:20 +0000 |
215 | +++ tools/grail-test-3-1.c 2012-03-30 20:02:18 +0000 |
216 | @@ -202,7 +202,7 @@ |
217 | Window win; |
218 | XIEventMask mask; |
219 | XIGrabModifiers mods = { XIAnyModifier, 0 }; |
220 | - XSyncCounter server_time_counter; |
221 | + XSyncAlarm alarm; |
222 | UFStatus frame_status; |
223 | UFHandle frame_handle; |
224 | UGStatus grail_status; |
225 | @@ -250,7 +250,7 @@ |
226 | |
227 | nfds = ConnectionNumber(display) + 1; |
228 | |
229 | - server_time_counter = get_server_time_counter(display); |
230 | + alarm = create_alarm(display); |
231 | |
232 | mask.deviceid = XIAllMasterDevices; |
233 | mask.mask_len = XIMaskLen(XI_LASTEVENT); |
234 | @@ -306,7 +306,7 @@ |
235 | FD_SET(frame_fd, &set); |
236 | FD_SET(grail_fd, &set); |
237 | |
238 | - set_timeout(grail_handle, display, server_time_counter); |
239 | + set_timeout(grail_handle, display, alarm); |
240 | |
241 | ret = select(nfds, &set, NULL, NULL, NULL); |
242 | |
243 | @@ -327,11 +327,11 @@ |
244 | |
245 | if (event.type != GenericEvent) { |
246 | /* If it's not an XI 2 event, it's a timer event */ |
247 | - if (server_time_counter >= 0) { |
248 | + if (alarm != None) { |
249 | /* Process any outstanding frame events first */ |
250 | process_frame_events(grail_handle, frame_handle, win, |
251 | subscriptions); |
252 | - update_time(grail_handle, (XSyncCounterNotifyEvent *)&event); |
253 | + update_time(grail_handle, (XSyncAlarmNotifyEvent *)&event); |
254 | } |
255 | continue; |
256 | } |
257 | @@ -364,6 +364,7 @@ |
258 | } |
259 | } |
260 | |
261 | + destroy_alarm(display, alarm); |
262 | grail_delete_v3(grail_handle); |
263 | frame_x11_delete(frame_handle); |
264 | XCloseDisplay(display); |
265 | |
266 | === modified file 'tools/grail-test-atomic.c' |
267 | --- tools/grail-test-atomic.c 2012-03-23 01:33:20 +0000 |
268 | +++ tools/grail-test-atomic.c 2012-03-30 20:02:18 +0000 |
269 | @@ -215,7 +215,7 @@ |
270 | Window win; |
271 | XIEventMask mask; |
272 | XIGrabModifiers mods = { XIAnyModifier, 0 }; |
273 | - XSyncCounter server_time_counter; |
274 | + XSyncAlarm alarm; |
275 | UFStatus frame_status; |
276 | UFHandle frame_handle; |
277 | UGStatus grail_status; |
278 | @@ -265,7 +265,7 @@ |
279 | |
280 | nfds = ConnectionNumber(display) + 1; |
281 | |
282 | - server_time_counter = get_server_time_counter(display); |
283 | + alarm = create_alarm(display); |
284 | |
285 | mask.deviceid = XIAllMasterDevices; |
286 | mask.mask_len = XIMaskLen(XI_LASTEVENT); |
287 | @@ -321,7 +321,7 @@ |
288 | FD_SET(frame_fd, &set); |
289 | FD_SET(grail_fd, &set); |
290 | |
291 | - set_timeout(grail_handle, display, server_time_counter); |
292 | + set_timeout(grail_handle, display, alarm); |
293 | |
294 | ret = select(nfds, &set, NULL, NULL, NULL); |
295 | |
296 | @@ -342,11 +342,11 @@ |
297 | |
298 | if (event.type != GenericEvent) { |
299 | /* If it's not an XI 2 event, it's a timer event */ |
300 | - if (server_time_counter >= 0) { |
301 | + if (alarm != None) { |
302 | /* Process any outstanding frame events first */ |
303 | process_frame_events(grail_handle, frame_handle, win, |
304 | subscriptions); |
305 | - update_time(grail_handle, (XSyncCounterNotifyEvent *)&event); |
306 | + update_time(grail_handle, (XSyncAlarmNotifyEvent *)&event); |
307 | } |
308 | continue; |
309 | } |
310 | @@ -379,6 +379,7 @@ |
311 | } |
312 | } |
313 | |
314 | + destroy_alarm(display, alarm); |
315 | grail_delete_v3(grail_handle); |
316 | frame_x11_delete(frame_handle); |
317 | XCloseDisplay(display); |
318 | |
319 | === modified file 'tools/grail-test-edge.c' |
320 | --- tools/grail-test-edge.c 2012-03-23 01:33:20 +0000 |
321 | +++ tools/grail-test-edge.c 2012-03-30 20:02:18 +0000 |
322 | @@ -226,7 +226,7 @@ |
323 | Window win; |
324 | XIEventMask mask; |
325 | XIGrabModifiers mods = { XIAnyModifier, 0 }; |
326 | - XSyncCounter server_time_counter; |
327 | + XSyncAlarm alarm; |
328 | UFStatus frame_status; |
329 | UFHandle frame_handle; |
330 | UGStatus grail_status; |
331 | @@ -264,7 +264,7 @@ |
332 | |
333 | win = DefaultRootWindow(display); |
334 | |
335 | - server_time_counter = get_server_time_counter(display); |
336 | + alarm = create_alarm(display); |
337 | |
338 | mask.deviceid = XIAllMasterDevices; |
339 | mask.mask_len = XIMaskLen(XI_LASTEVENT); |
340 | @@ -320,7 +320,7 @@ |
341 | FD_SET(frame_fd, &set); |
342 | FD_SET(grail_fd, &set); |
343 | |
344 | - set_timeout(grail_handle, display, server_time_counter); |
345 | + set_timeout(grail_handle, display, alarm); |
346 | |
347 | ret = select(nfds, &set, NULL, NULL, NULL); |
348 | |
349 | @@ -341,11 +341,11 @@ |
350 | |
351 | if (event.type != GenericEvent) { |
352 | /* If it's not an XI 2 event, it's probably a timer event */ |
353 | - if (server_time_counter >= 0) { |
354 | + if (alarm != None) { |
355 | /* Process any outstanding frame events first */ |
356 | process_frame_events(grail_handle, frame_handle, win, |
357 | subscriptions); |
358 | - update_time(grail_handle, (XSyncCounterNotifyEvent *)&event); |
359 | + update_time(grail_handle, (XSyncAlarmNotifyEvent *)&event); |
360 | } |
361 | continue; |
362 | } |
363 | @@ -378,6 +378,7 @@ |
364 | } |
365 | } |
366 | |
367 | + destroy_alarm(display, alarm); |
368 | grail_delete_v3(grail_handle); |
369 | frame_x11_delete(frame_handle); |
370 | XCloseDisplay(display); |
371 | |
372 | === modified file 'tools/grail-test-propagation.c' |
373 | --- tools/grail-test-propagation.c 2012-03-23 01:33:20 +0000 |
374 | +++ tools/grail-test-propagation.c 2012-03-30 20:02:18 +0000 |
375 | @@ -184,7 +184,7 @@ |
376 | Window win; |
377 | XIEventMask mask; |
378 | XIGrabModifiers mods = { XIAnyModifier, 0 }; |
379 | - XSyncCounter server_time_counter; |
380 | + XSyncAlarm alarm; |
381 | UFStatus frame_status; |
382 | UFHandle frame_handle; |
383 | UGStatus grail_status; |
384 | @@ -232,7 +232,7 @@ |
385 | |
386 | nfds = ConnectionNumber(display) + 1; |
387 | |
388 | - server_time_counter = get_server_time_counter(display); |
389 | + alarm = create_alarm(display); |
390 | |
391 | mask.deviceid = XIAllMasterDevices; |
392 | mask.mask_len = XIMaskLen(XI_LASTEVENT); |
393 | @@ -288,7 +288,7 @@ |
394 | FD_SET(frame_fd, &set); |
395 | FD_SET(grail_fd, &set); |
396 | |
397 | - set_timeout(grail_handle, display, server_time_counter); |
398 | + set_timeout(grail_handle, display, alarm); |
399 | |
400 | ret = select(nfds, &set, NULL, NULL, NULL); |
401 | |
402 | @@ -309,11 +309,11 @@ |
403 | |
404 | if (event.type != GenericEvent) { |
405 | /* If it's not an XI 2 event, it's probably a timer event */ |
406 | - if (server_time_counter >= 0) { |
407 | + if (alarm != None) { |
408 | /* Process any outstanding frame events first */ |
409 | process_frame_events(grail_handle, frame_handle, win, |
410 | subscriptions); |
411 | - update_time(grail_handle, (XSyncCounterNotifyEvent *)&event); |
412 | + update_time(grail_handle, (XSyncAlarmNotifyEvent *)&event); |
413 | } |
414 | continue; |
415 | } |
416 | @@ -346,6 +346,7 @@ |
417 | } |
418 | } |
419 | |
420 | + destroy_alarm(display, alarm); |
421 | grail_delete_v3(grail_handle); |
422 | frame_x11_delete(frame_handle); |
423 | XCloseDisplay(display); |
+ attrs.state = XSyncAlarmInactive;
Documentation says "client cannot set this"