From 8c3f4cebba2eff4475f4bea4638aaca7575722a4 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Fri, 8 Sep 2006 04:10:47 +0000 Subject: [PATCH] Allow flushing of queued input events. --- stepmania/src/InputFilter.cpp | 10 ++++++++++ stepmania/src/InputFilter.h | 1 + 2 files changed, 11 insertions(+) diff --git a/stepmania/src/InputFilter.cpp b/stepmania/src/InputFilter.cpp index de166066d3..4e7a2f2426 100644 --- a/stepmania/src/InputFilter.cpp +++ b/stepmania/src/InputFilter.cpp @@ -354,6 +354,16 @@ void InputFilter::GetInputEvents( vector &array ) array.swap( queue ); } +void InputFilter::FlushInputEvents() +{ + /* Calling clear() will delete each InputEvent while holding the lock. + * This way, the LockMutex will be deleted before array which will unlock + * the mutex before deleting each InputEvent. */ + vector array; + LockMut(*queuemutex); + array.swap( queue ); +} + void InputFilter::GetPressedButtons( vector &array ) { LockMut(*queuemutex); diff --git a/stepmania/src/InputFilter.h b/stepmania/src/InputFilter.h index bb18a2514c..de35a2673b 100644 --- a/stepmania/src/InputFilter.h +++ b/stepmania/src/InputFilter.h @@ -61,6 +61,7 @@ public: RString GetButtonComment( const DeviceInput &di ) const; void GetInputEvents( vector &aEventOut ); + void FlushInputEvents(); void GetPressedButtons( vector &array ); private: