summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@gmail.com>2013-09-12 19:32:07 +0200
committerFrediano Ziglio <fziglio@redhat.com>2015-10-29 18:22:19 +0000
commit39b7e55ec7a348055bc7673f7cf1086f1cb9813d (patch)
tree08011295d5ea992fc5d9fef0e61640d1211e6e5e
parent93414b23fa5d87ad94f1bd198dc3be0132d75a15 (diff)
downloadspice-39b7e55ec7a348055bc7673f7cf1086f1cb9813d.tar.gz
spice-39b7e55ec7a348055bc7673f7cf1086f1cb9813d.tar.xz
spice-39b7e55ec7a348055bc7673f7cf1086f1cb9813d.zip
Replace now() with get_mononotonic_time()
Acked-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r--server/Makefile.am1
-rw-r--r--server/display-channel.h3
-rw-r--r--server/red_channel.c16
-rw-r--r--server/red_time.h32
-rw-r--r--server/red_worker.c24
-rw-r--r--server/utils.h2
6 files changed, 22 insertions, 56 deletions
diff --git a/server/Makefile.am b/server/Makefile.am
index 87540e4a..87288ccb 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -103,7 +103,6 @@ libspice_server_la_SOURCES = \
red_replay_qxl.c \
red_replay_qxl.h \
red_parse_qxl.h \
- red_time.h \
red_worker.c \
red_worker.h \
display-channel.h \
diff --git a/server/display-channel.h b/server/display-channel.h
index fb38ee2f..e1ddc117 100644
--- a/server/display-channel.h
+++ b/server/display-channel.h
@@ -21,8 +21,7 @@
#include "red_worker.h"
#include "cache-item.h"
#include "pixmap-cache.h"
-
-typedef int64_t red_time_t;
+#include "utils.h"
typedef struct Drawable Drawable;
diff --git a/server/red_channel.c b/server/red_channel.c
index 5fc34bad..34aa9dce 100644
--- a/server/red_channel.c
+++ b/server/red_channel.c
@@ -43,7 +43,7 @@
#include "reds.h"
#include "reds_stream.h"
#include "main_dispatcher.h"
-#include "red_time.h"
+#include "utils.h"
typedef struct EmptyMsgPipeItem {
PipeItem base;
@@ -2332,7 +2332,7 @@ int red_channel_client_wait_outgoing_item(RedChannelClient *rcc,
return TRUE;
}
if (timeout != -1) {
- end_time = red_now() + timeout;
+ end_time = red_get_monotonic_time() + timeout;
} else {
end_time = UINT64_MAX;
}
@@ -2343,7 +2343,7 @@ int red_channel_client_wait_outgoing_item(RedChannelClient *rcc,
red_channel_client_receive(rcc);
red_channel_client_send(rcc);
} while ((blocked = red_channel_client_blocked(rcc)) &&
- (timeout == -1 || red_now() < end_time));
+ (timeout == -1 || red_get_monotonic_time() < end_time));
if (blocked) {
spice_warning("timeout");
@@ -2365,7 +2365,7 @@ int red_channel_client_wait_pipe_item_sent(RedChannelClient *rcc,
spice_info(NULL);
if (timeout != -1) {
- end_time = red_now() + timeout;
+ end_time = red_get_monotonic_time() + timeout;
} else {
end_time = UINT64_MAX;
}
@@ -2379,7 +2379,7 @@ int red_channel_client_wait_pipe_item_sent(RedChannelClient *rcc,
red_channel_client_push(rcc);
while((item_in_pipe = ring_item_is_linked(&item->link)) &&
- (timeout == -1 || red_now() < end_time)) {
+ (timeout == -1 || red_get_monotonic_time() < end_time)) {
usleep(CHANNEL_BLOCKED_SLEEP_DURATION);
red_channel_client_receive(rcc);
red_channel_client_send(rcc);
@@ -2392,7 +2392,7 @@ int red_channel_client_wait_pipe_item_sent(RedChannelClient *rcc,
return FALSE;
} else {
return red_channel_client_wait_outgoing_item(rcc,
- timeout == -1 ? -1 : end_time - red_now());
+ timeout == -1 ? -1 : end_time - red_get_monotonic_time());
}
}
@@ -2404,7 +2404,7 @@ int red_channel_wait_all_sent(RedChannel *channel,
int blocked = FALSE;
if (timeout != -1) {
- end_time = red_now() + timeout;
+ end_time = red_get_monotonic_time() + timeout;
} else {
end_time = UINT64_MAX;
}
@@ -2412,7 +2412,7 @@ int red_channel_wait_all_sent(RedChannel *channel,
red_channel_push(channel);
while (((max_pipe_size = red_channel_max_pipe_size(channel)) ||
(blocked = red_channel_any_blocked(channel))) &&
- (timeout == -1 || red_now() < end_time)) {
+ (timeout == -1 || red_get_monotonic_time() < end_time)) {
spice_debug("pipe-size %u blocked %d", max_pipe_size, blocked);
usleep(CHANNEL_BLOCKED_SLEEP_DURATION);
red_channel_receive(channel);
diff --git a/server/red_time.h b/server/red_time.h
deleted file mode 100644
index 94c1ba61..00000000
--- a/server/red_time.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
-/*
- Copyright (C) 2009-2015 Red Hat, Inc.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, see <http://www.gnu.org/licenses/>.
-*/
-#ifndef H_RED_TIME
-#define H_RED_TIME
-
-#include <time.h>
-
-static inline uint64_t red_now(void)
-{
- struct timespec time;
-
- clock_gettime(CLOCK_MONOTONIC, &time);
-
- return ((uint64_t) time.tv_sec) * 1000000000 + time.tv_nsec;
-}
-
-#endif
diff --git a/server/red_worker.c b/server/red_worker.c
index 11267e9f..c8e4b2ca 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -89,13 +89,11 @@
#include "spice_timer_queue.h"
#include "main_dispatcher.h"
#include "spice_server_utils.h"
-#include "red_time.h"
#include "spice_bitmap_utils.h"
#include "spice_image_cache.h"
#include "pixmap-cache.h"
#include "display-channel.h"
#include "cursor-channel.h"
-#include "utils.h"
//#define COMPRESS_STAT
//#define DUMP_BITMAP
@@ -4208,7 +4206,7 @@ static int red_process_commands(RedWorker *worker, uint32_t max_pipe_size, int *
{
QXLCommandExt ext_cmd;
int n = 0;
- uint64_t start = red_now();
+ uint64_t start = red_get_monotonic_time();
if (!worker->running) {
*ring_is_empty = TRUE;
@@ -4308,7 +4306,7 @@ static int red_process_commands(RedWorker *worker, uint32_t max_pipe_size, int *
n++;
if ((worker->display_channel &&
red_channel_all_blocked(&worker->display_channel->common.base))
- || red_now() - start > 10 * 1000 * 1000) {
+ || red_get_monotonic_time() - start > 10 * 1000 * 1000) {
worker->event_timeout = 0;
return n;
}
@@ -7806,7 +7804,7 @@ static inline int red_marshall_stream_data(RedChannelClient *rcc,
}
StreamAgent *agent = &dcc->stream_agents[get_stream_id(worker, stream)];
- uint64_t time_now = red_now();
+ uint64_t time_now = red_get_monotonic_time();
size_t outbuf_size;
if (!dcc->use_mjpeg_encoder_rate_control) {
@@ -8841,7 +8839,7 @@ static inline void flush_display_commands(RedWorker *worker)
if (ring_is_empty) {
break;
}
- end_time = red_now() + DISPLAY_CLIENT_TIMEOUT;
+ end_time = red_get_monotonic_time() + DISPLAY_CLIENT_TIMEOUT;
int sleep_count = 0;
for (;;) {
red_channel_push(&worker->display_channel->common.base);
@@ -8854,7 +8852,7 @@ static inline void flush_display_commands(RedWorker *worker)
red_channel_send(channel);
// TODO: MC: the whole timeout will break since it takes lowest timeout, should
// do it client by client.
- if (red_now() >= end_time) {
+ if (red_get_monotonic_time() >= end_time) {
spice_warning("update timeout");
red_disconnect_all_display_TODO_remove_me(channel);
} else {
@@ -8885,7 +8883,7 @@ static inline void flush_cursor_commands(RedWorker *worker)
if (ring_is_empty) {
break;
}
- end_time = red_now() + DISPLAY_CLIENT_TIMEOUT;
+ end_time = red_get_monotonic_time() + DISPLAY_CLIENT_TIMEOUT;
int sleep_count = 0;
for (;;) {
red_channel_push(&worker->cursor_channel->common.base);
@@ -8896,7 +8894,7 @@ static inline void flush_cursor_commands(RedWorker *worker)
RedChannel *channel = (RedChannel *)worker->cursor_channel;
red_channel_receive(channel);
red_channel_send(channel);
- if (red_now() >= end_time) {
+ if (red_get_monotonic_time() >= end_time) {
spice_warning("flush cursor timeout");
cursor_channel_disconnect(channel);
worker->cursor_channel = NULL;
@@ -8930,7 +8928,7 @@ static void push_new_primary_surface(DisplayChannelClient *dcc)
static int display_channel_client_wait_for_init(DisplayChannelClient *dcc)
{
dcc->expect_init = TRUE;
- uint64_t end_time = red_now() + DISPLAY_CLIENT_TIMEOUT;
+ uint64_t end_time = red_get_monotonic_time() + DISPLAY_CLIENT_TIMEOUT;
for (;;) {
red_channel_client_receive(&dcc->common.base);
if (!red_channel_client_is_connected(&dcc->common.base)) {
@@ -8946,7 +8944,7 @@ static int display_channel_client_wait_for_init(DisplayChannelClient *dcc)
}
return TRUE;
}
- if (red_now() > end_time) {
+ if (red_get_monotonic_time() > end_time) {
spice_warning("timeout");
red_channel_client_disconnect(&dcc->common.base);
break;
@@ -10398,7 +10396,7 @@ void handle_dev_stop(void *opaque, void *payload)
static int display_channel_wait_for_migrate_data(DisplayChannel *display)
{
- uint64_t end_time = red_now() + DISPLAY_CLIENT_MIGRATE_DATA_TIMEOUT;
+ uint64_t end_time = red_get_monotonic_time() + DISPLAY_CLIENT_MIGRATE_DATA_TIMEOUT;
RedChannel *channel = &display->common.base;
RedChannelClient *rcc;
@@ -10417,7 +10415,7 @@ static int display_channel_wait_for_migrate_data(DisplayChannel *display)
if (!red_channel_client_waits_for_migrate_data(rcc)) {
return TRUE;
}
- if (red_now() > end_time) {
+ if (red_get_monotonic_time() > end_time) {
spice_warning("timeout");
red_channel_client_disconnect(rcc);
break;
diff --git a/server/utils.h b/server/utils.h
index ca8b7f1d..1ebc32fc 100644
--- a/server/utils.h
+++ b/server/utils.h
@@ -20,6 +20,8 @@
#include <time.h>
+typedef int64_t red_time_t;
+
/* FIXME: consider g_get_monotonic_time (), but in microseconds */
static inline red_time_t red_get_monotonic_time(void)
{