* $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
*
* 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"
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 );
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 );
}