]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/commands/async_queue.cpp
CACA: use key thread (partially fix #3661)
[vlc] / modules / gui / skins2 / commands / async_queue.cpp
index 170cec763386391efb262333fb754b97417dbc02..759ff6a6e5d37fa65d3ee7b67145aa3b6eb8f616 100644 (file)
@@ -5,7 +5,7 @@
  * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
- *          Olivier Teulière <ipkiss@via.ecp.fr>
+ *          Olivier Teulière <ipkiss@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #include "async_queue.hpp"
@@ -31,7 +31,7 @@ AsyncQueue::AsyncQueue( intf_thread_t *pIntf ): SkinObject( pIntf ),
     m_cmdFlush( this )
 {
     // Initialize the mutex
-    vlc_mutex_init( pIntf, &m_lock );
+    vlc_mutex_init( &m_lock );
 
     // Create a timer
     OSFactory *pOsFactory = OSFactory::instance( pIntf );
@@ -67,43 +67,45 @@ AsyncQueue *AsyncQueue::instance( intf_thread_t *pIntf )
 
 void AsyncQueue::destroy( intf_thread_t *pIntf )
 {
-    if( pIntf->p_sys->p_queue )
-    {
-        delete pIntf->p_sys->p_queue;
-        pIntf->p_sys->p_queue = NULL;
-    }
+    delete pIntf->p_sys->p_queue;
+    pIntf->p_sys->p_queue = NULL;
 }
 
 
 void AsyncQueue::push( const CmdGenericPtr &rcCommand, bool removePrev )
 {
+    vlc_mutex_lock( &m_lock );
+
     if( removePrev )
     {
         // Remove the commands of the same type
-        remove( rcCommand.get()->getType() );
+        remove( rcCommand.get()->getType(), rcCommand );
     }
     m_cmdList.push_back( rcCommand );
+
+    vlc_mutex_unlock( &m_lock );
 }
 
 
-void AsyncQueue::remove( const string &rType )
+void AsyncQueue::remove( const string &rType, const CmdGenericPtr &rcCommand )
 {
-    vlc_mutex_lock( &m_lock );
-
-    list<CmdGenericPtr>::iterator it;
-    for( it = m_cmdList.begin(); it != m_cmdList.end(); it++ )
+    cmdList_t::iterator it;
+    for( it = m_cmdList.begin(); it != m_cmdList.end(); /* nothing */ )
     {
-        // Remove the command if it is of the given type
-        if( (*it).get()->getType() == rType )
+        // Remove the command if it is of the given type and the command
+        // doesn't disagree. Note trickery to avoid skipping entries
+        // while maintaining iterator validity.
+
+        if( (*it).get()->getType() == rType &&
+            rcCommand.get()->checkRemove( (*it).get() ) )
         {
-            list<CmdGenericPtr>::iterator itNew = it;
-            itNew++;
+            cmdList_t::iterator itNew = it;
+            ++itNew;
             m_cmdList.erase( it );
             it = itNew;
         }
+        else ++it;
     }
-
-    vlc_mutex_unlock( &m_lock );
 }