Skip to content

Commit

Permalink
Rename the BasicPubSubManager thread
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada committed Dec 3, 2023
1 parent 934e518 commit 06cb7d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ set(SOURCE_FILES
util/RapidjsonHelpers.hpp
util/RatelimitBucket.cpp
util/RatelimitBucket.hpp
util/RenameThread.hpp
util/SampleData.cpp
util/SampleData.hpp
util/SharedPtrElementLess.hpp
Expand Down
3 changes: 3 additions & 0 deletions src/providers/liveupdates/BasicPubSubManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "providers/twitch/PubSubHelpers.hpp"
#include "util/DebugCount.hpp"
#include "util/ExponentialBackoff.hpp"
#include "util/RenameThread.hpp"

#include <pajlada/signals/signal.hpp>
#include <QJsonObject>
Expand Down Expand Up @@ -118,6 +119,8 @@ class BasicPubSubManager
this->mainThread_.reset(new std::thread([this] {
runThread();
}));

renameThread(*this->mainThread_.get(), "BPSM");
}

void stop()
Expand Down
19 changes: 19 additions & 0 deletions src/util/RenameThread.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <QtGlobal>

#ifdef Q_OS_LINUX
# include <pthread.h>
#endif

namespace chatterino {

template <typename T>
void renameThread(T &&thread, const char *threadName)
{
#ifdef Q_OS_LINUX
pthread_setname_np(thread.native_handle(), threadName);
#endif
}

} // namespace chatterino

0 comments on commit 06cb7d5

Please sign in to comment.