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

@@ -2,6 +2,7 @@
#include <map>
#include <memory>
#include <shared_mutex>
#include "Domain/Repositories/EntityRepositoryInterface.h"
#include "Domain/DTO/EntityState.h"
#include "../Factories/DropFactory.h"
@@ -18,6 +19,8 @@ namespace Interlude
public:
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override
{
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
const std::map<uint32_t, Item*> items = FindAllObjects<Item*>(m_Radius, [this](float_t radius, int32_t prevId) {
return m_NetworkHandler.GetNextItem(radius, prevId);
});
@@ -37,6 +40,7 @@ namespace Interlude
void Reset() override
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
m_Container.Reset();
}
@@ -57,5 +61,6 @@ namespace Interlude
const DropFactory& m_Factory;
const uint16_t m_Radius;
EntityHandler& m_Container;
std::shared_timed_mutex m_Mutex;
};
}