OpenFusion/src/CNShared.cpp

28 lines
758 B
C++
Raw Normal View History

2020-08-18 20:42:30 +00:00
#include "CNShared.hpp"
2020-08-19 20:42:44 +00:00
#if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS)
2020-08-18 20:42:30 +00:00
#include "mingw/mingw.mutex.h"
#else
#include <mutex>
#endif
std::map<int64_t, Player> CNSharedData::players;
std::mutex playerCrit;
void CNSharedData::setPlayer(int64_t sk, Player& plr) {
std::lock_guard<std::mutex> lock(playerCrit); // the lock will be removed when the function ends
players[sk] = plr;
}
Player CNSharedData::getPlayer(int64_t sk) {
std::lock_guard<std::mutex> lock(playerCrit); // the lock will be removed when the function ends
2020-08-18 20:42:30 +00:00
return players[sk];
}
void CNSharedData::erasePlayer(int64_t sk) {
std::lock_guard<std::mutex> lock(playerCrit); // the lock will be removed when the function ends
players.erase(sk);
}