From 00d8d232366f418d3a25046786ab9ab5c90a52c2 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 1 Jun 2016 16:33:45 +0600 Subject: CLOUD: Add mutexes in Storage --- backends/cloud/storage.cpp | 9 ++++++++- backends/cloud/storage.h | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'backends') 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(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(); -- cgit v1.2.3