Index: src/Platform.cpp |
=================================================================== |
--- a/src/Platform.cpp |
+++ b/src/Platform.cpp |
@@ -47,16 +47,21 @@ |
ASSIGN_PLATFORM_PARAM(logSystem); |
ASSIGN_PLATFORM_PARAM(timer); |
ASSIGN_PLATFORM_PARAM(fileSystem); |
ASSIGN_PLATFORM_PARAM(webRequest); |
} |
Platform::~Platform() |
{ |
+ std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
+ logSystem.reset(); |
+ timer.reset(); |
+ fileSystem.reset(); |
+ webRequest.reset(); |
} |
void Platform::SetUpJsEngine(const AppInfo& appInfo, std::unique_ptr<IV8IsolateProvider> isolate) |
{ |
std::lock_guard<std::mutex> lock(modulesMutex); |
if (jsEngine) |
return; |
jsEngine = JsEngine::New(appInfo, *this, std::move(isolate)); |
@@ -90,29 +95,35 @@ |
} |
FilterEngine& Platform::GetFilterEngine() |
{ |
CreateFilterEngineAsync(); |
return *std::shared_future<FilterEnginePtr>(filterEngine).get(); |
} |
-ITimer& Platform::GetTimer() |
+void Platform::WithTimer(const WithTimerCallback& callback) |
{ |
- return *timer; |
+ std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
+ if (timer && callback) |
+ callback(*timer); |
} |
-IFileSystem& Platform::GetFileSystem() |
+void Platform::WithFileSystem(const WithFileSystemCallback& callback) |
{ |
- return *fileSystem; |
+ std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
+ if (fileSystem && callback) |
+ callback(*fileSystem); |
} |
-IWebRequest& Platform::GetWebRequest() |
+void Platform::WithWebRequest(const WithWebRequestCallback& callback) |
{ |
- return *webRequest; |
+ std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
+ if (webRequest && callback) |
+ callback(*webRequest); |
} |
LogSystem& Platform::GetLogSystem() |
{ |
return *logSystem; |
} |
namespace |
@@ -182,9 +193,9 @@ |
if (!fileSystem) |
CreateDefaultFileSystem(); |
if (!webRequest) |
CreateDefaultWebRequest(); |
std::unique_ptr<Platform> platform(new DefaultPlatform(asyncExecutor, std::move(*this))); |
asyncExecutor.reset(); |
return platform; |
-} |
+} |