CLOUD: Add some mutexes in LocalWebserver

This commit is contained in:
Alexander Tkachev 2016-06-18 14:15:25 +06:00
parent 5e70f64e10
commit 6ac69729d5
2 changed files with 14 additions and 1 deletions

View file

@ -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) {

View file

@ -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();