aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud
diff options
context:
space:
mode:
Diffstat (limited to 'backends/cloud')
-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();