Skip to content

Commit

Permalink
Merge pull request #656 from galkinvv/fix-win10-cpu-usage-spikes
Browse files Browse the repository at this point in the history
Fixes high cpu usage spikes on win10
  • Loading branch information
p12tic authored Jun 4, 2020
2 parents 8df50c7 + 95f2a84 commit 0f29c77
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
6 changes: 0 additions & 6 deletions src/lib/base/EventQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,6 @@ EventQueue::removeHandlers(void* target)
}
}

bool
EventQueue::isEmpty() const
{
return (m_buffer->isEmpty() && getNextTimerTimeout() != 0.0);
}

IEventJob*
EventQueue::getHandler(Event::Type type, void* target) const
{
Expand Down
1 change: 0 additions & 1 deletion src/lib/base/EventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class EventQueue : public IEventQueue {
virtual void removeHandlers(void* target);
virtual Event::Type
registerTypeOnce(Event::Type& type, const char* name);
virtual bool isEmpty() const;
virtual IEventJob* getHandler(Event::Type type, void* target) const;
virtual const char* getTypeName(Event::Type type);
virtual Event::Type getRegisteredType(const std::string& name) const;
Expand Down
7 changes: 0 additions & 7 deletions src/lib/base/IEventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,6 @@ class IEventQueue : public IInterface {
//! @name accessors
//@{

//! Test if queue is empty
/*!
Returns true iff the queue has no events in it, including timer
events.
*/
virtual bool isEmpty() const = 0;

//! Get an event handler
/*!
Finds and returns the event handler for the \p type, \p target pair
Expand Down
16 changes: 12 additions & 4 deletions src/lib/platform/MSWindowsEventQueueBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "arch/win32/ArchMiscWindows.h"
#include "mt/Thread.h"
#include "base/IEventQueue.h"
#include <VersionHelpers.h>

//
// EventQueueTimer
Expand Down Expand Up @@ -48,6 +49,15 @@ MSWindowsEventQueueBuffer::MSWindowsEventQueueBuffer(IEventQueue* events) :
// make sure this thread has a message queue
MSG dummy;
PeekMessage(&dummy, NULL, WM_USER, WM_USER, PM_NOREMOVE);

m_os_supported_message_types = QS_ALLINPUT;
if (!IsWindows8OrGreater())
{
// don't use QS_POINTER, QS_TOUCH
// because they can cause GetQueueStatus() to always return 0 and we miss events
// since those flags are confusing Windows 7. See QTBUG-29097 for related info
m_os_supported_message_types &= ~(QS_TOUCH | QS_POINTER);
}
}

MSWindowsEventQueueBuffer::~MSWindowsEventQueueBuffer()
Expand Down Expand Up @@ -79,7 +89,7 @@ MSWindowsEventQueueBuffer::waitForEvent(double timeout)
// cancellation but that's okay because we're run in the main
// thread and we never cancel that thread.
HANDLE dummy[1];
MsgWaitForMultipleObjects(0, dummy, FALSE, t, QS_ALLINPUT);
MsgWaitForMultipleObjects(0, dummy, FALSE, t, m_os_supported_message_types);
}

IEventQueueBuffer::Type
Expand Down Expand Up @@ -128,9 +138,7 @@ MSWindowsEventQueueBuffer::addEvent(UInt32 dataID)
bool
MSWindowsEventQueueBuffer::isEmpty() const
{
// don't use QS_POINTER, QS_TOUCH, or any meta-flags that include them (like QS_ALLINPUT)
// because they can cause GetQueueStatus() to always return 0 and we miss events
return (HIWORD(GetQueueStatus(QS_POSTMESSAGE)) == 0);
return (HIWORD(GetQueueStatus(m_os_supported_message_types)) == 0);
}

EventQueueTimer*
Expand Down
1 change: 1 addition & 0 deletions src/lib/platform/MSWindowsEventQueueBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ class MSWindowsEventQueueBuffer : public IEventQueueBuffer {
MSG m_event;
UINT m_daemonQuit;
IEventQueue* m_events;
UINT m_os_supported_message_types;
};

0 comments on commit 0f29c77

Please sign in to comment.