output: migrate from pthread to glib threads

This commit is contained in:
Thomas Jansen 2008-12-28 22:09:42 +01:00
parent 28128dc4e3
commit 36b8968e36
4 changed files with 9 additions and 12 deletions

View File

@ -77,7 +77,7 @@ audio_output_open(struct audio_output *audioOutput,
audio_output_close(audioOutput); audio_output_close(audioOutput);
} }
if (audioOutput->thread == 0) if (audioOutput->thread == NULL)
audio_output_thread_start(audioOutput); audio_output_thread_start(audioOutput);
if (!audioOutput->open) if (!audioOutput->open)
@ -135,7 +135,7 @@ void audio_output_close(struct audio_output *audioOutput)
void audio_output_finish(struct audio_output *audioOutput) void audio_output_finish(struct audio_output *audioOutput)
{ {
audio_output_close(audioOutput); audio_output_close(audioOutput);
if (audioOutput->thread != 0) if (audioOutput->thread != NULL)
ao_command(audioOutput, AO_COMMAND_KILL); ao_command(audioOutput, AO_COMMAND_KILL);
if (audioOutput->plugin->finish) if (audioOutput->plugin->finish)
audioOutput->plugin->finish(audioOutput->data); audioOutput->plugin->finish(audioOutput->data);

View File

@ -102,7 +102,7 @@ int audio_output_init(struct audio_output *ao, ConfigParam * param)
} else } else
audio_format_clear(&ao->reqAudioFormat); audio_format_clear(&ao->reqAudioFormat);
ao->thread = 0; ao->thread = NULL;
notify_init(&ao->notify); notify_init(&ao->notify);
ao->command = AO_COMMAND_NONE; ao->command = AO_COMMAND_NONE;

View File

@ -23,7 +23,6 @@
#include "pcm_utils.h" #include "pcm_utils.h"
#include "notify.h" #include "notify.h"
#include <pthread.h>
#include <time.h> #include <time.h>
struct audio_output { struct audio_output {
@ -84,10 +83,10 @@ struct audio_output {
size_t convBufferLen; size_t convBufferLen;
/** /**
* The thread handle, or "0" if the output thread isn't * The thread handle, or NULL if the output thread isn't
* running. * running.
*/ */
pthread_t thread; GThread *thread;
/** /**
* Notify object for the thread. * Notify object for the thread.

View File

@ -106,7 +106,7 @@ static void ao_pause(struct audio_output *ao)
} }
} }
static void *audio_output_task(void *arg) static gpointer audio_output_task(gpointer arg)
{ {
struct audio_output *ao = arg; struct audio_output *ao = arg;
bool ret; bool ret;
@ -167,12 +167,10 @@ static void *audio_output_task(void *arg)
void audio_output_thread_start(struct audio_output *ao) void audio_output_thread_start(struct audio_output *ao)
{ {
pthread_attr_t attr; GError *e;
assert(ao->command == AO_COMMAND_NONE); assert(ao->command == AO_COMMAND_NONE);
pthread_attr_init(&attr); if (!(ao->thread = g_thread_create(audio_output_task, ao, FALSE, &e)))
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); g_error("Failed to spawn output task: %s\n", e->message);
if (pthread_create(&ao->thread, &attr, audio_output_task, ao))
g_error("Failed to spawn output task: %s\n", strerror(errno));
} }