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