[vlc-devel] commit: Use a custom condition variable for the playlist engine ( Rémi Denis-Courmont )

git version control git at videolan.org
Tue Jan 6 15:19:12 CET 2009


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Mon Jan  5 23:39:54 2009 +0200| [e966180ec9241fa44ba95cb0d911c68319992683] | committer: Rémi Denis-Courmont 

Use a custom condition variable for the playlist engine

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

 src/playlist/control.c           |    2 +-
 src/playlist/engine.c            |    4 +++-
 src/playlist/item.c              |   10 +++++-----
 src/playlist/playlist_internal.h |    2 ++
 src/playlist/search.c            |    2 +-
 src/playlist/thread.c            |   13 ++++++++++---
 6 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/src/playlist/control.c b/src/playlist/control.c
index f340d58..a3f87c6 100644
--- a/src/playlist/control.c
+++ b/src/playlist/control.c
@@ -176,7 +176,7 @@ static int PlaylistVAControl( playlist_t * p_playlist, int i_query, va_list args
         msg_Err( p_playlist, "unknown playlist query" );
         return VLC_EBADVAR;
     }
-    vlc_object_signal_unlocked( p_playlist );
+    vlc_cond_signal( &pl_priv(p_playlist)->signal );
 
     return VLC_SUCCESS;
 }
diff --git a/src/playlist/engine.c b/src/playlist/engine.c
index 0952bcf..e1e9e11 100644
--- a/src/playlist/engine.c
+++ b/src/playlist/engine.c
@@ -49,7 +49,7 @@ static int RandomCallback( vlc_object_t *p_this, char const *psz_cmd,
     PL_LOCK;
 
     pl_priv(p_playlist)->b_reset_currently_playing = true;
-    vlc_object_signal_unlocked( p_playlist );
+    vlc_cond_signal( &pl_priv(p_playlist)->signal );
 
     PL_UNLOCK;
     return VLC_SUCCESS;
@@ -81,6 +81,7 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
     libvlc_priv(p_parent->p_libvlc)->p_playlist = p_playlist;
 
     VariablesInit( p_playlist );
+    vlc_cond_init( &p->signal );
 
     /* Initialise data structures */
     pl_priv(p_playlist)->i_last_playlist_id = 0;
@@ -179,6 +180,7 @@ static void playlist_Destructor( vlc_object_t * p_this )
     assert( !p_sys->p_preparser );
     assert( !p_sys->p_fetcher );
 
+    vlc_cond_destroy( &p_sys->signal );
     msg_Dbg( p_this, "Destroyed" );
 }
 
diff --git a/src/playlist/item.c b/src/playlist/item.c
index 55ed4da..780ebfc 100644
--- a/src/playlist/item.c
+++ b/src/playlist/item.c
@@ -635,7 +635,7 @@ playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist,
                              p_playlist->p_root_onelevel, false );
         }
         pl_priv(p_playlist)->b_reset_currently_playing = true;
-        vlc_object_signal_unlocked( p_playlist );
+        vlc_cond_signal( &pl_priv(p_playlist)->signal );
         var_SetInteger( p_playlist, "item-change", p_item_in_category->
                                                         p_input->i_id );
         PL_UNLOCK_IF( !b_locked );
@@ -772,7 +772,7 @@ int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
     else
         i_ret = TreeMove( p_playlist, p_item, p_node, i_newpos );
     pl_priv(p_playlist)->b_reset_currently_playing = true;
-    vlc_object_signal_unlocked( p_playlist );
+    vlc_cond_signal( &pl_priv(p_playlist)->signal );
     return i_ret;
 }
 
@@ -800,7 +800,7 @@ void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id,
     val.p_address = p_add;
     pl_priv(p_playlist)->b_reset_currently_playing = true;
     if( b_signal )
-        vlc_object_signal_unlocked( p_playlist );
+        vlc_cond_signal( &pl_priv(p_playlist)->signal );
 
     var_Set( p_playlist, "item-append", val );
     free( p_add );
