Commit ff8bace6 authored by Cyril Deguet's avatar Cyril Deguet

* async_queue.*: AsyncQueue::remove is now thread-safe to avoid potential

  (but *very* unlikely) segfaults
parent f53b5e07
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
AsyncQueue::AsyncQueue( intf_thread_t *pIntf ): SkinObject( pIntf ) AsyncQueue::AsyncQueue( intf_thread_t *pIntf ): SkinObject( pIntf )
{ {
// Initialize the mutex
vlc_mutex_init( pIntf, &m_lock );
// Create a timer // Create a timer
OSFactory *pOsFactory = OSFactory::instance( pIntf ); OSFactory *pOsFactory = OSFactory::instance( pIntf );
m_pTimer = pOsFactory->createOSTimer( Callback( this, &doFlush ) ); m_pTimer = pOsFactory->createOSTimer( Callback( this, &doFlush ) );
...@@ -41,6 +44,7 @@ AsyncQueue::AsyncQueue( intf_thread_t *pIntf ): SkinObject( pIntf ) ...@@ -41,6 +44,7 @@ AsyncQueue::AsyncQueue( intf_thread_t *pIntf ): SkinObject( pIntf )
AsyncQueue::~AsyncQueue() AsyncQueue::~AsyncQueue()
{ {
delete( m_pTimer ); delete( m_pTimer );
vlc_mutex_destroy( &m_lock );
} }
...@@ -78,6 +82,8 @@ void AsyncQueue::push( const CmdGenericPtr &rcCommand ) ...@@ -78,6 +82,8 @@ void AsyncQueue::push( const CmdGenericPtr &rcCommand )
void AsyncQueue::remove( const string &rType ) void AsyncQueue::remove( const string &rType )
{ {
vlc_mutex_lock( &m_lock );
list<CmdGenericPtr>::iterator it; list<CmdGenericPtr>::iterator it;
for( it = m_cmdList.begin(); it != m_cmdList.end(); it++ ) for( it = m_cmdList.begin(); it != m_cmdList.end(); it++ )
{ {
...@@ -90,19 +96,25 @@ void AsyncQueue::remove( const string &rType ) ...@@ -90,19 +96,25 @@ void AsyncQueue::remove( const string &rType )
it = itNew; it = itNew;
} }
} }
vlc_mutex_unlock( &m_lock );
} }
void AsyncQueue::flush() void AsyncQueue::flush()
{ {
vlc_mutex_lock( &m_lock );
while( m_cmdList.size() > 0 ) while( m_cmdList.size() > 0 )
{ {
// Execute the first command in the queue // Pop the first command from the queue
CmdGenericPtr &rcCommand = m_cmdList.front(); CmdGenericPtr cCommand = m_cmdList.front();
rcCommand.get()->execute();
// And remove it
m_cmdList.pop_front(); m_cmdList.pop_front();
// And execute it
cCommand.get()->execute();
} }
vlc_mutex_unlock( &m_lock );
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* async_queue.hpp * async_queue.hpp
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * 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> * Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr> * Olivier Teulière <ipkiss@via.ecp.fr>
...@@ -58,6 +58,8 @@ class AsyncQueue: public SkinObject ...@@ -58,6 +58,8 @@ class AsyncQueue: public SkinObject
list<CmdGenericPtr> m_cmdList; list<CmdGenericPtr> m_cmdList;
/// Timer /// Timer
OSTimer *m_pTimer; OSTimer *m_pTimer;
/// Mutex
vlc_mutex_t m_lock;
// Private because it is a singleton // Private because it is a singleton
AsyncQueue( intf_thread_t *pIntf ); AsyncQueue( intf_thread_t *pIntf );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment