Revision 691a0c9c qemu-timer.c
b/qemu-timer.c | ||
---|---|---|
150 | 150 |
int enabled; |
151 | 151 |
|
152 | 152 |
QEMUTimer *warp_timer; |
153 |
|
|
154 |
NotifierList reset_notifiers; |
|
155 |
int64_t last; |
|
153 | 156 |
}; |
154 | 157 |
|
155 | 158 |
struct QEMUTimer { |
... | ... | |
376 | 379 |
static QEMUClock *qemu_new_clock(int type) |
377 | 380 |
{ |
378 | 381 |
QEMUClock *clock; |
382 |
|
|
379 | 383 |
clock = qemu_mallocz(sizeof(QEMUClock)); |
380 | 384 |
clock->type = type; |
381 | 385 |
clock->enabled = 1; |
386 |
notifier_list_init(&clock->reset_notifiers); |
|
387 |
/* required to detect & report backward jumps */ |
|
388 |
if (type == QEMU_CLOCK_HOST) { |
|
389 |
clock->last = get_clock_realtime(); |
|
390 |
} |
|
382 | 391 |
return clock; |
383 | 392 |
} |
384 | 393 |
|
... | ... | |
593 | 602 |
|
594 | 603 |
int64_t qemu_get_clock_ns(QEMUClock *clock) |
595 | 604 |
{ |
605 |
int64_t now, last; |
|
606 |
|
|
596 | 607 |
switch(clock->type) { |
597 | 608 |
case QEMU_CLOCK_REALTIME: |
598 | 609 |
return get_clock(); |
... | ... | |
604 | 615 |
return cpu_get_clock(); |
605 | 616 |
} |
606 | 617 |
case QEMU_CLOCK_HOST: |
607 |
return get_clock_realtime(); |
|
618 |
now = get_clock_realtime(); |
|
619 |
last = clock->last; |
|
620 |
clock->last = now; |
|
621 |
if (now < last) { |
|
622 |
notifier_list_notify(&clock->reset_notifiers, &now); |
|
623 |
} |
|
624 |
return now; |
|
608 | 625 |
} |
609 | 626 |
} |
610 | 627 |
|
628 |
void qemu_register_clock_reset_notifier(QEMUClock *clock, Notifier *notifier) |
|
629 |
{ |
|
630 |
notifier_list_add(&clock->reset_notifiers, notifier); |
|
631 |
} |
|
632 |
|
|
633 |
void qemu_unregister_clock_reset_notifier(QEMUClock *clock, Notifier *notifier) |
|
634 |
{ |
|
635 |
notifier_list_remove(&clock->reset_notifiers, notifier); |
|
636 |
} |
|
637 |
|
|
611 | 638 |
void init_clocks(void) |
612 | 639 |
{ |
613 | 640 |
rt_clock = qemu_new_clock(QEMU_CLOCK_REALTIME); |
Also available in: Unified diff