From 44d9f62f34e0561d83ea32941f0ea1b529b1490d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 16 Aug 2008 09:28:15 -0700 Subject: core rewrite (decode,player,outputBuffer,playlist) This is a huge refactoring of the core mpd process. The queueing/buffering mechanism is heavily reworked. The player.c code has been merged into outputBuffer (the actual ring buffering logic is handled by ringbuf.c); and decode.c actually handles decoding stuff. The end result is several hundreds of lines shorter, even though we still have a lot of DEBUG statements left in there for tracing and a lot of assertions, too. --- src/condition.h | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'src/condition.h') diff --git a/src/condition.h b/src/condition.h index 576ff9dc3..75e9cfad5 100644 --- a/src/condition.h +++ b/src/condition.h @@ -27,40 +27,62 @@ struct condition { pthread_cond_t cond; }; +#define STATIC_COND_INITIALIZER \ + { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER } + void cond_init(struct condition *cond); /** * The thread which shall be notified by this object must call this * function before any cond_wait() invocation. It locks the mutex. */ -void cond_enter(struct condition *cond); +static inline void cond_enter(struct condition *cond) +{ + pthread_mutex_lock(&cond->mutex); +} + +/** + * Will try to enter a condition where it can eventually wait. + * + * Returns immediately, 0 if successful, EBUSY if failed + */ +static inline int cond_tryenter(struct condition *cond) +{ + return pthread_mutex_trylock(&cond->mutex); +} /** * Neutralize cond_leave(). */ -void cond_leave(struct condition *cond); +static inline void cond_leave(struct condition *cond) +{ + pthread_mutex_unlock(&cond->mutex); +} /** * Wait for a conditio. Return immediately if we have already * been notified since we last returned from cond_wait(). */ -void cond_wait(struct condition *cond); +static inline void cond_wait(struct condition *cond) +{ + pthread_cond_wait(&cond->cond, &cond->mutex); +} /** * Wait for a condition with timeout * - * @param sec number of seconds to wait for (subject to change) + * @param sec number of milliseconds to wait for * * @return ETIMEDOUT if timed out, 0 if notification was received */ -int cond_timedwait(struct condition *cond, const long sec); +int cond_timedwait(struct condition *cond, const long msec); /** * Notify the thread there is a waiter. This function never blocks. * * @return EBUSY if it was unable to lock the mutex, 0 on success */ -int cond_signal_async(struct condition *cond); +int cond_signal_trysync(struct condition *cond); /** * Notify the thread synchronously, i.e. wait until it can deliver @@ -68,6 +90,14 @@ int cond_signal_async(struct condition *cond); */ void cond_signal_sync(struct condition *cond); +/** + * Signal the thread without caring about delivery success/failure + */ +static inline void cond_signal(struct condition *cond) +{ + pthread_cond_signal(&cond->cond); +} + /** * cond_destroy - destroy the cond and internal structures */ -- cgit v1.2.3