X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Futils%2Fchannel.c;h=6db9b9512310b8d626ea12f73e33e90a5ff3d34e;hb=dd9a22a959e81398c7d8c513d36a3e7f08b47d21;hp=afce6f5d9cc9aa883afb9569aef9a384c433eb01;hpb=23c8e0f818e5baf91e75993571b67fcb735628f5;p=sysdb.git 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); }