aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Tkachev2016-06-01 16:33:45 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit00d8d232366f418d3a25046786ab9ab5c90a52c2 (patch)
treea100c2386b4e6fe4e405050790b8503751011855
parentb3bf5322117d03c003011839ea1e7897c48183fa (diff)
downloadscummvm-rg350-00d8d232366f418d3a25046786ab9ab5c90a52c2.tar.gz
scummvm-rg350-00d8d232366f418d3a25046786ab9ab5c90a52c2.tar.bz2
scummvm-rg350-00d8d232366f418d3a25046786ab9ab5c90a52c2.zip
CLOUD: Add mutexes in Storage
-rw-r--r--backends/cloud/storage.cpp9
-rw-r--r--backends/cloud/storage.h4
2 files changed, 11 insertions, 2 deletions
diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp
index 0f9a2a168a..f035c93368 100644
--- a/backends/cloud/storage.cpp
+++ b/backends/cloud/storage.cpp
@@ -44,14 +44,18 @@ void Storage::printErrorResponse(Networking::ErrorResponse error) {
}
Networking::Request *Storage::addRequest(Networking::Request *request) {
+ _runningRequestsMutex.lock();
++_runningRequestsCount;
if (_runningRequestsCount == 1) debug("Storage is working now");
+ _runningRequestsMutex.unlock();
return ConnMan.addRequest(request, new Common::Callback<Storage, Networking::Request *>(this, &Storage::requestFinishedCallback));
}
void Storage::requestFinishedCallback(Networking::Request *invalidRequestPointer) {
+ _runningRequestsMutex.lock();
--_runningRequestsCount;
if (_runningRequestsCount == 0) debug("Storage is not working now");
+ _runningRequestsMutex.unlock();
}
Networking::Request *Storage::upload(Common::String remotePath, Common::String localPath, UploadCallback callback, Networking::ErrorCallback errorCallback) {
@@ -97,7 +101,10 @@ Networking::Request *Storage::syncSaves(BoolCallback callback, Networking::Error
}
bool Storage::isWorking() {
- return _runningRequestsCount > 0;
+ _runningRequestsMutex.lock();
+ bool working = _runningRequestsCount > 0;
+ _runningRequestsMutex.unlock();
+ return working;
}
} // End of namespace Cloud
diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h
index b1c62ba05b..1276b81827 100644
--- a/backends/cloud/storage.h
+++ b/backends/cloud/storage.h
@@ -28,9 +28,10 @@
#include "backends/networking/curl/request.h"
#include "backends/networking/curl/curlrequest.h"
#include "common/array.h"
+#include "common/callback.h"
+#include "common/mutex.h"
#include "common/stream.h"
#include "common/str.h"
-#include "common/callback.h"
namespace Cloud {
@@ -51,6 +52,7 @@ public:
protected:
/** Keeps track of running requests. */
uint32 _runningRequestsCount;
+ Common::Mutex _runningRequestsMutex;
/** Returns default error callback (printErrorResponse). */
virtual Networking::ErrorCallback getErrorPrintingCallback();