From 12375d1d3aa41f7d277a9af584c7b810b636ec95 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Wed, 2 Mar 2011 08:49:38 +0000 Subject: Merge functionality of wakeups and semaphores-- fewer APIs and object types. semaphore_wait takes a timeout now so codecs and plugins have to be made incompatible. Don't make semaphores for targets not using them. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29492 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs.h | 6 +++--- apps/codecs/mpa.c | 4 ++-- apps/codecs/spc.c | 17 ++++++++--------- apps/plugin.h | 6 +++--- 4 files changed, 16 insertions(+), 17 deletions(-) (limited to 'apps') diff --git a/apps/codecs.h b/apps/codecs.h index 8a40791106..028e3614ff 100644 --- a/apps/codecs.h +++ b/apps/codecs.h @@ -75,12 +75,12 @@ #define CODEC_ENC_MAGIC 0x52454E43 /* RENC */ /* increase this every time the api struct changes */ -#define CODEC_API_VERSION 38 +#define CODEC_API_VERSION 39 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define CODEC_MIN_API_VERSION 38 +#define CODEC_MIN_API_VERSION 39 /* codec return codes */ enum codec_status { @@ -166,7 +166,7 @@ struct codec_api { void (*thread_thaw)(unsigned int thread_id); void (*thread_wait)(unsigned int thread_id); void (*semaphore_init)(struct semaphore *s, int max, int start); - void (*semaphore_wait)(struct semaphore *s); + int (*semaphore_wait)(struct semaphore *s, int timeout); void (*semaphore_release)(struct semaphore *s); #endif /* NUM_CORES */ diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c index d3da63b430..4d6c52f2b3 100644 --- a/apps/codecs/mpa.c +++ b/apps/codecs/mpa.c @@ -211,7 +211,7 @@ static void mad_synth_thread(void) { while(1) { ci->semaphore_release(&synth_done_sem); - ci->semaphore_wait(&synth_pending_sem); + ci->semaphore_wait(&synth_pending_sem, TIMEOUT_BLOCK); if(die) break; @@ -224,7 +224,7 @@ static void mad_synth_thread(void) * synthesized */ static inline void mad_synth_thread_wait_pcm(void) { - ci->semaphore_wait(&synth_done_sem); + ci->semaphore_wait(&synth_done_sem, TIMEOUT_BLOCK); } /* increment the done semaphore - used after a wait for idle to preserve the diff --git a/apps/codecs/spc.c b/apps/codecs/spc.c index d4ed741f7e..4db2878964 100644 --- a/apps/codecs/spc.c +++ b/apps/codecs/spc.c @@ -244,7 +244,7 @@ static inline void samples_release_wrbuf(void) static inline struct sample_queue_chunk * samples_get_wrbuf(void) { - ci->semaphore_wait(&sample_queue.emu_sem_tail); + ci->semaphore_wait(&sample_queue.emu_sem_tail, TIMEOUT_BLOCK); return &sample_queue.wav_chunk[sample_queue.tail & WAV_CHUNK_MASK]; } @@ -259,7 +259,7 @@ static inline void samples_release_rdbuf(void) static inline int32_t * samples_get_rdbuf(void) { - ci->semaphore_wait(&sample_queue.emu_sem_head); + ci->semaphore_wait(&sample_queue.emu_sem_head, TIMEOUT_BLOCK); if (ci->stop_codec || ci->new_track) { @@ -275,7 +275,7 @@ static intptr_t emu_thread_send_msg(long id, intptr_t data) { struct sample_queue_chunk *chunk; /* Grab an audio output buffer */ - ci->semaphore_wait(&sample_queue.emu_sem_head); + ci->semaphore_wait(&sample_queue.emu_sem_head, TIMEOUT_BLOCK); chunk = &sample_queue.wav_chunk[sample_queue.head & WAV_CHUNK_MASK]; /* Place a message in it instead of audio */ chunk->id = id; @@ -285,7 +285,7 @@ static intptr_t emu_thread_send_msg(long id, intptr_t data) if (id != SPC_EMU_QUIT) { /* Wait for a response */ - ci->semaphore_wait(&sample_queue.emu_evt_reply); + ci->semaphore_wait(&sample_queue.emu_evt_reply, TIMEOUT_BLOCK); } return sample_queue.retval; @@ -308,11 +308,10 @@ static bool emu_thread_process_msg(struct sample_queue_chunk *chunk) sample_queue.retval = SPC_load_spc(&spc_emu, ld->buf, ld->size); /* Empty the audio queue */ - /* This is a dirty hack a timeout based wait would make unnescessary but - still safe because the other thread is known to be waiting for a reply - and is not using the objects. */ - ci->semaphore_init(&sample_queue.emu_sem_tail, 2, 2); - ci->semaphore_init(&sample_queue.emu_sem_head, 2, 0); + ci->semaphore_release(&sample_queue.emu_sem_tail); + ci->semaphore_release(&sample_queue.emu_sem_tail); + ci->semaphore_wait(&sample_queue.emu_sem_head, TIMEOUT_NOBLOCK); + ci->semaphore_wait(&sample_queue.emu_sem_head, TIMEOUT_NOBLOCK); sample_queue.head = sample_queue.tail = 0; } diff --git a/apps/plugin.h b/apps/plugin.h index 8c2d458c57..2275b309d7 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -145,12 +145,12 @@ void* plugin_get_buffer(size_t *buffer_size); #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 199 +#define PLUGIN_API_VERSION 200 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define PLUGIN_MIN_API_VERSION 199 +#define PLUGIN_MIN_API_VERSION 200 /* plugin return codes */ /* internal returns start at 0x100 to make exit(1..255) work */ @@ -901,7 +901,7 @@ struct plugin_api { #ifdef HAVE_SEMAPHORE_OBJECTS void (*semaphore_init)(struct semaphore *s, int max, int start); - void (*semaphore_wait)(struct semaphore *s); + int (*semaphore_wait)(struct semaphore *s, int timeout); void (*semaphore_release)(struct semaphore *s); #endif -- cgit v1.2.3