using semaphores...
This commit is contained in:
@@ -56,7 +56,6 @@ typedef int(*ao_play_func_t)(void *, char *, uint32_t);
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
Queue_t *play_queue;
|
Queue_t *play_queue;
|
||||||
Queue_t *last_frame;
|
Queue_t *last_frame;
|
||||||
sem_t queue_sem;
|
|
||||||
|
|
||||||
int paused;
|
int paused;
|
||||||
|
|
||||||
@@ -71,6 +70,7 @@ typedef struct {
|
|||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
pthread_mutex_t pause_mutex;
|
pthread_mutex_t pause_mutex;
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
|
sem_t *queue_sem;
|
||||||
#endif
|
#endif
|
||||||
double at_second;
|
double at_second;
|
||||||
double music_duration;
|
double music_duration;
|
||||||
@@ -89,7 +89,11 @@ static Queue_t *front(AO_Handle *h)
|
|||||||
|
|
||||||
static Queue_t *get(AO_Handle *h)
|
static Queue_t *get(AO_Handle *h)
|
||||||
{
|
{
|
||||||
sem_wait(&h->queue_sem);
|
#ifdef USE_PTHREADS
|
||||||
|
sem_wait(h->queue_sem);
|
||||||
|
#endif
|
||||||
|
#ifdef USE_WINDOWS_THREADS
|
||||||
|
#endif
|
||||||
MUTEX_LOCK(h->mutex);
|
MUTEX_LOCK(h->mutex);
|
||||||
assert(h->play_queue != NULL);
|
assert(h->play_queue != NULL);
|
||||||
Queue_t *q = h->play_queue;
|
Queue_t *q = h->play_queue;
|
||||||
@@ -119,8 +123,12 @@ static void add(AO_Handle *h, Queue_t *elem)
|
|||||||
h->last_frame = elem;
|
h->last_frame = elem;
|
||||||
}
|
}
|
||||||
h->buf_size += elem->buflen;
|
h->buf_size += elem->buflen;
|
||||||
|
#ifdef USE_PTHREADS
|
||||||
|
sem_post(h->queue_sem);
|
||||||
|
#endif
|
||||||
|
#ifdef USE_WINDOWS_THREADS
|
||||||
|
#endif
|
||||||
MUTEX_UNLOCK(h->mutex);
|
MUTEX_UNLOCK(h->mutex);
|
||||||
sem_post(&h->queue_sem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Queue_t *new_elem(int command, double at_second, double music_duration, int buf_len, void *buf)
|
static Queue_t *new_elem(int command, double at_second, double music_duration, int buf_len, void *buf)
|
||||||
@@ -154,9 +162,30 @@ static void del_elem(Queue_t *q)
|
|||||||
|
|
||||||
static void clear(AO_Handle *h)
|
static void clear(AO_Handle *h)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
MUTEX_LOCK(h->mutex);
|
||||||
while (h->play_queue != NULL) {
|
while (h->play_queue != NULL) {
|
||||||
Queue_t *q = get(h);
|
Queue_t *q = h->play_queue;
|
||||||
del_elem(q);
|
h->play_queue = h->play_queue->next;
|
||||||
|
del_elem(q);
|
||||||
|
if (h->play_queue == NULL) {
|
||||||
|
h->last_frame = NULL;
|
||||||
|
} else {
|
||||||
|
h->play_queue->prev = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef USE_PTHREADS
|
||||||
|
sem_destroy(h->queue_sem);
|
||||||
|
sem_init(h->queue_sem, 0, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_WINDOWS_THREADS
|
||||||
|
#endif
|
||||||
|
MUTEX_UNLOCK(h->mutex);
|
||||||
|
*/
|
||||||
|
while (h->play_queue != NULL) {
|
||||||
|
Queue_t *q = get(h);
|
||||||
|
del_elem(q);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +254,8 @@ void *ao_create_async(void *ao_device_yeah, void *ao_play_f)
|
|||||||
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
|
||||||
handle->mutex = m;
|
handle->mutex = m;
|
||||||
pthread_create(&handle->thread, NULL, run, handle);
|
pthread_create(&handle->thread, NULL, run, handle);
|
||||||
sem_init(&handle->queue_sem, 0, 0);
|
handle->queue_sem = (sem_t *) malloc(sizeof(sem_t));
|
||||||
|
sem_init(handle->queue_sem, 0, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_WINDOWS_THREADS
|
#ifdef USE_WINDOWS_THREADS
|
||||||
|
|||||||
Reference in New Issue
Block a user