Kaydet (Commit) 6b1b5b7c authored tarafından Minh Ngo's avatar Minh Ngo

Thread safe queue + event handler

Change-Id: I4c08179d6e5e2a6d8a3637e7ca306458cc59dfc8
üst 6f41d3db
...@@ -11,12 +11,18 @@ ...@@ -11,12 +11,18 @@
namespace VLC namespace VLC
{ {
EventHandler::EventHandler( const char *name ) EventHandler::EventHandler()
: Thread( name ) : ::osl::Thread()
{ {
} }
void EventHandler::execute() void EventHandler::stop()
{
mCallbackQueue.push(TCallback());
join();
}
void EventHandler::run()
{ {
TCallback callback; TCallback callback;
do do
...@@ -25,8 +31,8 @@ void EventHandler::execute() ...@@ -25,8 +31,8 @@ void EventHandler::execute()
if ( callback.empty() ) if ( callback.empty() )
return; return;
else
callback(); callback();
} while ( true ); } while ( true );
} }
......
...@@ -15,13 +15,14 @@ ...@@ -15,13 +15,14 @@
namespace VLC namespace VLC
{ {
class EventHandler : public salhelper::Thread class EventHandler : public ::osl::Thread
{ {
public: public:
EventHandler( const char* name ); EventHandler();
void stop();
protected: protected:
virtual void execute(); virtual void run();
public: public:
typedef boost::function< void() > TCallback; typedef boost::function< void() > TCallback;
......
...@@ -52,22 +52,21 @@ void ThreadsafeQueue<T>::push( const T& data ) ...@@ -52,22 +52,21 @@ void ThreadsafeQueue<T>::push( const T& data )
{ {
::osl::MutexGuard guard( mMutex ); ::osl::MutexGuard guard( mMutex );
mQueue.push( data ); mQueue.push( data );
mMutex.release();
mCondition.set(); mCondition.set();
} }
template<class T> template<class T>
void ThreadsafeQueue<T>::pop( T& data ) void ThreadsafeQueue<T>::pop( T& data )
{ {
mMutex.acquire(); mCondition.wait();
if ( mQueue.empty() ) ::osl::MutexGuard guard( mMutex );
while ( mQueue.empty() )
{ {
mMutex.release(); mMutex.release();
mCondition.wait(); mCondition.wait();
mCondition.reset(); mMutex.acquire();
} }
::osl::MutexGuard guard( mMutex );
data = mQueue.front(); data = mQueue.front();
mQueue.pop(); mQueue.pop();
} }
......
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