@@ -839,7 +839,7 @@ static void GoAndPreparse( playlist_t *p_playlist, int i_mode,
         if( pl_priv(p_playlist)->p_input )
             input_StopThread( pl_priv(p_playlist)->p_input );
         pl_priv(p_playlist)->request.i_status = PLAYLIST_RUNNING;
-        vlc_object_signal_unlocked( p_playlist );
+        vlc_cond_signal( &pl_priv(p_playlist)->signal );
     }
     /* Preparse if PREPARSE or SPREPARSE & not enough meta */
     char *psz_artist = input_item_GetArtist( p_item_cat->p_input );
@@ -922,7 +922,7 @@ static int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
             pl_priv(p_playlist)->request.b_request = true;
             pl_priv(p_playlist)->request.p_item = NULL;
             msg_Info( p_playlist, "stopping playback" );
-            vlc_object_signal_unlocked( VLC_OBJECT(p_playlist) );
+            vlc_cond_signal( &pl_priv(p_playlist)->signal );
         }
     }
 
diff --git a/src/playlist/playlist_internal.h b/src/playlist/playlist_internal.h
index 73fa3a1..a931153 100644
--- a/src/playlist/playlist_internal.h
+++ b/src/playlist/playlist_internal.h
@@ -82,6 +82,8 @@ typedef struct playlist_private_t
         vlc_mutex_t         lock;     /**< Lock to protect request */
     } request;
 
+    vlc_cond_t signal; /**< wakes up the playlist engine thread */
+
     int      i_last_playlist_id; /**< Last id to an item */
     bool     b_reset_currently_playing; /** Reset current item array */
 
diff --git a/src/playlist/search.c b/src/playlist/search.c
index 5851eff..96e0c37 100644
--- a/src/playlist/search.c
+++ b/src/playlist/search.c
@@ -173,6 +173,6 @@ int playlist_LiveSearchUpdate( playlist_t *p_playlist, playlist_item_t *p_root,
     PL_ASSERT_LOCKED;
     pl_priv(p_playlist)->b_reset_currently_playing = true;
     playlist_LiveSearchUpdateInternal( p_playlist, p_root, psz_string );
-    vlc_object_signal_unlocked( p_playlist );
+    vlc_cond_signal( &pl_priv(p_playlist)->signal );
     return VLC_SUCCESS;
 }
diff --git a/src/playlist/thread.c b/src/playlist/thread.c
index 4763823..d3ae009 100644
--- a/src/playlist/thread.c
+++ b/src/playlist/thread.c
@@ -82,6 +82,10 @@ void playlist_Deactivate( playlist_t *p_playlist )
     msg_Dbg( p_playlist, "Deactivate" );
 
     vlc_object_kill( p_playlist );
+    PL_LOCK;
+    vlc_cond_signal( &p_sys->signal );
+    PL_UNLOCK;
+
     vlc_thread_join( p_playlist );
     assert( !p_sys->p_input );
 
@@ -150,7 +154,8 @@ static int InputEvent( vlc_object_t *p_this, char const *psz_cmd,
 
     PL_LOCK;
 
-    vlc_object_signal_unlocked( p_playlist );
+    /* XXX: signaling while not changing any parameter... suspicious... */
+    vlc_cond_signal( &pl_priv(p_playlist)->signal );
 
     PL_UNLOCK;
     return VLC_SUCCESS;
@@ -548,7 +553,8 @@ static void LoopRequest( playlist_t *p_playlist )
             input_ressource_TerminateVout( p_sys->p_input_ressource );
 
         if( vlc_object_alive( p_playlist ) )
-            vlc_object_wait( p_playlist );
+            vlc_cond_wait( &pl_priv(p_playlist)->signal,
+                           &vlc_internals(p_playlist)->lock );
         return;
     }
 
@@ -593,7 +599,8 @@ static void *Thread ( vlc_object_t *p_this )
 
         /* If there is an input, check that it doesn't need to die. */
         while( !LoopInput( p_playlist ) )
-            vlc_object_wait( p_playlist );
+            vlc_cond_wait( &pl_priv(p_playlist)->signal,
+                           &vlc_internals(p_playlist)->lock );
 
         LoopRequest( p_playlist );
     }




More information about the vlc-devel mailing list