From ace917bddb2ed2448a97ddf279445bb581c5cd32 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 1 Oct 2012 23:09:30 +0200 Subject: [PATCH] Fix high CPU usage in profiling on MS-Windows. src/w32proc.c (timer_loop): Fix code that waits for timer expiration, to avoid high CPU usage. --- src/ChangeLog | 5 +++++ src/w32proc.c | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index ee7543a2830..7061038fdec 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2012-10-01 Eli Zaretskii + + * w32proc.c (timer_loop): Fix code that waits for timer + expiration, to avoid high CPU usage. + 2012-10-01 Stefan Monnier * fns.c (check_hash_table, get_key_arg, maybe_resize_hash_table) diff --git a/src/w32proc.c b/src/w32proc.c index 4c20ca13379..58e6117a7e8 100644 --- a/src/w32proc.c +++ b/src/w32proc.c @@ -333,11 +333,11 @@ timer_loop (LPVOID arg) Sleep (sleep_time * 1000 / CLOCKS_PER_SEC); /* Always sleep past the expiration time, to make sure we never call the handler _before_ the expiration time, - always slightly after it. Sleep(0) relinquishes the rest - of the scheduled slot, so that we let other threads - work. */ + always slightly after it. Sleep(5) makes sure we don't + hog the CPU by calling 'clock' with high frequency, and + also let other threads work. */ while (clock () < expire) - Sleep (0); + Sleep (5); } if (itimer->expire == 0) -- 2.39.2