diff --git a/src/utils/channel.c b/src/utils/channel.c
index 6db9b9512310b8d626ea12f73e33e90a5ff3d34e..7c5c002ae545f43901e5b9dab352329936218b67 100644 (file)
--- a/src/utils/channel.c
+++ b/src/utils/channel.c
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif /* HAVE_CONFIG_H */
+
#include "utils/channel.h"
#include <assert.h>
size_t head;
size_t tail;
_Bool full;
+
+ _Bool shutdown;
};
/*
{
assert(chan);
- if (chan->full)
+ if (chan->full || chan->shutdown)
return -1;
else if (! data)
return 0;
break;
}
+ if (chan->shutdown) {
+ if (read_status)
+ status = EBADF;
+ break;
+ }
+
if (timeout) {
struct timespec abstime;
- if (clock_gettime(CLOCK_REALTIME, &abstime))
+ if (clock_gettime(CLOCK_REALTIME, &abstime)) {
+ pthread_mutex_unlock(&chan->lock);
return -1;
+ }
abstime.tv_sec += timeout->tv_sec;
abstime.tv_nsec += timeout->tv_nsec;
+ if (abstime.tv_nsec > 1000000000) {
+ abstime.tv_nsec -= 1000000000;
+ abstime.tv_sec += 1;
+ }
+
status = pthread_cond_timedwait(&chan->cond, &chan->lock,
&abstime);
}
else
status = pthread_cond_wait(&chan->cond, &chan->lock);
}
-
pthread_mutex_unlock(&chan->lock);
+
if (status) {
errno = status;
return -1;
return status;
} /* sdb_channel_read */
+int
+sdb_channel_shutdown(sdb_channel_t *chan)
+{
+ if (! chan)
+ return -1;
+ chan->shutdown = 1;
+ return 0;
+} /* sdb_channel_shutdown */
+
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */