diff options
| author | Eli Zaretskii | 2012-10-28 19:42:52 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2012-10-28 19:42:52 +0200 |
| commit | 640bf8ad44027d37f917d0927e50c2dfea254917 (patch) | |
| tree | 19953e299a16d30ef5357549c3a753a320228074 /src | |
| parent | 64ccff5f0ed8f0347b30e8fb4bd9b18a6cbaf1c0 (diff) | |
| download | emacs-640bf8ad44027d37f917d0927e50c2dfea254917.tar.gz emacs-640bf8ad44027d37f917d0927e50c2dfea254917.zip | |
Don't use CLOCKS_PER_SEC in w32 timers.
src/w32proc.c (TIMER_TICKS_PER_SEC): New macro.
(timer_loop, getitimer, setitimer): Use it instead of
CLOCKS_PER_SEC, which is no longer pertinent, since we don't use
'clock'.
(w32_get_timer_time): Use 10*TIMER_TICKS_PER_SEC instead of a
literal 10000.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 9 | ||||
| -rw-r--r-- | src/w32proc.c | 39 |
2 files changed, 31 insertions, 17 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index d2c16fa8310..beec867d333 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2012-10-28 Eli Zaretskii <eliz@gnu.org> | ||
| 2 | |||
| 3 | * w32proc.c (TIMER_TICKS_PER_SEC): New macro. | ||
| 4 | (timer_loop, getitimer, setitimer): Use it instead of | ||
| 5 | CLOCKS_PER_SEC, which is no longer pertinent, since we don't use | ||
| 6 | 'clock'. | ||
| 7 | (w32_get_timer_time): Use 10*TIMER_TICKS_PER_SEC instead of a | ||
| 8 | literal 10000. | ||
| 9 | |||
| 1 | 2012-10-28 Jan Djärv <jan.h.d@swipnet.se> | 10 | 2012-10-28 Jan Djärv <jan.h.d@swipnet.se> |
| 2 | 11 | ||
| 3 | * nsterm.m (NO_APPDEFINED_DATA): New define. | 12 | * nsterm.m (NO_APPDEFINED_DATA): New define. |
diff --git a/src/w32proc.c b/src/w32proc.c index e2187d52425..d45d9879a24 100644 --- a/src/w32proc.c +++ b/src/w32proc.c | |||
| @@ -272,6 +272,9 @@ typedef BOOL (WINAPI *GetThreadTimes_Proc) ( | |||
| 272 | 272 | ||
| 273 | static GetThreadTimes_Proc s_pfn_Get_Thread_Times; | 273 | static GetThreadTimes_Proc s_pfn_Get_Thread_Times; |
| 274 | 274 | ||
| 275 | #define MAX_SINGLE_SLEEP 30 | ||
| 276 | #define TIMER_TICKS_PER_SEC 1000 | ||
| 277 | |||
| 275 | /* Return a suitable time value, in 1-ms units, for THREAD, a handle | 278 | /* Return a suitable time value, in 1-ms units, for THREAD, a handle |
| 276 | to a thread. If THREAD is NULL or an invalid handle, return the | 279 | to a thread. If THREAD is NULL or an invalid handle, return the |
| 277 | current wall-clock time since January 1, 1601 (UTC). Otherwise, | 280 | current wall-clock time since January 1, 1601 (UTC). Otherwise, |
| @@ -282,6 +285,8 @@ w32_get_timer_time (HANDLE thread) | |||
| 282 | { | 285 | { |
| 283 | ULONGLONG retval; | 286 | ULONGLONG retval; |
| 284 | int use_system_time = 1; | 287 | int use_system_time = 1; |
| 288 | /* The functions below return times in 100-ns units. */ | ||
| 289 | const int tscale = 10 * TIMER_TICKS_PER_SEC; | ||
| 285 | 290 | ||
| 286 | if (thread && thread != INVALID_HANDLE_VALUE | 291 | if (thread && thread != INVALID_HANDLE_VALUE |
| 287 | && s_pfn_Get_Thread_Times != NULL) | 292 | && s_pfn_Get_Thread_Times != NULL) |
| @@ -300,8 +305,8 @@ w32_get_timer_time (HANDLE thread) | |||
| 300 | temp_user.LowPart = user_ftime.dwLowDateTime; | 305 | temp_user.LowPart = user_ftime.dwLowDateTime; |
| 301 | temp_user.HighPart = user_ftime.dwHighDateTime; | 306 | temp_user.HighPart = user_ftime.dwHighDateTime; |
| 302 | retval = | 307 | retval = |
| 303 | temp_creation.QuadPart / 10000 + temp_kernel.QuadPart / 10000 | 308 | temp_creation.QuadPart / tscale + temp_kernel.QuadPart / tscale |
| 304 | + temp_user.QuadPart / 10000; | 309 | + temp_user.QuadPart / tscale; |
| 305 | } | 310 | } |
| 306 | else | 311 | else |
| 307 | DebPrint (("GetThreadTimes failed with error code %lu\n", | 312 | DebPrint (("GetThreadTimes failed with error code %lu\n", |
| @@ -318,14 +323,12 @@ w32_get_timer_time (HANDLE thread) | |||
| 318 | temp.LowPart = current_ftime.dwLowDateTime; | 323 | temp.LowPart = current_ftime.dwLowDateTime; |
| 319 | temp.HighPart = current_ftime.dwHighDateTime; | 324 | temp.HighPart = current_ftime.dwHighDateTime; |
| 320 | 325 | ||
| 321 | retval = temp.QuadPart / 10000; | 326 | retval = temp.QuadPart / tscale; |
| 322 | } | 327 | } |
| 323 | 328 | ||
| 324 | return retval; | 329 | return retval; |
| 325 | } | 330 | } |
| 326 | 331 | ||
| 327 | #define MAX_SINGLE_SLEEP 30 | ||
| 328 | |||
| 329 | /* Thread function for a timer thread. */ | 332 | /* Thread function for a timer thread. */ |
| 330 | static DWORD WINAPI | 333 | static DWORD WINAPI |
| 331 | timer_loop (LPVOID arg) | 334 | timer_loop (LPVOID arg) |
| @@ -334,7 +337,7 @@ timer_loop (LPVOID arg) | |||
| 334 | int which = itimer->type; | 337 | int which = itimer->type; |
| 335 | int sig = (which == ITIMER_REAL) ? SIGALRM : SIGPROF; | 338 | int sig = (which == ITIMER_REAL) ? SIGALRM : SIGPROF; |
| 336 | CRITICAL_SECTION *crit = (which == ITIMER_REAL) ? &crit_real : &crit_prof; | 339 | CRITICAL_SECTION *crit = (which == ITIMER_REAL) ? &crit_real : &crit_prof; |
| 337 | const DWORD max_sleep = MAX_SINGLE_SLEEP * 1000 / CLOCKS_PER_SEC; | 340 | const DWORD max_sleep = MAX_SINGLE_SLEEP * 1000 / TIMER_TICKS_PER_SEC; |
| 338 | HANDLE hth = (which == ITIMER_REAL) ? NULL : itimer->caller_thread; | 341 | HANDLE hth = (which == ITIMER_REAL) ? NULL : itimer->caller_thread; |
| 339 | 342 | ||
| 340 | while (1) | 343 | while (1) |
| @@ -379,7 +382,7 @@ timer_loop (LPVOID arg) | |||
| 379 | return 0; | 382 | return 0; |
| 380 | if (sleep_time > 0) | 383 | if (sleep_time > 0) |
| 381 | { | 384 | { |
| 382 | Sleep (sleep_time * 1000 / CLOCKS_PER_SEC); | 385 | Sleep (sleep_time * 1000 / TIMER_TICKS_PER_SEC); |
| 383 | /* Always sleep past the expiration time, to make sure we | 386 | /* Always sleep past the expiration time, to make sure we |
| 384 | never call the handler _before_ the expiration time, | 387 | never call the handler _before_ the expiration time, |
| 385 | always slightly after it. Sleep(5) makes sure we don't | 388 | always slightly after it. Sleep(5) makes sure we don't |
| @@ -629,11 +632,13 @@ getitimer (int which, struct itimerval *value) | |||
| 629 | if (expire) | 632 | if (expire) |
| 630 | expire -= ticks_now; | 633 | expire -= ticks_now; |
| 631 | 634 | ||
| 632 | value->it_value.tv_sec = expire / CLOCKS_PER_SEC; | 635 | value->it_value.tv_sec = expire / TIMER_TICKS_PER_SEC; |
| 633 | usecs = (expire % CLOCKS_PER_SEC) * (__int64)1000000 / CLOCKS_PER_SEC; | 636 | usecs = |
| 637 | (expire % TIMER_TICKS_PER_SEC) * (__int64)1000000 / TIMER_TICKS_PER_SEC; | ||
| 634 | value->it_value.tv_usec = usecs; | 638 | value->it_value.tv_usec = usecs; |
| 635 | value->it_interval.tv_sec = reload / CLOCKS_PER_SEC; | 639 | value->it_interval.tv_sec = reload / TIMER_TICKS_PER_SEC; |
| 636 | usecs = (reload % CLOCKS_PER_SEC) * (__int64)1000000 / CLOCKS_PER_SEC; | 640 | usecs = |
| 641 | (reload % TIMER_TICKS_PER_SEC) * (__int64)1000000 / TIMER_TICKS_PER_SEC; | ||
| 637 | value->it_interval.tv_usec= usecs; | 642 | value->it_interval.tv_usec= usecs; |
| 638 | 643 | ||
| 639 | return 0; | 644 | return 0; |
| @@ -690,26 +695,26 @@ setitimer(int which, struct itimerval *value, struct itimerval *ovalue) | |||
| 690 | return 0; | 695 | return 0; |
| 691 | } | 696 | } |
| 692 | 697 | ||
| 693 | reload = value->it_interval.tv_sec * CLOCKS_PER_SEC; | 698 | reload = value->it_interval.tv_sec * TIMER_TICKS_PER_SEC; |
| 694 | 699 | ||
| 695 | usecs = value->it_interval.tv_usec; | 700 | usecs = value->it_interval.tv_usec; |
| 696 | if (value->it_interval.tv_sec == 0 | 701 | if (value->it_interval.tv_sec == 0 |
| 697 | && usecs && usecs * CLOCKS_PER_SEC < clocks_min * 1000000) | 702 | && usecs && usecs * TIMER_TICKS_PER_SEC < clocks_min * 1000000) |
| 698 | reload = clocks_min; | 703 | reload = clocks_min; |
| 699 | else | 704 | else |
| 700 | { | 705 | { |
| 701 | usecs *= CLOCKS_PER_SEC; | 706 | usecs *= TIMER_TICKS_PER_SEC; |
| 702 | reload += usecs / 1000000; | 707 | reload += usecs / 1000000; |
| 703 | } | 708 | } |
| 704 | 709 | ||
| 705 | expire = value->it_value.tv_sec * CLOCKS_PER_SEC; | 710 | expire = value->it_value.tv_sec * TIMER_TICKS_PER_SEC; |
| 706 | usecs = value->it_value.tv_usec; | 711 | usecs = value->it_value.tv_usec; |
| 707 | if (value->it_value.tv_sec == 0 | 712 | if (value->it_value.tv_sec == 0 |
| 708 | && usecs * CLOCKS_PER_SEC < clocks_min * 1000000) | 713 | && usecs * TIMER_TICKS_PER_SEC < clocks_min * 1000000) |
| 709 | expire = clocks_min; | 714 | expire = clocks_min; |
| 710 | else | 715 | else |
| 711 | { | 716 | { |
| 712 | usecs *= CLOCKS_PER_SEC; | 717 | usecs *= TIMER_TICKS_PER_SEC; |
| 713 | expire += usecs / 1000000; | 718 | expire += usecs / 1000000; |
| 714 | } | 719 | } |
| 715 | 720 | ||