[vlc-commits] Lua: SD: simplify thread loop

Rémi Denis-Courmont git at videolan.org
Mon Jun 24 19:13:28 CEST 2013


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jun 16 17:28:53 2013 +0300| [7d7890ed110c13bc4ec8067a9c11f96e7f1706af] | committer: Rémi Denis-Courmont

Lua: SD: simplify thread loop

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7d7890ed110c13bc4ec8067a9c11f96e7f1706af
---

 modules/lua/services_discovery.c |   34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/modules/lua/services_discovery.c b/modules/lua/services_discovery.c
index 7cd0bd6..8aa4115 100644
--- a/modules/lua/services_discovery.c
+++ b/modules/lua/services_discovery.c
@@ -52,7 +52,6 @@ struct services_discovery_sys_t
     vlc_thread_t thread;
     vlc_mutex_t lock;
     vlc_cond_t cond;
-    bool b_exiting;
 
     char **ppsz_query;
     int i_query;
@@ -135,7 +134,6 @@ int Open_LuaSD( vlc_object_t *p_this )
     p_sys->L = L;
     vlc_mutex_init( &p_sys->lock );
     vlc_cond_init( &p_sys->cond );
-    p_sys->b_exiting = false;
     TAB_INIT( p_sys->i_query, p_sys->ppsz_query );
 
     if( vlc_clone( &p_sys->thread, Run, p_sd, VLC_THREAD_PRIORITY_LOW ) )
@@ -163,10 +161,6 @@ void Close_LuaSD( vlc_object_t *p_this )
     services_discovery_t *p_sd = ( services_discovery_t * )p_this;
     services_discovery_sys_t *p_sys = p_sd->p_sys;
 
-    vlc_mutex_lock( &p_sys->lock );
-    p_sys->b_exiting = true;
-    vlc_mutex_unlock( &p_sys->lock );
-
     vlc_cancel( p_sys->thread );
     vlc_join( p_sys->thread, NULL );
 
@@ -213,29 +207,29 @@ static void* Run( void *data )
     /* Main loop to handle search requests */
     vlc_mutex_lock( &p_sys->lock );
     mutex_cleanup_push( &p_sys->lock );
-    while( !p_sys->b_exiting )
+    for( ;; )
     {
         /* Wait for a request */
-        while( !p_sys->i_query )
+        if( !p_sys->i_query )
+        {
             vlc_cond_wait( &p_sys->cond, &p_sys->lock );
+            continue;
+        }
 
-        /* Execute every query each one protected against cancelation */
-        cancel = vlc_savecancel();
-        while( !p_sys->b_exiting && p_sys->i_query )
-        {
-            char *psz_query = p_sys->ppsz_query[p_sys->i_query - 1];
-            REMOVE_ELEM( p_sys->ppsz_query, p_sys->i_query, p_sys->i_query - 1 );
+        /* Execute one query (protected against cancellation) */
+        char *psz_query = p_sys->ppsz_query[p_sys->i_query - 1];
+        REMOVE_ELEM( p_sys->ppsz_query, p_sys->i_query, p_sys->i_query - 1 );
+        vlc_mutex_unlock( &p_sys->lock );
 
-            vlc_mutex_unlock( &p_sys->lock );
-            DoSearch( p_sd, psz_query );
-            free( psz_query );
-            vlc_mutex_lock( &p_sys->lock );
-        }
+        cancel = vlc_savecancel();
+        DoSearch( p_sd, psz_query );
+        free( psz_query );
         /* Force garbage collection, because the core will keep the SD
          * open, but lua will never gc until lua_close(). */
         lua_gc( L, LUA_GCCOLLECT, 0 );
-
         vlc_restorecancel( cancel );
+
+        vlc_mutex_lock( &p_sys->lock );
     }
     vlc_cleanup_run();
 



More information about the vlc-commits mailing list