Merge remote-tracking branch 'remotes/kraxel/tags/pull-ui-20161013-1' into staging
[qemu/ar7.git] / tests / ptimer-test-stubs.c
blob92a22fbb095e1c9cc7b70d72b944e66c8a34fa72
1 /*
2 * Stubs for the ptimer-test
4 * Author: Dmitry Osipenko <digetx@gmail.com>
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
9 */
11 #include "qemu/osdep.h"
12 #include "qemu/main-loop.h"
13 #include "sysemu/replay.h"
15 #include "ptimer-test.h"
17 struct QEMUBH {
18 QEMUBHFunc *cb;
19 void *opaque;
22 QEMUTimerListGroup main_loop_tlg;
24 int64_t ptimer_test_time_ns;
26 void timer_init_tl(QEMUTimer *ts,
27 QEMUTimerList *timer_list, int scale,
28 QEMUTimerCB *cb, void *opaque)
30 ts->timer_list = timer_list;
31 ts->cb = cb;
32 ts->opaque = opaque;
33 ts->scale = scale;
34 ts->expire_time = -1;
37 void timer_mod(QEMUTimer *ts, int64_t expire_time)
39 QEMUTimerList *timer_list = ts->timer_list;
40 QEMUTimer *t = &timer_list->active_timers;
42 while (t->next != NULL) {
43 if (t->next == ts) {
44 break;
47 t = t->next;
50 ts->expire_time = MAX(expire_time * ts->scale, 0);
51 ts->next = NULL;
52 t->next = ts;
55 void timer_del(QEMUTimer *ts)
57 QEMUTimerList *timer_list = ts->timer_list;
58 QEMUTimer *t = &timer_list->active_timers;
60 while (t->next != NULL) {
61 if (t->next == ts) {
62 t->next = ts->next;
63 return;
66 t = t->next;
70 int64_t qemu_clock_get_ns(QEMUClockType type)
72 return ptimer_test_time_ns;
75 int64_t qemu_clock_deadline_ns_all(QEMUClockType type)
77 QEMUTimerList *timer_list = main_loop_tlg.tl[type];
78 QEMUTimer *t = timer_list->active_timers.next;
79 int64_t deadline = -1;
81 while (t != NULL) {
82 if (deadline == -1) {
83 deadline = t->expire_time;
84 } else {
85 deadline = MIN(deadline, t->expire_time);
88 t = t->next;
91 return deadline;
94 QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
96 QEMUBH *bh = g_new(QEMUBH, 1);
98 bh->cb = cb;
99 bh->opaque = opaque;
101 return bh;
104 void replay_bh_schedule_event(QEMUBH *bh)
106 bh->cb(bh->opaque);