summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 31891e0)
raw | patch | inline | side by side (parent: 31891e0)
author | Sebastian Harl <sh@tokkee.org> | |
Sun, 20 Oct 2013 19:30:55 +0000 (21:30 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sun, 20 Oct 2013 19:30:55 +0000 (21:30 +0200) |
src/include/utils/channel.h | patch | blob | history | |
src/utils/channel.c | patch | blob | history |
index ca450ce22282dc2af98b7889f7fc15189a544b86..e1b3f0e63e695f83b4ebf5d64671bf181920ff2f 100644 (file)
* 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 22e31a8b4eb0303e063ca6b3bfae2e0e8dcb19ad..92d793e468c441b044c24d76bedd2d9dc51510f0 100644 (file)
--- a/src/utils/channel.c
+++ b/src/utils/channel.c
#include <stdlib.h>
#include <string.h>
+#include <time.h>
+
#include <pthread.h>
/*
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)
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;
if (timeout)
status = pthread_cond_timedwait(&chan->cond, &chan->lock,
- timeout);
+ &abstime);
else
status = pthread_cond_wait(&chan->cond, &chan->lock);
}