1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-04 08:43:13 +02:00

api: use microseconds instead of milliseconds in functions util_timeval_diff and util_timeval_add

This commit is contained in:
Sébastien Helleu
2014-08-29 18:17:27 +02:00
parent ddd829a1c7
commit 7b546bea2e
15 changed files with 133 additions and 62 deletions
+5 -3
View File
@@ -984,7 +984,8 @@ hook_timer_init (struct t_hook *hook)
HOOK_TIMER(hook, next_exec).tv_usec = HOOK_TIMER(hook, last_exec).tv_usec;
/* add interval to next call date */
util_timeval_add (&HOOK_TIMER(hook, next_exec), HOOK_TIMER(hook, interval));
util_timeval_add (&HOOK_TIMER(hook, next_exec),
((long long)HOOK_TIMER(hook, interval)) * 1000);
}
/*
@@ -1179,8 +1180,9 @@ hook_timer_exec ()
HOOK_TIMER(ptr_hook, last_exec).tv_sec = tv_time.tv_sec;
HOOK_TIMER(ptr_hook, last_exec).tv_usec = tv_time.tv_usec;
util_timeval_add (&HOOK_TIMER(ptr_hook, next_exec),
HOOK_TIMER(ptr_hook, interval));
util_timeval_add (
&HOOK_TIMER(ptr_hook, next_exec),
((long long)HOOK_TIMER(ptr_hook, interval)) * 1000);
if (HOOK_TIMER(ptr_hook, remaining_calls) > 0)
{
+2 -2
View File
@@ -898,7 +898,7 @@ void
upgrade_weechat_end ()
{
struct timeval tv_now;
long time_diff;
long long time_diff;
/* remove .upgrade files */
util_exec_on_files (weechat_home,
@@ -912,7 +912,7 @@ upgrade_weechat_end ()
gui_chat_printf (NULL,
/* TRANSLATORS: %.02fs is a float number + "s" ("seconds") */
_("Upgrade done (%.02fs)"),
((float)time_diff) / 1000);
((float)time_diff) / 1000000);
/* upgrading ended */
weechat_upgrading = 0;
+10 -9
View File
@@ -254,13 +254,13 @@ util_timeval_cmp (struct timeval *tv1, struct timeval *tv2)
/*
* Calculates difference between two timeval structures.
*
* Returns difference in milliseconds.
* Returns difference in microseconds.
*/
long
long long
util_timeval_diff (struct timeval *tv1, struct timeval *tv2)
{
long diff_sec, diff_usec;
long long diff_sec, diff_usec;
if (!tv1 || !tv2)
return 0;
@@ -273,23 +273,24 @@ util_timeval_diff (struct timeval *tv1, struct timeval *tv2)
diff_usec += 1000000;
diff_sec--;
}
return ((diff_usec / 1000) + (diff_sec * 1000));
return (diff_sec * 1000000) + diff_usec;
}
/*
* Adds interval (in milliseconds) to a timeval structure.
* Adds interval (in microseconds) to a timeval structure.
*/
void
util_timeval_add (struct timeval *tv, long interval)
util_timeval_add (struct timeval *tv, long long interval)
{
long usec;
long long usec;
if (!tv)
return;
tv->tv_sec += (interval / 1000);
usec = tv->tv_usec + ((interval % 1000) * 1000);
tv->tv_sec += (interval / 1000000);
usec = tv->tv_usec + (interval % 1000000);
if (usec > 1000000)
{
tv->tv_usec = usec % 1000000;
+2 -2
View File
@@ -36,8 +36,8 @@ struct t_util_signal
extern void util_setrlimit ();
extern int util_timeval_cmp (struct timeval *tv1, struct timeval *tv2);
extern long util_timeval_diff (struct timeval *tv1, struct timeval *tv2);
extern void util_timeval_add (struct timeval *tv, long interval);
extern long long util_timeval_diff (struct timeval *tv1, struct timeval *tv2);
extern void util_timeval_add (struct timeval *tv, long long interval);
extern char *util_get_time_string (const time_t *date);
extern int util_signal_search (const char *name);
extern void util_catch_signal (int signum, void (*handler)(int));