[vlc-devel] commit: preparser: shut threat down when not needed ( Rémi Denis-Courmont )
git version control
git at videolan.org
Thu Jun 4 19:49:45 CEST 2009
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jun 4 20:49:27 2009 +0300| [823b056881f5807cbb847e8f7208dc0f8f1ba4d8] | committer: Rémi Denis-Courmont
preparser: shut threat down when not needed
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=823b056881f5807cbb847e8f7208dc0f8f1ba4d8
---
src/playlist/preparser.c | 65 +++++++++++++++++++++++++++------------------
1 files changed, 39 insertions(+), 26 deletions(-)
diff --git a/src/playlist/preparser.c b/src/playlist/preparser.c
index f2cb232..b2e1902 100644
--- a/src/playlist/preparser.c
+++ b/src/playlist/preparser.c
@@ -44,7 +44,7 @@ struct playlist_preparser_t
vlc_thread_t thread;
vlc_mutex_t lock;
- vlc_cond_t wait;
+ bool b_live, b_zombie;
input_item_t **pp_waiting;
int i_waiting;
@@ -65,18 +65,11 @@ playlist_preparser_t *playlist_preparser_New( playlist_t *p_playlist, playlist_f
p_preparser->p_playlist = p_playlist;
p_preparser->p_fetcher = p_fetcher;
vlc_mutex_init( &p_preparser->lock );
- vlc_cond_init( &p_preparser->wait );
+ p_preparser->b_zombie = p_preparser->b_live = false;
p_preparser->i_art_policy = var_GetInteger( p_playlist, "album-art" );
p_preparser->i_waiting = 0;
p_preparser->pp_waiting = NULL;
- if( vlc_clone( &p_preparser->thread, Thread, p_preparser,
- VLC_THREAD_PRIORITY_LOW ) )
- {
- msg_Err( p_playlist, "cannot spawn preparse thread" );
- free( p_preparser );
- return NULL;
- }
return p_preparser;
}
@@ -85,24 +78,43 @@ void playlist_preparser_Push( playlist_preparser_t *p_preparser, input_item_t *p
vlc_gc_incref( p_item );
vlc_mutex_lock( &p_preparser->lock );
+ if( p_preparser->b_zombie )
+ {
+ vlc_join( p_preparser->thread, NULL );
+ p_preparser->b_zombie = false;
+ }
INSERT_ELEM( p_preparser->pp_waiting, p_preparser->i_waiting,
p_preparser->i_waiting, p_item );
- vlc_cond_signal( &p_preparser->wait );
+ if( !p_preparser->b_live )
+ {
+ if( vlc_clone( &p_preparser->thread, Thread, p_preparser,
+ VLC_THREAD_PRIORITY_LOW ) )
+ msg_Warn( p_preparser->p_playlist,
+ "cannot spawn pre-parser thread" );
+ else
+ p_preparser->b_live = true;
+ }
vlc_mutex_unlock( &p_preparser->lock );
}
void playlist_preparser_Delete( playlist_preparser_t *p_preparser )
{
+ bool b_join;
+
/* Destroy the item preparser */
- vlc_cancel( p_preparser->thread );
- vlc_join( p_preparser->thread, NULL );
+ vlc_mutex_lock( &p_preparser->lock );
+ if( p_preparser->b_live )
+ vlc_cancel( p_preparser->thread );
+ b_join = p_preparser->b_live || p_preparser->b_zombie;
+ vlc_mutex_unlock( &p_preparser->lock );
+ if( b_join )
+ vlc_join( p_preparser->thread, NULL );
while( p_preparser->i_waiting > 0 )
{ /* Any left-over unparsed item? */
vlc_gc_decref( p_preparser->pp_waiting[0] );
REMOVE_ELEM( p_preparser->pp_waiting, p_preparser->i_waiting, 0 );
}
- vlc_cond_destroy( &p_preparser->wait );
vlc_mutex_destroy( &p_preparser->lock );
free( p_preparser );
}
@@ -187,22 +199,23 @@ static void *Thread( void *data )
{
input_item_t *p_current;
- /* Be sure to be cancellable before our queue is empty */
- vlc_testcancel();
-
/* */
vlc_mutex_lock( &p_preparser->lock );
- mutex_cleanup_push( &p_preparser->lock );
-
- while( p_preparser->i_waiting == 0 )
- vlc_cond_wait( &p_preparser->wait, &p_preparser->lock );
-
- p_current = p_preparser->pp_waiting[0];
- REMOVE_ELEM( p_preparser->pp_waiting, p_preparser->i_waiting, 0 );
- vlc_cleanup_run( );
+ if( p_preparser->i_waiting > 0 )
+ {
+ p_current = p_preparser->pp_waiting[0];
+ REMOVE_ELEM( p_preparser->pp_waiting, p_preparser->i_waiting, 0 );
+ }
+ else
+ {
+ p_current = NULL;
+ p_preparser->b_live = false;
+ p_preparser->b_zombie = true;
+ }
+ vlc_mutex_unlock( &p_preparser->lock );
if( !p_current )
- continue;
+ break;
int canc = vlc_savecancel();
@@ -217,7 +230,7 @@ static void *Thread( void *data )
if( i_activity < 0 )
i_activity = 0;
- /* Sleep at least 1ms */
+ /* Sleep at least 1ms and cancel thread if needed */
msleep( (i_activity+1) * 1000 );
}
return NULL;
More information about the vlc-devel
mailing list