From 618c44a3534e738138455caba68c925eb39f94e3 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 20 Oct 2013 21:30:55 +0200 Subject: [PATCH] utils channel: Changed abstime argument to a timeout. --- src/include/utils/channel.h | 5 ++--- src/utils/channel.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/include/utils/channel.h b/src/include/utils/channel.h index ca450ce..e1b3f0e 100644 --- a/src/include/utils/channel.h +++ b/src/include/utils/channel.h @@ -101,9 +101,8 @@ sdb_channel_read(sdb_channel_t *chan, void *data); * to the channel. If non-NULL, the value pointed to by the 'want...' * arguments will be "true" iff the respective operation is ready. If the * '..._data' arguments are non-NULL, the respective operation is executed - * atomically once the channel is ready for it. If 'abstime' is specified, the - * operation will time out with an error if the specified absolute time has - * passed. + * atomically once the channel is ready for it. If 'timeout' is specified, the + * operation will time out with an error after the specified time has passed. */ int sdb_channel_select(sdb_channel_t *chan, int *wantread, void *read_data, diff --git a/src/utils/channel.c b/src/utils/channel.c index 22e31a8..92d793e 100644 --- a/src/utils/channel.c +++ b/src/utils/channel.c @@ -32,6 +32,8 @@ #include #include +#include + #include /* @@ -165,6 +167,7 @@ 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) @@ -173,6 +176,14 @@ sdb_channel_select(sdb_channel_t *chan, int *wantread, void *read_data, if ((! wantread) && (! read_data) && (! wantwrite) && (! write_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; @@ -193,7 +204,7 @@ sdb_channel_select(sdb_channel_t *chan, int *wantread, void *read_data, if (timeout) status = pthread_cond_timedwait(&chan->cond, &chan->lock, - timeout); + &abstime); else status = pthread_cond_wait(&chan->cond, &chan->lock); } -- 2.30.2