From 8426740f44e6584e291f23ac9858754111221395 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 30 Jun 2008 02:43:04 +0000 Subject: utils: add new unforgiving utility functions We'll be using pipes when waiting for I/O, and condition variables at other times. git-svn-id: https://svn.musicpd.org/mpd/trunk@7391 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/utils.c | 24 ++++++++++++++++++++++++ src/utils.h | 6 ++++++ 2 files changed, 30 insertions(+) diff --git a/src/utils.c b/src/utils.c index a311796c8..eedae22de 100644 --- a/src/utils.c +++ b/src/utils.c @@ -230,3 +230,27 @@ int set_nonblocking(int fd) while ((ret = fcntl(fd, F_SETFL, flags)) < 0 && errno == EINTR) ; return ret; } + +void init_async_pipe(int file_des[2]) +{ + if (pipe(file_des) < 0) + FATAL("Couldn't open pipe: %s", strerror(errno)); + if (set_nonblocking(file_des[0]) < 0) + FATAL("Couldn't set non-blocking I/O: %s\n", strerror(errno)); + if (set_nonblocking(file_des[1]) < 0) + FATAL("Couldn't set non-blocking I/O: %s\n", strerror(errno)); +} + +void xpthread_mutex_destroy(pthread_mutex_t *mutex) +{ + int err; + if ((err = pthread_mutex_destroy(mutex))) + FATAL("failed to destroy mutex: %s\n", strerror(err)); +} + +void xpthread_cond_destroy(pthread_cond_t *cond) +{ + int err; + if ((err = pthread_cond_destroy(cond))) + FATAL("failed to destroy cond: %s\n", strerror(err)); +} diff --git a/src/utils.h b/src/utils.h index 0b6763a05..eb16e87bc 100644 --- a/src/utils.h +++ b/src/utils.h @@ -80,4 +80,10 @@ char *parsePath(char *path); int set_nonblocking(int fd); +void init_async_pipe(int file_des[2]); + +void xpthread_mutex_destroy(pthread_mutex_t *mutex); + +void xpthread_cond_destroy(pthread_cond_t *cond); + #endif -- cgit v1.2.3