added code to handle a single connection

This commit is contained in:
fourtf
2018-07-16 17:23:41 +02:00
parent e51c5c692a
commit 3b3c5d8d75
18 changed files with 114 additions and 84 deletions
+13 -12
View File
@@ -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