diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-08-16 09:28:15 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-08-16 09:39:32 -0700 |
commit | 44d9f62f34e0561d83ea32941f0ea1b529b1490d (patch) | |
tree | 5345eba046b6e3bcf8c063e7bae8b501b7a99f4a /src/condition.h | |
parent | f9f70860622613686e6ac0bf7ebd448f437d92a7 (diff) | |
download | mpd-44d9f62f34e0561d83ea32941f0ea1b529b1490d.tar.gz mpd-44d9f62f34e0561d83ea32941f0ea1b529b1490d.tar.xz mpd-44d9f62f34e0561d83ea32941f0ea1b529b1490d.zip |
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.
Diffstat (limited to 'src/condition.h')
-rw-r--r-- | src/condition.h | 42 |
1 files changed, 36 insertions, 6 deletions
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 @@ -69,6 +91,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 */ void cond_destroy(struct condition *cond); |