From dd9a22a959e81398c7d8c513d36a3e7f08b47d21 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 20 Oct 2013 21:56:44 +0200 Subject: [PATCH] utils channel: Update timeout in channel_select when needed. --- src/utils/channel.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/utils/channel.c b/src/utils/channel.c index afce6f5..6db9b95 100644 --- a/src/utils/channel.c +++ b/src/utils/channel.c @@ -169,7 +169,6 @@ int sdb_channel_select(sdb_channel_t *chan, int *wantread, void *read_data, int *wantwrite, void *write_data, const struct timespec *timeout) { - struct timespec abstime; int status = 0; if (! chan) { @@ -182,14 +181,6 @@ sdb_channel_select(sdb_channel_t *chan, int *wantread, void *read_data, return -1; } - if (timeout) { - if (clock_gettime(CLOCK_REALTIME, &abstime)) - return -1; - - abstime.tv_sec += timeout->tv_sec; - abstime.tv_nsec += timeout->tv_nsec; - } - pthread_mutex_lock(&chan->lock); while (! status) { int read_status, write_status; @@ -208,9 +199,18 @@ sdb_channel_select(sdb_channel_t *chan, int *wantread, void *read_data, break; } - if (timeout) + if (timeout) { + struct timespec abstime; + + if (clock_gettime(CLOCK_REALTIME, &abstime)) + return -1; + + abstime.tv_sec += timeout->tv_sec; + abstime.tv_nsec += timeout->tv_nsec; + status = pthread_cond_timedwait(&chan->cond, &chan->lock, &abstime); + } else status = pthread_cond_wait(&chan->cond, &chan->lock); } -- 2.30.2