Replace multi-process logic to multi-thread logic #2

Merged
bartfaik04 merged 4 commits from process-to-threads into main 2025-06-01 12:18:06 +02:00
Showing only changes of commit 23d0216a27 - Show all commits

View File

@@ -5,6 +5,7 @@
#include <map>
#include <vector>
#include <sstream>
#include <mutex>
#include "locations.h"
std::vector<std::string> splitLogFile(const std::string& input, char delimiter);
@@ -13,6 +14,7 @@ class userManager
{
private:
std::map<std::string, bool> users;
std::mutex mtx;
public:
@@ -23,6 +25,7 @@ public:
void addUser(std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
if (users.count(user) == 0)
{
users[user] = false;
@@ -31,16 +34,19 @@ public:
void removeUser(std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
users.erase(user);
}
bool isContains(std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
return users.count(user) == 1;
}
void setUserFlagged(std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
if (users.count(user) == 1)
{
users[user] = true;
@@ -49,6 +55,7 @@ public:
void setUserUnflagged(std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
if (users.count(user) == 1)
{
users[user] = false;
@@ -57,6 +64,7 @@ public:
void unflagAllUsers()
{
std::lock_guard<std::mutex> lock(mtx);
for (std::map<std::string, bool>::iterator it = users.begin(); it != users.end(); ++it)
{
it->second = false;
@@ -67,6 +75,8 @@ public:
{
std::vector<std::string> ret;
std::lock_guard<std::mutex> lock(mtx);
for (std::map<std::string, bool>::iterator it = users.begin(); it != users.end(); ++it)
{
ret.push_back(it->first);
@@ -79,6 +89,8 @@ public:
{
std::vector<std::string> ret;
std::lock_guard<std::mutex> lock(mtx);
for (std::map<std::string, bool>::iterator it = users.begin(); it != users.end(); ++it)
{
if (it->second)