Skip to content

Commit

Permalink
Reduce sender CPU usage on Linux/macOS
Browse files Browse the repository at this point in the history
Threads works differently under Unix(alike), than under Windows; So also use a small sleep with tickLoop on these platforms
  • Loading branch information
marcusbirkin committed Nov 21, 2022
1 parent 68a6a47 commit db986ab
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/sacn/sacnsender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@

#include "preferences.h"

using namespace std::chrono_literals;
#if defined(Q_OS_UNIX)
constexpr auto tickLoopInterval = 1ms;
#elif defined(Q_OS_WIN)
constexpr auto tickLoopInterval = 0ms; // Don't use on Windows
#endif
const auto tickLoopPriority = QThread::LowestPriority;

sACNSentUniverse::sACNSentUniverse(int universe) :
Expand Down Expand Up @@ -435,11 +441,16 @@ void CStreamServer::TickLoop()
{
qDebug() << "sACNSender" << QThread::currentThreadId()
<< ": Starting with priority"
<< this->thread()->priority();
<< this->thread()->priority()
<< " and tickLoopInterval"
<< std::chrono::duration_cast<std::chrono::milliseconds>(tickLoopInterval).count() << "ms";

assert(this->thread()->priority() <= QThread::LowestPriority);
Q_ASSERT(this->thread()->priority() == tickLoopPriority);

while (!m_thread_stop) {
if (tickLoopInterval.count())
QThread::usleep(std::chrono::duration_cast<std::chrono::microseconds>(tickLoopInterval).count());

QMutexLocker locker(&m_writeMutex);

int valid_count = 0;
Expand Down

0 comments on commit db986ab

Please sign in to comment.