added code to handle a single connection
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
QMap<QString, int64_t> DebugCount::counts_;
|
||||
std::mutex DebugCount::mut_;
|
||||
UniqueAccess<QMap<QString, int64_t>> DebugCount::counts_;
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
+13
-12
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <common/UniqueAccess.hpp>
|
||||
|
||||
#include <mutex>
|
||||
#include <typeinfo>
|
||||
|
||||
@@ -13,11 +15,11 @@ class DebugCount
|
||||
public:
|
||||
static void increase(const QString &name)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mut_);
|
||||
auto counts = counts_.access();
|
||||
|
||||
auto it = counts_.find(name);
|
||||
if (it == counts_.end()) {
|
||||
counts_.insert(name, 1);
|
||||
auto it = counts->find(name);
|
||||
if (it == counts->end()) {
|
||||
counts->insert(name, 1);
|
||||
} else {
|
||||
reinterpret_cast<int64_t &>(it.value())++;
|
||||
}
|
||||
@@ -25,11 +27,11 @@ public:
|
||||
|
||||
static void decrease(const QString &name)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mut_);
|
||||
auto counts = counts_.access();
|
||||
|
||||
auto it = counts_.find(name);
|
||||
if (it == counts_.end()) {
|
||||
counts_.insert(name, -1);
|
||||
auto it = counts->find(name);
|
||||
if (it == counts->end()) {
|
||||
counts->insert(name, -1);
|
||||
} else {
|
||||
reinterpret_cast<int64_t &>(it.value())--;
|
||||
}
|
||||
@@ -37,10 +39,10 @@ public:
|
||||
|
||||
static QString getDebugText()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mut_);
|
||||
auto counts = counts_.access();
|
||||
|
||||
QString text;
|
||||
for (auto it = counts_.begin(); it != counts_.end(); it++) {
|
||||
for (auto it = counts->begin(); it != counts->end(); it++) {
|
||||
text += it.key() + ": " + QString::number(it.value()) + "\n";
|
||||
}
|
||||
return text;
|
||||
@@ -52,8 +54,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
static QMap<QString, int64_t> counts_;
|
||||
static std::mutex mut_;
|
||||
static UniqueAccess<QMap<QString, int64_t>> counts_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user