AsyncQueue::AsyncQueue( intf_thread_t *pIntf ): SkinObject( pIntf )
{
+ // Initialize the mutex
+ vlc_mutex_init( pIntf, &m_lock );
+
// Create a timer
OSFactory *pOsFactory = OSFactory::instance( pIntf );
m_pTimer = pOsFactory->createOSTimer( Callback( this, &doFlush ) );
AsyncQueue::~AsyncQueue()
{
delete( m_pTimer );
+ vlc_mutex_destroy( &m_lock );
}
void AsyncQueue::remove( const string &rType )
{
+ vlc_mutex_lock( &m_lock );
+
list<CmdGenericPtr>::iterator it;
for( it = m_cmdList.begin(); it != m_cmdList.end(); it++ )
{
it = itNew;
}
}
+
+ vlc_mutex_unlock( &m_lock );
}
void AsyncQueue::flush()
{
+ vlc_mutex_lock( &m_lock );
+
while( m_cmdList.size() > 0 )
{
- // Execute the first command in the queue
- CmdGenericPtr &rcCommand = m_cmdList.front();
- rcCommand.get()->execute();
- // And remove it
+ // Pop the first command from the queue
+ CmdGenericPtr cCommand = m_cmdList.front();
m_cmdList.pop_front();
+ // And execute it
+ cCommand.get()->execute();
}
+
+ vlc_mutex_unlock( &m_lock );
}
* async_queue.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
- * $Id: async_queue.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
+ * $Id$
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
list<CmdGenericPtr> m_cmdList;
/// Timer
OSTimer *m_pTimer;
+ /// Mutex
+ vlc_mutex_t m_lock;
// Private because it is a singleton
AsyncQueue( intf_thread_t *pIntf );