Commit 7d7890ed authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Lua: SD: simplify thread loop

parent 9ba5f88e
......@@ -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 )
{
/* 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 );
cancel = vlc_savecancel();
DoSearch( p_sd, psz_query );
free( psz_query );
vlc_mutex_lock( &p_sys->lock );
}
/* 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();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment