Browse Source

Replace std::mutex with SdlMutex

pull/2130/head
staphen 5 years ago committed by Anders Jenbo
parent
commit
b6398b75d0
  1. 37
      Source/storm/storm_net.cpp

37
Source/storm/storm_net.cpp

@ -3,6 +3,7 @@
#include <mutex> #include <mutex>
#include <thread> #include <thread>
#include <utility> #include <utility>
#include "utils/sdl_mutex.h"
#endif #endif
#include "dvlnet/abstract_net.h" #include "dvlnet/abstract_net.h"
@ -18,13 +19,13 @@ static char gpszGameName[128] = {};
static char gpszGamePassword[128] = {}; static char gpszGamePassword[128] = {};
#ifndef NONET #ifndef NONET
static std::mutex storm_net_mutex; static SdlMutex storm_net_mutex;
#endif #endif
bool SNetReceiveMessage(int *senderplayerid, char **data, int *databytes) bool SNetReceiveMessage(int *senderplayerid, char **data, int *databytes)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
if (!dvlnet_inst->SNetReceiveMessage(senderplayerid, data, databytes)) { if (!dvlnet_inst->SNetReceiveMessage(senderplayerid, data, databytes)) {
SErrSetLastError(STORM_ERROR_NO_MESSAGES_WAITING); SErrSetLastError(STORM_ERROR_NO_MESSAGES_WAITING);
@ -36,7 +37,7 @@ bool SNetReceiveMessage(int *senderplayerid, char **data, int *databytes)
bool SNetSendMessage(int playerID, void *data, unsigned int databytes) bool SNetSendMessage(int playerID, void *data, unsigned int databytes)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
return dvlnet_inst->SNetSendMessage(playerID, data, databytes); return dvlnet_inst->SNetSendMessage(playerID, data, databytes);
} }
@ -45,7 +46,7 @@ bool SNetReceiveTurns(int a1, int arraysize, char **arraydata, unsigned int *arr
DWORD *arrayplayerstatus) DWORD *arrayplayerstatus)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
if (a1 != 0) if (a1 != 0)
UNIMPLEMENTED(); UNIMPLEMENTED();
@ -61,7 +62,7 @@ bool SNetReceiveTurns(int a1, int arraysize, char **arraydata, unsigned int *arr
bool SNetSendTurn(char *data, unsigned int databytes) bool SNetSendTurn(char *data, unsigned int databytes)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
return dvlnet_inst->SNetSendTurn(data, databytes); return dvlnet_inst->SNetSendTurn(data, databytes);
} }
@ -69,7 +70,7 @@ bool SNetSendTurn(char *data, unsigned int databytes)
int SNetGetProviderCaps(struct _SNETCAPS *caps) int SNetGetProviderCaps(struct _SNETCAPS *caps)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
return dvlnet_inst->SNetGetProviderCaps(caps); return dvlnet_inst->SNetGetProviderCaps(caps);
} }
@ -77,7 +78,7 @@ int SNetGetProviderCaps(struct _SNETCAPS *caps)
bool SNetUnregisterEventHandler(event_type evtype, SEVTHANDLER func) bool SNetUnregisterEventHandler(event_type evtype, SEVTHANDLER func)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
return dvlnet_inst->SNetUnregisterEventHandler(evtype, func); return dvlnet_inst->SNetUnregisterEventHandler(evtype, func);
} }
@ -85,7 +86,7 @@ bool SNetUnregisterEventHandler(event_type evtype, SEVTHANDLER func)
bool SNetRegisterEventHandler(event_type evtype, SEVTHANDLER func) bool SNetRegisterEventHandler(event_type evtype, SEVTHANDLER func)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
return dvlnet_inst->SNetRegisterEventHandler(evtype, func); return dvlnet_inst->SNetRegisterEventHandler(evtype, func);
} }
@ -93,7 +94,7 @@ bool SNetRegisterEventHandler(event_type evtype, SEVTHANDLER func)
bool SNetDestroy() bool SNetDestroy()
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
return true; return true;
} }
@ -101,7 +102,7 @@ bool SNetDestroy()
bool SNetDropPlayer(int playerid, DWORD flags) bool SNetDropPlayer(int playerid, DWORD flags)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
return dvlnet_inst->SNetDropPlayer(playerid, flags); return dvlnet_inst->SNetDropPlayer(playerid, flags);
} }
@ -109,7 +110,7 @@ bool SNetDropPlayer(int playerid, DWORD flags)
bool SNetGetGameInfo(game_info type, void *dst, unsigned int length) bool SNetGetGameInfo(game_info type, void *dst, unsigned int length)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
switch (type) { switch (type) {
case GAMEINFO_NAME: case GAMEINFO_NAME:
@ -126,7 +127,7 @@ bool SNetGetGameInfo(game_info type, void *dst, unsigned int length)
bool SNetLeaveGame(int type) bool SNetLeaveGame(int type)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
if (dvlnet_inst == nullptr) if (dvlnet_inst == nullptr)
return true; return true;
@ -140,7 +141,7 @@ bool SNetLeaveGame(int type)
bool SNetInitializeProvider(uint32_t provider, struct GameData *gameData) bool SNetInitializeProvider(uint32_t provider, struct GameData *gameData)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
dvlnet_inst = net::abstract_net::make_net(provider); dvlnet_inst = net::abstract_net::make_net(provider);
return mainmenu_select_hero_dialog(gameData); return mainmenu_select_hero_dialog(gameData);
@ -152,7 +153,7 @@ bool SNetInitializeProvider(uint32_t provider, struct GameData *gameData)
bool SNetCreateGame(const char *pszGameName, const char *pszGamePassword, char *gameTemplateData, int gameTemplateSize, int *playerID) bool SNetCreateGame(const char *pszGameName, const char *pszGamePassword, char *gameTemplateData, int gameTemplateSize, int *playerID)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
if (gameTemplateSize != sizeof(GameData)) if (gameTemplateSize != sizeof(GameData))
ABORT(); ABORT();
@ -175,7 +176,7 @@ bool SNetCreateGame(const char *pszGameName, const char *pszGamePassword, char *
bool SNetJoinGame(char *pszGameName, char *pszGamePassword, int *playerID) bool SNetJoinGame(char *pszGameName, char *pszGamePassword, int *playerID)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
if (pszGameName != nullptr) if (pszGameName != nullptr)
strncpy(gpszGameName, pszGameName, sizeof(gpszGameName) - 1); strncpy(gpszGameName, pszGameName, sizeof(gpszGameName) - 1);
@ -191,7 +192,7 @@ bool SNetJoinGame(char *pszGameName, char *pszGamePassword, int *playerID)
bool SNetGetOwnerTurnsWaiting(DWORD *turns) bool SNetGetOwnerTurnsWaiting(DWORD *turns)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
return dvlnet_inst->SNetGetOwnerTurnsWaiting(turns); return dvlnet_inst->SNetGetOwnerTurnsWaiting(turns);
} }
@ -199,7 +200,7 @@ bool SNetGetOwnerTurnsWaiting(DWORD *turns)
bool SNetGetTurnsInTransit(DWORD *turns) bool SNetGetTurnsInTransit(DWORD *turns)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
return dvlnet_inst->SNetGetTurnsInTransit(turns); return dvlnet_inst->SNetGetTurnsInTransit(turns);
} }
@ -210,7 +211,7 @@ bool SNetGetTurnsInTransit(DWORD *turns)
bool SNetSetBasePlayer(int) bool SNetSetBasePlayer(int)
{ {
#ifndef NONET #ifndef NONET
std::lock_guard<std::mutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
return true; return true;
} }

Loading…
Cancel
Save