summaryrefslogtreecommitdiff
path: root/src/core/wee-util.c
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2007-12-14 17:01:02 +0100
committerSebastien Helleu <flashcode@flashtux.org>2007-12-14 17:01:02 +0100
commite62ec5204c7061a83860fa6c6c8204414a2dd057 (patch)
tree122d8931668748e0bb445d7378be050ebcf22801 /src/core/wee-util.c
parent70e44d3c548c9c6856f0fd0d07c22df88817273b (diff)
downloadweechat-e62ec5204c7061a83860fa6c6c8204414a2dd057.zip
Improved main loop (less CPU usage), better precision for timers, use of one list by hook type (for fast search in hooks)
Diffstat (limited to 'src/core/wee-util.c')
-rw-r--r--src/core/wee-util.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/core/wee-util.c b/src/core/wee-util.c
index b9238e5d3..e737c7592 100644
--- a/src/core/wee-util.c
+++ b/src/core/wee-util.c
@@ -37,6 +37,27 @@
/*
+ * util_timeval_cmp: compare two timeval structures
+ * return: -1 if tv1 < tv2
+ * 0 if tv1 == tv2
+ * 1 if tv1 > tv2
+ */
+
+int
+util_timeval_cmp (struct timeval *tv1, struct timeval *tv2)
+{
+ if (tv1->tv_sec < tv2->tv_sec)
+ return -1;
+ if (tv1->tv_sec > tv2->tv_sec)
+ return 1;
+ if (tv1->tv_usec < tv2->tv_usec)
+ return -1;
+ if (tv1->tv_usec > tv2->tv_usec)
+ return 1;
+ return 0;
+}
+
+/*
* util_timeval_diff: calculates difference between two times (return in
* milliseconds)
*/
@@ -58,6 +79,26 @@ util_timeval_diff (struct timeval *tv1, struct timeval *tv2)
}
/*
+ * util_timeval_add: add interval (in milliseconds) to a timeval struct
+ */
+
+void
+util_timeval_add (struct timeval *tv, long interval)
+{
+ long usec;
+
+ tv->tv_sec += (interval / 1000);
+ usec = tv->tv_usec + ((interval % 1000) * 1000);
+ if (usec > 1000000)
+ {
+ tv->tv_usec = usec % 1000000;
+ tv->tv_sec++;
+ }
+ else
+ tv->tv_usec = usec;
+}
+
+/*
* util_get_time_length: calculates time length with a time format
*/