Mercurial > audlegacy-plugins
changeset 2152:8a5231ff9c4f
- Use a single lock for the ring buffer and the condition variable
author | Ralf Ertzinger <ralf@skytale.net> |
---|---|
date | Sun, 04 Nov 2007 14:05:16 +0100 |
parents | 9a9f406374c6 |
children | a0efcdd66861 69c9f138611b |
files | src/neon/Makefile src/neon/neon.c |
diffstat | 2 files changed, 13 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/neon/Makefile Sun Nov 04 14:04:37 2007 +0100 +++ b/src/neon/Makefile Sun Nov 04 14:05:16 2007 +0100 @@ -9,5 +9,5 @@ plugindir := ${plugindir}/${TRANSPORT_PLUGIN_DIR} CFLAGS += ${PLUGIN_CFLAGS} -CPPFLAGS += ${PLUGIN_CPPFLAGS} ${MOWGLI_CFLAGS} ${DBUS_CFLAGS} ${GTK_CFLAGS} ${GLIB_CFLAGS} ${PANGO_CFLAGS} ${ARCH_DEFINES} ${XML_CPPFLAGS} ${NEON_CFLAGS} -I../../intl -I../.. +CPPFLAGS += ${PLUGIN_CPPFLAGS} ${MOWGLI_CFLAGS} ${DBUS_CFLAGS} ${GTK_CFLAGS} ${GLIB_CFLAGS} ${PANGO_CFLAGS} ${ARCH_DEFINES} ${XML_CPPFLAGS} ${NEON_CFLAGS} -I../../intl -I../.. -D_RB_USE_GLIB LIBS += ${GTK_LIBS} ${GLIB_LIBS} ${PANGO_LIBS} ${XML_LIBS} ${NEON_LIBS}
--- a/src/neon/neon.c Sun Nov 04 14:04:37 2007 +0100 +++ b/src/neon/neon.c Sun Nov 04 14:05:16 2007 +0100 @@ -90,7 +90,13 @@ _LEAVE NULL; } - if (0 != init_rb(&(h->rb), NBUFSIZ)) { + h->reader = NULL; + h->reader_status.mutex = g_mutex_new(); + h->reader_status.cond = g_cond_new(); + h->reader_status.reading = FALSE; + h->reader_status.status = NEON_READER_INIT; + + if (0 != init_rb_with_lock(&(h->rb), NBUFSIZ, h->reader_status.mutex)) { _ERROR("Could not initialize buffer"); free(h); _LEAVE NULL; @@ -111,11 +117,6 @@ h->icy_metadata.stream_title = NULL; h->icy_metadata.stream_url = NULL; h->icy_metadata.stream_contenttype = NULL; - h->reader = NULL; - h->reader_status.mutex = g_mutex_new(); - h->reader_status.cond = g_cond_new(); - h->reader_status.reading = FALSE; - h->reader_status.status = NEON_READER_INIT; h->eof = FALSE; _LEAVE h; @@ -715,12 +716,12 @@ g_mutex_lock(h->reader_status.mutex); while(h->reader_status.reading) { - g_mutex_unlock(h->reader_status.mutex); /* * Hit the network only if we have more than NETBLKSIZ of free buffer */ - if (NETBLKSIZ < free_rb(&h->rb)) { + if (NETBLKSIZ < free_rb_locked(&h->rb)) { + g_mutex_unlock(h->reader_status.mutex); _DEBUG("Filling buffer..."); ret = fill_buffer(h); @@ -756,18 +757,9 @@ * Not enough free space in the buffer. * Sleep until the main thread wakes us up. */ - g_mutex_lock(h->reader_status.mutex); - if (h->reader_status.reading) { - _DEBUG("Reader thread going to sleep"); - g_cond_wait(h->reader_status.cond, h->reader_status.mutex); - _DEBUG("Reader thread woke up"); - } else { - /* - * Main thread has ordered termination of this thread. - * Leave the loop. - */ - break; - } + _DEBUG("Reader thread going to sleep"); + g_cond_wait(h->reader_status.cond, h->reader_status.mutex); + _DEBUG("Reader thread woke up"); } }