* [Qemu-devel] [PATCH] win32: implement missing timersub
@ 2011-03-13 14:49 Blue Swirl
2011-03-13 17:00 ` Stefan Weil
0 siblings, 1 reply; 3+ messages in thread
From: Blue Swirl @ 2011-03-13 14:49 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 2198 bytes --]
Implement and wrap timersub() for Win32.
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
osdep.h | 19 +++++++++++++++++--
ui/vnc.c | 6 +++---
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/osdep.h b/osdep.h
index 27eedcf..8c45000 100644
--- a/osdep.h
+++ b/osdep.h
@@ -8,9 +8,7 @@
#include <sys/signal.h>
#endif
-#ifndef _WIN32
#include <sys/time.h>
-#endif
#ifndef glue
#define xglue(x, y) x ## y
@@ -131,4 +129,21 @@ int qemu_madvise(void *addr, size_t len, int advice);
int qemu_create_pidfile(const char *filename);
+#ifdef _WIN32
+static inline void qemu_timersub(const struct timeval *val1,
+ const struct timeval *val2,
+ struct timeval *res)
+{
+ res->tv_sec = val1->tv_sec - val2->tv_sec;
+ if (val1->tv_usec - val2->tv_usec < 0) {
+ res->tv_sec--;
+ res->tv_usec = val1->tv_usec - val2->tv_usec + 1000 * 1000;
+ } else {
+ res->tv_usec = val1->tv_usec - val2->tv_usec;
+ }
+}
+#else
+#define qemu_timersub timersub
+#endif
+
#endif
diff --git a/ui/vnc.c b/ui/vnc.c
index 34dc0cd..1b68965 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2302,7 +2302,7 @@ static int vnc_update_stats(VncDisplay *vd,
struct timeval * tv)
}
}
- timersub(tv, &VNC_REFRESH_STATS, &res);
+ qemu_timersub(tv, &VNC_REFRESH_STATS, &res);
if (timercmp(&vd->guest.last_freq_check, &res, >)) {
return has_dirty;
@@ -2320,7 +2320,7 @@ static int vnc_update_stats(VncDisplay *vd,
struct timeval * tv)
}
max = rect->times[(rect->idx + count - 1) % count];
- timersub(tv, &max, &res);
+ qemu_timersub(tv, &max, &res);
if (timercmp(&res, &VNC_REFRESH_LOSSY, >)) {
rect->freq = 0;
@@ -2331,7 +2331,7 @@ static int vnc_update_stats(VncDisplay *vd,
struct timeval * tv)
min = rect->times[rect->idx];
max = rect->times[(rect->idx + count - 1) % count];
- timersub(&max, &min, &res);
+ qemu_timersub(&max, &min, &res);
rect->freq = res.tv_sec + res.tv_usec / 1000000.;
rect->freq /= count;
--
1.6.2.4
[-- Attachment #2: 0001-win32-implement-missing-timersub.patch --]
[-- Type: text/x-diff, Size: 2504 bytes --]
From cff2dbcf5ae3fc259b78dfa2d77737ec38c6de42 Mon Sep 17 00:00:00 2001
Message-Id: <cff2dbcf5ae3fc259b78dfa2d77737ec38c6de42.1300027705.git.blauwirbel@gmail.com>
From: Blue Swirl <blauwirbel@gmail.com>
Date: Sun, 13 Mar 2011 10:30:52 +0000
Subject: [PATCH] win32: implement missing timersub
Implement and wrap timersub() for Win32.
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
osdep.h | 19 +++++++++++++++++--
ui/vnc.c | 6 +++---
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/osdep.h b/osdep.h
index 27eedcf..8c45000 100644
--- a/osdep.h
+++ b/osdep.h
@@ -8,9 +8,7 @@
#include <sys/signal.h>
#endif
-#ifndef _WIN32
#include <sys/time.h>
-#endif
#ifndef glue
#define xglue(x, y) x ## y
@@ -131,4 +129,21 @@ int qemu_madvise(void *addr, size_t len, int advice);
int qemu_create_pidfile(const char *filename);
+#ifdef _WIN32
+static inline void qemu_timersub(const struct timeval *val1,
+ const struct timeval *val2,
+ struct timeval *res)
+{
+ res->tv_sec = val1->tv_sec - val2->tv_sec;
+ if (val1->tv_usec - val2->tv_usec < 0) {
+ res->tv_sec--;
+ res->tv_usec = val1->tv_usec - val2->tv_usec + 1000 * 1000;
+ } else {
+ res->tv_usec = val1->tv_usec - val2->tv_usec;
+ }
+}
+#else
+#define qemu_timersub timersub
+#endif
+
#endif
diff --git a/ui/vnc.c b/ui/vnc.c
index 34dc0cd..1b68965 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2302,7 +2302,7 @@ static int vnc_update_stats(VncDisplay *vd, struct timeval * tv)
}
}
- timersub(tv, &VNC_REFRESH_STATS, &res);
+ qemu_timersub(tv, &VNC_REFRESH_STATS, &res);
if (timercmp(&vd->guest.last_freq_check, &res, >)) {
return has_dirty;
@@ -2320,7 +2320,7 @@ static int vnc_update_stats(VncDisplay *vd, struct timeval * tv)
}
max = rect->times[(rect->idx + count - 1) % count];
- timersub(tv, &max, &res);
+ qemu_timersub(tv, &max, &res);
if (timercmp(&res, &VNC_REFRESH_LOSSY, >)) {
rect->freq = 0;
@@ -2331,7 +2331,7 @@ static int vnc_update_stats(VncDisplay *vd, struct timeval * tv)
min = rect->times[rect->idx];
max = rect->times[(rect->idx + count - 1) % count];
- timersub(&max, &min, &res);
+ qemu_timersub(&max, &min, &res);
rect->freq = res.tv_sec + res.tv_usec / 1000000.;
rect->freq /= count;
--
1.7.2.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] win32: implement missing timersub
2011-03-13 14:49 [Qemu-devel] [PATCH] win32: implement missing timersub Blue Swirl
@ 2011-03-13 17:00 ` Stefan Weil
2011-03-15 20:52 ` Blue Swirl
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Weil @ 2011-03-13 17:00 UTC (permalink / raw)
To: Blue Swirl; +Cc: qemu-devel
Am 13.03.2011 15:49, schrieb Blue Swirl:
> Implement and wrap timersub() for Win32.
>
> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
> ---
> osdep.h | 19 +++++++++++++++++--
> ui/vnc.c | 6 +++---
> 2 files changed, 20 insertions(+), 5 deletions(-)
>
> diff --git a/osdep.h b/osdep.h
> index 27eedcf..8c45000 100644
> --- a/osdep.h
> +++ b/osdep.h
> @@ -8,9 +8,7 @@
> #include <sys/signal.h>
> #endif
>
> -#ifndef _WIN32
> #include <sys/time.h>
> -#endif
>
> #ifndef glue
> #define xglue(x, y) x ## y
> @@ -131,4 +129,21 @@ int qemu_madvise(void *addr, size_t len, int advice);
>
> int qemu_create_pidfile(const char *filename);
>
> +#ifdef _WIN32
> +static inline void qemu_timersub(const struct timeval *val1,
> + const struct timeval *val2,
> + struct timeval *res)
> +{
> + res->tv_sec = val1->tv_sec - val2->tv_sec;
> + if (val1->tv_usec - val2->tv_usec < 0) {
shorter: if (val1->tv_usec < val2->tv_usec) {
> + res->tv_sec--;
> + res->tv_usec = val1->tv_usec - val2->tv_usec + 1000 * 1000;
> + } else {
> + res->tv_usec = val1->tv_usec - val2->tv_usec;
> + }
> +}
> +#else
> +#define qemu_timersub timersub
> +#endif
> +
> #endif
> diff --git a/ui/vnc.c b/ui/vnc.c
> index 34dc0cd..1b68965 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -2302,7 +2302,7 @@ static int vnc_update_stats(VncDisplay *vd,
> struct timeval * tv)
> }
> }
>
> - timersub(tv, &VNC_REFRESH_STATS, &res);
> + qemu_timersub(tv, &VNC_REFRESH_STATS, &res);
>
> if (timercmp(&vd->guest.last_freq_check, &res, >)) {
> return has_dirty;
> @@ -2320,7 +2320,7 @@ static int vnc_update_stats(VncDisplay *vd,
> struct timeval * tv)
> }
>
> max = rect->times[(rect->idx + count - 1) % count];
> - timersub(tv, &max, &res);
> + qemu_timersub(tv, &max, &res);
>
> if (timercmp(&res, &VNC_REFRESH_LOSSY, >)) {
> rect->freq = 0;
> @@ -2331,7 +2331,7 @@ static int vnc_update_stats(VncDisplay *vd,
> struct timeval * tv)
>
> min = rect->times[rect->idx];
> max = rect->times[(rect->idx + count - 1) % count];
> - timersub(&max, &min, &res);
> + qemu_timersub(&max, &min, &res);
>
> rect->freq = res.tv_sec + res.tv_usec / 1000000.;
> rect->freq /= count;
Acked-by: Stefan Weil <weil@mail.berlios.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] win32: implement missing timersub
2011-03-13 17:00 ` Stefan Weil
@ 2011-03-15 20:52 ` Blue Swirl
0 siblings, 0 replies; 3+ messages in thread
From: Blue Swirl @ 2011-03-15 20:52 UTC (permalink / raw)
To: Stefan Weil; +Cc: qemu-devel
On Sun, Mar 13, 2011 at 7:00 PM, Stefan Weil <weil@mail.berlios.de> wrote:
> Am 13.03.2011 15:49, schrieb Blue Swirl:
>>
>> Implement and wrap timersub() for Win32.
>>
>> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
>> ---
>> osdep.h | 19 +++++++++++++++++--
>> ui/vnc.c | 6 +++---
>> 2 files changed, 20 insertions(+), 5 deletions(-)
>>
>> diff --git a/osdep.h b/osdep.h
>> index 27eedcf..8c45000 100644
>> --- a/osdep.h
>> +++ b/osdep.h
>> @@ -8,9 +8,7 @@
>> #include <sys/signal.h>
>> #endif
>>
>> -#ifndef _WIN32
>> #include <sys/time.h>
>> -#endif
>>
>> #ifndef glue
>> #define xglue(x, y) x ## y
>> @@ -131,4 +129,21 @@ int qemu_madvise(void *addr, size_t len, int advice);
>>
>> int qemu_create_pidfile(const char *filename);
>>
>> +#ifdef _WIN32
>> +static inline void qemu_timersub(const struct timeval *val1,
>> + const struct timeval *val2,
>> + struct timeval *res)
>> +{
>> + res->tv_sec = val1->tv_sec - val2->tv_sec;
>> + if (val1->tv_usec - val2->tv_usec < 0) {
>
> shorter: if (val1->tv_usec < val2->tv_usec) {
>
>> + res->tv_sec--;
>> + res->tv_usec = val1->tv_usec - val2->tv_usec + 1000 * 1000;
>> + } else {
>> + res->tv_usec = val1->tv_usec - val2->tv_usec;
>> + }
>> +}
>> +#else
>> +#define qemu_timersub timersub
>> +#endif
>> +
>> #endif
>> diff --git a/ui/vnc.c b/ui/vnc.c
>> index 34dc0cd..1b68965 100644
>> --- a/ui/vnc.c
>> +++ b/ui/vnc.c
>> @@ -2302,7 +2302,7 @@ static int vnc_update_stats(VncDisplay *vd,
>> struct timeval * tv)
>> }
>> }
>>
>> - timersub(tv, &VNC_REFRESH_STATS, &res);
>> + qemu_timersub(tv, &VNC_REFRESH_STATS, &res);
>>
>> if (timercmp(&vd->guest.last_freq_check, &res, >)) {
>> return has_dirty;
>> @@ -2320,7 +2320,7 @@ static int vnc_update_stats(VncDisplay *vd,
>> struct timeval * tv)
>> }
>>
>> max = rect->times[(rect->idx + count - 1) % count];
>> - timersub(tv, &max, &res);
>> + qemu_timersub(tv, &max, &res);
>>
>> if (timercmp(&res, &VNC_REFRESH_LOSSY, >)) {
>> rect->freq = 0;
>> @@ -2331,7 +2331,7 @@ static int vnc_update_stats(VncDisplay *vd,
>> struct timeval * tv)
>>
>> min = rect->times[rect->idx];
>> max = rect->times[(rect->idx + count - 1) % count];
>> - timersub(&max, &min, &res);
>> + qemu_timersub(&max, &min, &res);
>>
>> rect->freq = res.tv_sec + res.tv_usec / 1000000.;
>> rect->freq /= count;
>
> Acked-by: Stefan Weil <weil@mail.berlios.de>
Thanks for the ack, applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-03-15 20:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-13 14:49 [Qemu-devel] [PATCH] win32: implement missing timersub Blue Swirl
2011-03-13 17:00 ` Stefan Weil
2011-03-15 20:52 ` Blue Swirl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).