aboutsummaryrefslogtreecommitdiff
path: root/backends/networking/sdl_net
diff options
context:
space:
mode:
authorAlexander Tkachev2016-06-18 14:15:25 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit6ac69729d5c93899a3b1f5d82b6c5b008f030a7c (patch)
treec36c43a8d956f4e95b2c684342f4b488946c7f7e /backends/networking/sdl_net
parent5e70f64e108a3b155fc14f5087a7747e5c89f581 (diff)
downloadscummvm-rg350-6ac69729d5c93899a3b1f5d82b6c5b008f030a7c.tar.gz
scummvm-rg350-6ac69729d5c93899a3b1f5d82b6c5b008f030a7c.tar.bz2
scummvm-rg350-6ac69729d5c93899a3b1f5d82b6c5b008f030a7c.zip
CLOUD: Add some mutexes in LocalWebserver
Diffstat (limited to 'backends/networking/sdl_net')
-rw-r--r--backends/networking/sdl_net/localwebserver.cpp13
-rw-r--r--backends/networking/sdl_net/localwebserver.h2
2 files changed, 14 insertions, 1 deletions
diff --git a/backends/networking/sdl_net/localwebserver.cpp b/backends/networking/sdl_net/localwebserver.cpp
index d6033d1db1..1cfbbb8819 100644
--- a/backends/networking/sdl_net/localwebserver.cpp
+++ b/backends/networking/sdl_net/localwebserver.cpp
@@ -69,6 +69,7 @@ void LocalWebserver::stopTimer() {
}
void LocalWebserver::start() {
+ _handleMutex.lock();
_stopOnIdle = false;
if (_timerStarted) return;
startTimer();
@@ -93,9 +94,11 @@ void LocalWebserver::start() {
if (numused == -1) {
error("SDLNet_AddSocket: %s\n", SDLNet_GetError());
}
+ _handleMutex.unlock();
}
void LocalWebserver::stop() {
+ _handleMutex.lock();
if (_timerStarted) stopTimer();
if (_serverSocket) {
@@ -112,6 +115,7 @@ void LocalWebserver::stop() {
SDLNet_FreeSocketSet(_set);
_set = nullptr;
}
+ _handleMutex.unlock();
}
void LocalWebserver::stopOnIdle() { _stopOnIdle = true; }
@@ -129,6 +133,7 @@ void LocalWebserver::removePathHandler(Common::String path) {
IndexPageHandler &LocalWebserver::indexPageHandler() { return _indexPageHandler; }
void LocalWebserver::handle() {
+ _handleMutex.lock();
int numready = SDLNet_CheckSockets(_set, 0);
if (numready == -1) {
error("SDLNet_CheckSockets: %s\n", SDLNet_GetError());
@@ -145,7 +150,13 @@ void LocalWebserver::handle() {
if (_clients == 0) ++_idlingFrames;
else _idlingFrames = 0;
- if (_idlingFrames > FRAMES_PER_SECOND && _stopOnIdle) stop();
+ if (_idlingFrames > FRAMES_PER_SECOND && _stopOnIdle) {
+ _handleMutex.unlock();
+ stop();
+ return;
+ }
+
+ _handleMutex.unlock();
}
void LocalWebserver::handleClient(uint32 i) {
diff --git a/backends/networking/sdl_net/localwebserver.h b/backends/networking/sdl_net/localwebserver.h
index f51c33b418..2bd8daff5d 100644
--- a/backends/networking/sdl_net/localwebserver.h
+++ b/backends/networking/sdl_net/localwebserver.h
@@ -27,6 +27,7 @@
#include "backends/networking/sdl_net/indexpagehandler.h"
#include "common/callback.h"
#include "common/hash-str.h"
+#include "common/mutex.h"
#include "common/singleton.h"
#include "common/scummsys.h"
@@ -57,6 +58,7 @@ class LocalWebserver : public Common::Singleton<LocalWebserver> {
Common::HashMap<Common::String, ClientHandler> _pathHandlers;
IndexPageHandler _indexPageHandler;
uint32 _idlingFrames;
+ Common::Mutex _handleMutex;
void startTimer(int interval = TIMER_INTERVAL);
void stopTimer();