/* thread function */ static bool emu_thread_process_msg(struct sample_queue_chunk *chunk) { long id = chunk->id; bool ret = id != SPC_EMU_QUIT; chunk->id = SPC_EMU_AUDIO; /* Reset chunk type to audio */ sample_queue.retval = 0; if (id == SPC_EMU_LOAD) { struct spc_load *ld = (struct spc_load *)chunk->data; ci->commit_discard_dcache(); SPC_Init(&spc_emu); sample_queue.retval = SPC_load_spc(&spc_emu, ld->buf, ld->size); /* Empty the audio queue */ 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; } if (id != SPC_EMU_QUIT) { ci->semaphore_release(&sample_queue.emu_evt_reply); } return ret; }
/* thread function */ static bool emu_thread_process_msg(struct sample_queue_chunk *chunk) { long id = chunk->id; bool ret = id != SPC_EMU_QUIT; chunk->id = SPC_EMU_AUDIO; /* Reset chunk type to audio */ sample_queue.retval = 0; if (id == SPC_EMU_LOAD) { struct spc_load *ld = (struct spc_load *)chunk->data; ci->cpucache_invalidate(); SPC_Init(&spc_emu); 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); sample_queue.head = sample_queue.tail = 0; } if (id != SPC_EMU_QUIT) { ci->semaphore_release(&sample_queue.emu_evt_reply); } return ret; }