From 934c14fc7c8fd6d83c2aced24dea48eb7205419b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Mon, 10 Dec 2007 17:43:56 +0100 Subject: Don't run the infinite loop when checking operations. Instead a condition is signalled when adding new entries, and waited for if no entries are present. --- src/audio_out/audio_pulse_out.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/audio_out/audio_pulse_out.c b/src/audio_out/audio_pulse_out.c index efe1aab91..e341aec3b 100644 --- a/src/audio_out/audio_pulse_out.c +++ b/src/audio_out/audio_pulse_out.c @@ -68,6 +68,7 @@ typedef struct { operation_waiter_t *op_list; /**< List of operations awaited */ pthread_mutex_t op_mutex; /**< Mutex controlling op_list access. */ pthread_t op_thread; /**< The operation_waiting_thread() thread. */ + pthread_cond_t op_list_newentries; /**< condition signalled when new entries are added to the list */ } pulse_class_t; typedef struct pulse_driver_s { @@ -100,7 +101,14 @@ static void *operation_waiting_thread(void *class_gen) { pulse_class_t *class = class_gen; operation_waiter_t *curr_op; + pthread_mutex_t condmutex = PTHREAD_MUTEX_INITIALIZER; + while(1) { + if ( class->op_list == NULL ) { + pthread_mutex_lock(&condmutex); + pthread_cond_wait(&class->op_list_newentries, &condmutex); + } + pa_threaded_mainloop_lock(class->mainloop); pa_threaded_mainloop_wait(class->mainloop); @@ -132,6 +140,7 @@ static void *operation_waiting_thread(void *class_gen) { static void wait_for_operation(pulse_driver_t *this, struct pa_operation *operation) { operation_waiter_t *op = xine_xmalloc(sizeof(operation_waiter_t)); + int signal_new_entries = 0; /* Signal that new entries are available */ pthread_mutex_t condmutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&condmutex); @@ -142,8 +151,13 @@ static void wait_for_operation(pulse_driver_t *this, struct pa_operation *operat if ( this->pa_class->op_list ) op->next = this->pa_class->op_list; + else + signal_new_entries = 1; this->pa_class->op_list = op; + if ( signal_new_entries ) + pthread_cond_signal(&this->pa_class->op_list_newentries); + pthread_mutex_unlock(&this->pa_class->op_mutex); pthread_cond_wait(&op->condition, &condmutex); @@ -679,6 +693,7 @@ static void *init_class (xine_t *xine, void *data) { pa_threaded_mainloop_start(this->mainloop); pthread_mutex_init(&this->op_mutex, NULL); + pthread_cond_init(&this->op_list_newentries, NULL); pthread_create(&this->op_thread, NULL, &operation_waiting_thread, this); this->context = NULL; -- cgit v1.2.3