fix: add lock to repositories

This commit is contained in:
k0t9i
2023-02-01 16:45:12 +04:00
parent 9a0204c6ed
commit 1bd107ad0a
4 changed files with 19 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
#pragma once
#include <map>
#include <shared_mutex>
#include "../GameStructs/NetworkHandlerWrapper.h"
#include "Domain/Repositories/EntityRepositoryInterface.h"
#include "../Factories/NPCFactory.h"
@@ -19,6 +20,8 @@ namespace Interlude
public:
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override
{
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
const auto creatures = FindAllObjects<User*>(m_Radius, [this](float_t radius, int32_t prevId) {
return m_NetworkHandler.GetNextCreature(radius, prevId);
});
@@ -49,6 +52,7 @@ namespace Interlude
void Reset() override
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
m_EntityHandler.Reset();
}
@@ -112,5 +116,6 @@ namespace Interlude
const NetworkHandlerWrapper& m_NetworkHandler;
const uint16_t m_Radius = 0;
EntityHandler& m_EntityHandler;
std::shared_timed_mutex m_Mutex;
};
}