[network] Fix CZeroconfBrowserAvahi dtor avahi thread termination.
authorKai Sommerfeld <kai.sommerfeld@gmx.com>
Thu, 25 Feb 2016 21:51:03 +0000 (22:51 +0100)
committerKai Sommerfeld <kai.sommerfeld@gmx.com>
Sat, 27 Feb 2016 13:53:37 +0000 (14:53 +0100)
xbmc/network/linux/ZeroconfBrowserAvahi.cpp
xbmc/network/linux/ZeroconfBrowserAvahi.h

index 2c62f48..1a0402f 100644 (file)
@@ -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
index d59faa6..4e56ad9 100644 (file)
@@ -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