mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-05-30 20:05:51 +00:00
Replace all CRITICAL_SECTION usage with std::mutex and std::lock_guard
Migrates 59 files from WinAPI CRITICAL_SECTION to portable C++ std::mutex/std::lock_guard/std::unique_lock. Removes Linux CRITICAL_SECTION shims from winapi_stubs.h.
This commit is contained in:
@@ -57,8 +57,6 @@ PlayerConnection::PlayerConnection(MinecraftServer* server,
|
||||
this->player = player;
|
||||
// player->connection = this; // 4J - moved out as we can't
|
||||
// assign in a ctor
|
||||
InitializeCriticalSection(&done_cs);
|
||||
|
||||
m_bCloseOnTick = false;
|
||||
m_bWasKicked = false;
|
||||
|
||||
@@ -73,7 +71,6 @@ PlayerConnection::PlayerConnection(MinecraftServer* server,
|
||||
|
||||
PlayerConnection::~PlayerConnection() {
|
||||
delete connection;
|
||||
DeleteCriticalSection(&done_cs);
|
||||
}
|
||||
|
||||
void PlayerConnection::tick() {
|
||||
@@ -106,9 +103,8 @@ void PlayerConnection::tick() {
|
||||
}
|
||||
|
||||
void PlayerConnection::disconnect(DisconnectPacket::eDisconnectReason reason) {
|
||||
EnterCriticalSection(&done_cs);
|
||||
std::lock_guard<std::mutex> lock(done_cs);
|
||||
if (done) {
|
||||
LeaveCriticalSection(&done_cs);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -135,7 +131,6 @@ void PlayerConnection::disconnect(DisconnectPacket::eDisconnectReason reason) {
|
||||
|
||||
server->getPlayers()->remove(player);
|
||||
done = true;
|
||||
LeaveCriticalSection(&done_cs);
|
||||
}
|
||||
|
||||
void PlayerConnection::handlePlayerInput(
|
||||
@@ -555,7 +550,7 @@ void PlayerConnection::handleUseItem(std::shared_ptr<UseItemPacket> packet) {
|
||||
|
||||
void PlayerConnection::onDisconnect(DisconnectPacket::eDisconnectReason reason,
|
||||
void* reasonObjects) {
|
||||
EnterCriticalSection(&done_cs);
|
||||
std::lock_guard<std::mutex> lock(done_cs);
|
||||
if (done) return;
|
||||
// logger.info(player.name + " lost connection: " + reason);
|
||||
// 4J-PB - removed, since it needs to be localised in the language the
|
||||
@@ -572,7 +567,6 @@ void PlayerConnection::onDisconnect(DisconnectPacket::eDisconnectReason reason,
|
||||
}
|
||||
server->getPlayers()->remove(player);
|
||||
done = true;
|
||||
LeaveCriticalSection(&done_cs);
|
||||
}
|
||||
|
||||
void PlayerConnection::onUnhandledPacket(std::shared_ptr<Packet> packet) {
|
||||
|
||||
Reference in New Issue
Block a user