aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Sommerfeld <kai.sommerfeld@gmx.com>2016-02-25 22:51:03 +0100
committerKai Sommerfeld <kai.sommerfeld@gmx.com>2016-02-27 14:53:37 +0100
commitc5d29b928fd847f39b44b3aa2535c4455e24818b (patch)
tree1caf5ace54710366d8dcaa6b2040379b062a21bf
parent25efe6c4b30716b1a794e57baf9d5cc9dfd71963 (diff)
[network] Fix CZeroconfBrowserAvahi dtor avahi thread termination.
-rw-r--r--xbmc/network/linux/ZeroconfBrowserAvahi.cpp45
-rw-r--r--xbmc/network/linux/ZeroconfBrowserAvahi.h6
2 files changed, 3 insertions, 48 deletions
diff --git a/xbmc/network/linux/ZeroconfBrowserAvahi.cpp b/xbmc/network/linux/ZeroconfBrowserAvahi.cpp
index 2c62f4838c..1a0402fc7a 100644
--- a/xbmc/network/linux/ZeroconfBrowserAvahi.cpp
+++ b/xbmc/network/linux/ZeroconfBrowserAvahi.cpp
@@ -47,7 +47,7 @@ private:
};
}
-CZeroconfBrowserAvahi::CZeroconfBrowserAvahi() : mp_client ( 0 ), mp_poll ( 0 ), m_shutdown(false), m_thread_id(0)
+CZeroconfBrowserAvahi::CZeroconfBrowserAvahi() : mp_client ( 0 ), mp_poll ( 0 )
{
if ( ! ( mp_poll = avahi_threaded_poll_new() ) )
{
@@ -74,27 +74,8 @@ CZeroconfBrowserAvahi::~CZeroconfBrowserAvahi()
CLog::Log ( LOGDEBUG, "CZeroconfAvahi::~CZeroconfAvahi() Going down! cleaning up..." );
if ( mp_poll )
{
- //normally we would stop the avahi thread here and do our work, but
- //it looks like this does not work -> www.avahi.org/ticket/251
- //so instead of calling
- //avahi_threaded_poll_stop(mp_poll);
- //we set m_shutdown=true, post an event and wait for it to stop itself
- struct timeval tv = { 0, 0 }; //TODO: does tv survive the thread?
- AvahiTimeout* lp_timeout;
- {
- ScopedEventLoopBlock l_block(mp_poll);
- const AvahiPoll* cp_apoll = avahi_threaded_poll_get(mp_poll);
- m_shutdown = true;
- lp_timeout = cp_apoll->timeout_new(cp_apoll,
- &tv,
- shutdownCallback,
- this);
- }
-
- //now wait for the thread to stop
- assert(m_thread_id);
- pthread_join(m_thread_id, NULL);
- avahi_threaded_poll_get(mp_poll)->timeout_free(lp_timeout);
+ //stop avahi polling thread
+ avahi_threaded_poll_stop(mp_poll);
}
//free the client (frees all browsers, groups, ...)
if ( mp_client )
@@ -207,15 +188,6 @@ bool CZeroconfBrowserAvahi::doResolveService ( CZeroconfBrowser::ZeroconfService
void CZeroconfBrowserAvahi::clientCallback ( AvahiClient* fp_client, AvahiClientState f_state, void* fp_data )
{
CZeroconfBrowserAvahi* p_instance = static_cast<CZeroconfBrowserAvahi*> ( fp_data );
-
- //store our thread ID and check for shutdown -> check details in destructor
- p_instance->m_thread_id = pthread_self();
- if (p_instance->m_shutdown)
- {
- avahi_threaded_poll_quit(p_instance->mp_poll);
- return;
- }
-
switch ( f_state )
{
case AVAHI_CLIENT_S_RUNNING:
@@ -404,15 +376,4 @@ AvahiServiceBrowser* CZeroconfBrowserAvahi::createServiceBrowser ( const std::st
return ret;
}
-
-void CZeroconfBrowserAvahi::shutdownCallback(AvahiTimeout *fp_e, void *fp_data)
-{
- CZeroconfBrowserAvahi* p_instance = static_cast<CZeroconfBrowserAvahi*>(fp_data);
- //should only be called on shutdown
- if (p_instance->m_shutdown)
- {
- avahi_threaded_poll_quit(p_instance->mp_poll);
- }
-}
-
#endif //HAS_AVAHI
diff --git a/xbmc/network/linux/ZeroconfBrowserAvahi.h b/xbmc/network/linux/ZeroconfBrowserAvahi.h
index d59faa625a..4e56ad92f0 100644
--- a/xbmc/network/linux/ZeroconfBrowserAvahi.h
+++ b/xbmc/network/linux/ZeroconfBrowserAvahi.h
@@ -78,8 +78,6 @@ class CZeroconfBrowserAvahi : public CZeroconfBrowser
AvahiStringList *txt,
AvahiLookupResultFlags flags,
AVAHI_GCC_UNUSED void* userdata);
- //helper to workaround avahi bug
- static void shutdownCallback(AvahiTimeout *fp_e, void *fp_data);
//helpers
bool createClient();
static AvahiServiceBrowser* createServiceBrowser(const std::string& fcr_service_type, AvahiClient* fp_client, void* fp_userdata);
@@ -106,10 +104,6 @@ class CZeroconfBrowserAvahi : public CZeroconfBrowser
tDiscoveredServices m_discovered_services;
CZeroconfBrowser::ZeroconfService m_resolving_service;
CEvent m_resolved_event;
-
- //2 variables below are needed for workaround of avahi bug (see destructor for details)
- bool m_shutdown;
- pthread_t m_thread_id;
};
#endif //HAS_AVAHI