Skip to content

Commit

Permalink
qemu-timer: move timeBeginPeriod/timeEndPeriod to os-win32
Browse files Browse the repository at this point in the history
These are needed for any of the Win32 alarm timer implementations.
They are not tied to mmtimer exclusively.

Jacob tested this patch with both mmtimer and Win32 timers.

Cc: [email protected]
Tested-by: Jacob Kroon <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
bonzini authored and stweil committed Apr 12, 2013
1 parent 1046127 commit 0727b86
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
11 changes: 11 additions & 0 deletions os-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* THE SOFTWARE.
*/
#include <windows.h>
#include <mmsystem.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
Expand Down Expand Up @@ -67,9 +68,19 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)
return TRUE;
}

static TIMECAPS mm_tc;

static void os_undo_timer_resolution(void)
{
timeEndPeriod(mm_tc.wPeriodMin);
}

void os_setup_early_signal_handling(void)
{
SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
timeGetDevCaps(&mm_tc, sizeof(mm_tc));
timeBeginPeriod(mm_tc.wPeriodMin);
atexit(os_undo_timer_resolution);
}

/* Look for support files in the same directory as the executable. */
Expand Down
24 changes: 6 additions & 18 deletions qemu-timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,28 +624,14 @@ static void CALLBACK mm_alarm_handler(UINT uTimerID, UINT uMsg,
static int mm_start_timer(struct qemu_alarm_timer *t)
{
timeGetDevCaps(&mm_tc, sizeof(mm_tc));

timeBeginPeriod(mm_tc.wPeriodMin);

mm_timer = timeSetEvent(mm_tc.wPeriodMin, /* interval (ms) */
mm_tc.wPeriodMin, /* resolution */
mm_alarm_handler, /* function */
(DWORD_PTR)t, /* parameter */
TIME_ONESHOT | TIME_CALLBACK_FUNCTION);

if (!mm_timer) {
fprintf(stderr, "Failed to initialize win32 alarm timer\n");
timeEndPeriod(mm_tc.wPeriodMin);
return -1;
}

return 0;
}

static void mm_stop_timer(struct qemu_alarm_timer *t)
{
timeKillEvent(mm_timer);
timeEndPeriod(mm_tc.wPeriodMin);
if (mm_timer) {
timeKillEvent(mm_timer);
}
}

static void mm_rearm_timer(struct qemu_alarm_timer *t, int64_t delta)
Expand All @@ -657,7 +643,9 @@ static void mm_rearm_timer(struct qemu_alarm_timer *t, int64_t delta)
nearest_delta_ms = mm_tc.wPeriodMax;
}

timeKillEvent(mm_timer);
if (mm_timer) {
timeKillEvent(mm_timer);
}
mm_timer = timeSetEvent((UINT)nearest_delta_ms,
mm_tc.wPeriodMin,
mm_alarm_handler,
Expand Down

0 comments on commit 0727b86

Please sign in to comment.