2021-03-17 19:07:40 +00:00
|
|
|
#include "core/CNShared.hpp"
|
2020-08-18 20:42:30 +00:00
|
|
|
|
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"
|
2020-09-14 13:53:48 +00:00
|
|
|
#else
|
2020-08-18 20:42:30 +00:00
|
|
|
#include <mutex>
|
|
|
|
#endif
|
2022-07-23 00:07:26 +00:00
|
|
|
std::map<int64_t, Player> CNShared::players;
|
2020-08-18 20:42:30 +00:00
|
|
|
std::mutex playerCrit;
|
|
|
|
|
2022-07-23 00:07:26 +00:00
|
|
|
void CNShared::setPlayer(int64_t sk, Player& plr) {
|
2020-08-18 20:42:30 +00:00
|
|
|
std::lock_guard<std::mutex> lock(playerCrit); // the lock will be removed when the function ends
|
|
|
|
|
|
|
|
players[sk] = plr;
|
|
|
|
}
|
|
|
|
|
2022-07-23 00:07:26 +00:00
|
|
|
Player CNShared::getPlayer(int64_t sk) {
|
2020-08-19 17:22:54 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2022-07-23 00:07:26 +00:00
|
|
|
void CNShared::erasePlayer(int64_t sk) {
|
2020-08-18 20:42:30 +00:00
|
|
|
std::lock_guard<std::mutex> lock(playerCrit); // the lock will be removed when the function ends
|
|
|
|
|
|
|
|
players.erase(sk);
|
|
|
|
}
|