emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r110706: Don't use CLOCKS_PER_SEC in


From: Eli Zaretskii
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r110706: Don't use CLOCKS_PER_SEC in w32 timers.
Date: Sun, 28 Oct 2012 19:42:52 +0200
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 110706
committer: Eli Zaretskii <address@hidden>
branch nick: trunk
timestamp: Sun 2012-10-28 19:42:52 +0200
message:
  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.
modified:
  src/ChangeLog
  src/w32proc.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-10-28 16:10:06 +0000
+++ b/src/ChangeLog     2012-10-28 17:42:52 +0000
@@ -1,3 +1,12 @@
+2012-10-28  Eli Zaretskii  <address@hidden>
+
+       * 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.
+
 2012-10-28  Jan Djärv  <address@hidden>
 
        * nsterm.m (NO_APPDEFINED_DATA): New define.

=== modified file 'src/w32proc.c'
--- a/src/w32proc.c     2012-10-27 19:43:48 +0000
+++ b/src/w32proc.c     2012-10-28 17:42:52 +0000
@@ -272,6 +272,9 @@
 
 static GetThreadTimes_Proc s_pfn_Get_Thread_Times;
 
+#define MAX_SINGLE_SLEEP    30
+#define TIMER_TICKS_PER_SEC 1000
+
 /* Return a suitable time value, in 1-ms units, for THREAD, a handle
    to a thread.  If THREAD is NULL or an invalid handle, return the
    current wall-clock time since January 1, 1601 (UTC).  Otherwise,
@@ -282,6 +285,8 @@
 {
   ULONGLONG retval;
   int use_system_time = 1;
+  /* The functions below return times in 100-ns units.  */
+  const int tscale = 10 * TIMER_TICKS_PER_SEC;
 
   if (thread && thread != INVALID_HANDLE_VALUE
       && s_pfn_Get_Thread_Times != NULL)
@@ -300,8 +305,8 @@
          temp_user.LowPart = user_ftime.dwLowDateTime;
          temp_user.HighPart = user_ftime.dwHighDateTime;
          retval =
-           temp_creation.QuadPart / 10000 + temp_kernel.QuadPart / 10000
-           + temp_user.QuadPart / 10000;
+           temp_creation.QuadPart / tscale + temp_kernel.QuadPart / tscale
+           + temp_user.QuadPart / tscale;
        }
       else
        DebPrint (("GetThreadTimes failed with error code %lu\n",
@@ -318,14 +323,12 @@
       temp.LowPart = current_ftime.dwLowDateTime;
       temp.HighPart = current_ftime.dwHighDateTime;
 
-      retval = temp.QuadPart / 10000;
+      retval = temp.QuadPart / tscale;
     }
 
   return retval;
 }
 
-#define MAX_SINGLE_SLEEP 30
-
 /* Thread function for a timer thread.  */
 static DWORD WINAPI
 timer_loop (LPVOID arg)
@@ -334,7 +337,7 @@
   int which = itimer->type;
   int sig = (which == ITIMER_REAL) ? SIGALRM : SIGPROF;
   CRITICAL_SECTION *crit = (which == ITIMER_REAL) ? &crit_real : &crit_prof;
-  const DWORD max_sleep = MAX_SINGLE_SLEEP * 1000 / CLOCKS_PER_SEC;
+  const DWORD max_sleep = MAX_SINGLE_SLEEP * 1000 / TIMER_TICKS_PER_SEC;
   HANDLE hth = (which == ITIMER_REAL) ? NULL : itimer->caller_thread;
 
   while (1)
@@ -379,7 +382,7 @@
        return 0;
       if (sleep_time > 0)
        {
-         Sleep (sleep_time * 1000 / CLOCKS_PER_SEC);
+         Sleep (sleep_time * 1000 / TIMER_TICKS_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(5) makes sure we don't
@@ -629,11 +632,13 @@
   if (expire)
     expire -= ticks_now;
 
-  value->it_value.tv_sec    = expire / CLOCKS_PER_SEC;
-  usecs = (expire % CLOCKS_PER_SEC) * (__int64)1000000 / CLOCKS_PER_SEC;
+  value->it_value.tv_sec    = expire / TIMER_TICKS_PER_SEC;
+  usecs =
+    (expire % TIMER_TICKS_PER_SEC) * (__int64)1000000 / TIMER_TICKS_PER_SEC;
   value->it_value.tv_usec   = usecs;
-  value->it_interval.tv_sec = reload / CLOCKS_PER_SEC;
-  usecs = (reload % CLOCKS_PER_SEC) * (__int64)1000000 / CLOCKS_PER_SEC;
+  value->it_interval.tv_sec = reload / TIMER_TICKS_PER_SEC;
+  usecs =
+    (reload % TIMER_TICKS_PER_SEC) * (__int64)1000000 / TIMER_TICKS_PER_SEC;
   value->it_interval.tv_usec= usecs;
 
   return 0;
@@ -690,26 +695,26 @@
       return 0;
     }
 
-  reload = value->it_interval.tv_sec * CLOCKS_PER_SEC;
+  reload = value->it_interval.tv_sec * TIMER_TICKS_PER_SEC;
 
   usecs = value->it_interval.tv_usec;
   if (value->it_interval.tv_sec == 0
-      && usecs && usecs * CLOCKS_PER_SEC < clocks_min * 1000000)
+      && usecs && usecs * TIMER_TICKS_PER_SEC < clocks_min * 1000000)
     reload = clocks_min;
   else
     {
-      usecs *= CLOCKS_PER_SEC;
+      usecs *= TIMER_TICKS_PER_SEC;
       reload += usecs / 1000000;
     }
 
-  expire = value->it_value.tv_sec * CLOCKS_PER_SEC;
+  expire = value->it_value.tv_sec * TIMER_TICKS_PER_SEC;
   usecs = value->it_value.tv_usec;
   if (value->it_value.tv_sec == 0
-      && usecs * CLOCKS_PER_SEC < clocks_min * 1000000)
+      && usecs * TIMER_TICKS_PER_SEC < clocks_min * 1000000)
     expire = clocks_min;
   else
     {
-      usecs *= CLOCKS_PER_SEC;
+      usecs *= TIMER_TICKS_PER_SEC;
       expire += usecs / 1000000;
     }
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]