[vlc-commits] Qt: eventratelimiter: use mutex
Francois Cartegnie
git at videolan.org
Thu Aug 23 18:58:59 CEST 2012
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Aug 22 21:55:36 2012 +0200| [ddf9e6da14762a84d5c64eecd25015daef388098] | committer: Francois Cartegnie
Qt: eventratelimiter: use mutex
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ddf9e6da14762a84d5c64eecd25015daef388098
---
modules/gui/qt4/util/uniqueevent.cpp | 17 +++++++++++++++--
modules/gui/qt4/util/uniqueevent.hpp | 2 ++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/modules/gui/qt4/util/uniqueevent.cpp b/modules/gui/qt4/util/uniqueevent.cpp
index e116bb3..7dade60 100644
--- a/modules/gui/qt4/util/uniqueevent.cpp
+++ b/modules/gui/qt4/util/uniqueevent.cpp
@@ -21,10 +21,12 @@
#include <QTimer>
#include <QApplication>
+#include <QMutex>
RateLimitedEventPoster::RateLimitedEventPoster( int i_millisec_interval )
{
timer = new QTimer();
+ mutex = new QMutex();
timer->setSingleShot( true );
/* Assuming a 24fps event loop, delays at least events to the next frame */
if ( i_millisec_interval < 1 )
@@ -38,28 +40,39 @@ RateLimitedEventPoster::~RateLimitedEventPoster()
timer->stop();
commit();
delete timer;
+ delete mutex;
}
void RateLimitedEventPoster::postEvent( UniqueEvent *e, QObject *target )
{
event_tuple newtuple = { target, e };
- foreach( event_tuple tuple, eventsList )
+ mutex->lock();
+ foreach( const event_tuple & tuple, eventsList )
{
if ( target == tuple.target && tuple.event->equals( e ) )
{
delete e;
+ mutex->unlock();
return;
}
}
eventsList << newtuple;
+ mutex->unlock();
+ if ( eventsList.count() >= 100 ) /* limit lookup time */
+ {
+ timer->stop();
+ commit();
+ }
if ( !timer->isActive() ) timer->start();
}
void RateLimitedEventPoster::commit()
{
- foreach( event_tuple tuple, eventsList )
+ mutex->lock();
+ foreach( const event_tuple & tuple, eventsList )
{
QApplication::postEvent( tuple.target, tuple.event );
}
eventsList.clear();
+ mutex->unlock();
}
diff --git a/modules/gui/qt4/util/uniqueevent.hpp b/modules/gui/qt4/util/uniqueevent.hpp
index 0eb2bd3..5065441 100644
--- a/modules/gui/qt4/util/uniqueevent.hpp
+++ b/modules/gui/qt4/util/uniqueevent.hpp
@@ -22,6 +22,7 @@
#include <QEvent>
#include <QList>
class QTimer;
+class QMutex;
class UniqueEvent : public QEvent
{
@@ -50,6 +51,7 @@ private:
};
QList<event_tuple> eventsList;
QTimer *timer;
+ QMutex *mutex;
};
#endif // UNIQUEEVENT_HPP
More information about the vlc-commits
mailing list