Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/Platform.cpp

Issue 29727558: Issue 6489 - fix initialization moment of the default scheduler of DefaultPlatformBuilder (Closed) Base URL: https://github.com/adblockplus/libadblockplus@cd1cd70ea3122fb4b8a96c40d96ce9b1ae5a3ae9
Patch Set: fix typo Created March 19, 2018, 12:33 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/AdblockPlus/Platform.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/Platform.cpp
diff --git a/src/Platform.cpp b/src/Platform.cpp
index 2f8c6795aa8dd6e485a2590294dcdef415cc8406..ffe6e69056b4eb57516e2363b7d79040ff1ec406 100644
--- a/src/Platform.cpp
+++ b/src/Platform.cpp
@@ -117,35 +117,10 @@ void Platform::WithLogSystem(const WithLogSystemCallback& callback)
namespace
{
- class SharedAsyncExecutor {
- public:
- SharedAsyncExecutor()
- : executor(new AsyncExecutor())
- {
- }
- void Dispatch(const std::function<void()>& task) {
- std::lock_guard<std::mutex> lock(asyncExecutorMutex);
- if (!executor)
- return;
- executor->Dispatch(task);
- }
- void Invalidate() {
- std::unique_ptr<AsyncExecutor> tmp;
- {
- std::lock_guard<std::mutex> lock(asyncExecutorMutex);
- tmp = move(executor);
- }
- }
- private:
- std::mutex asyncExecutorMutex;
- std::unique_ptr<AsyncExecutor> executor;
- };
-
class DefaultPlatform : public Platform
{
public:
- typedef std::shared_ptr<SharedAsyncExecutor> AsyncExecutorPtr;
- explicit DefaultPlatform(const AsyncExecutorPtr& asyncExecutor, CreationParameters&& creationParams)
+ explicit DefaultPlatform(DefaultPlatformBuilder::AsyncExecutorPtr asyncExecutor, CreationParameters&& creationParams)
: Platform(std::move(creationParams)), asyncExecutor(asyncExecutor)
{
}
@@ -157,7 +132,7 @@ namespace
void WithLogSystem(const WithLogSystemCallback&) override;
private:
- AsyncExecutorPtr asyncExecutor;
+ DefaultPlatformBuilder::AsyncExecutorPtr asyncExecutor;
std::recursive_mutex interfacesMutex;
};
@@ -202,6 +177,15 @@ namespace
}
}
+DefaultPlatformBuilder::DefaultPlatformBuilder()
+{
+ auto sharedAsyncExecutor = this->sharedAsyncExecutor = std::make_shared<OptionalAsyncExecutor>();
+ defaultScheduler = [sharedAsyncExecutor](const SchedulerTask& task)
+ {
+ sharedAsyncExecutor->Dispatch(task);
+ };
+}
+
Scheduler DefaultPlatformBuilder::GetDefaultAsyncExecutor()
{
return defaultScheduler;
@@ -231,11 +215,7 @@ void DefaultPlatformBuilder::CreateDefaultLogSystem()
std::unique_ptr<Platform> DefaultPlatformBuilder::CreatePlatform()
{
- auto sharedAsyncExecutor = std::make_shared<SharedAsyncExecutor>();
- defaultScheduler = [sharedAsyncExecutor](const SchedulerTask& task)
- {
- sharedAsyncExecutor->Dispatch(task);
- };
+
if (!logSystem)
CreateDefaultLogSystem();
if (!timer)
@@ -245,6 +225,6 @@ std::unique_ptr<Platform> DefaultPlatformBuilder::CreatePlatform()
if (!webRequest)
CreateDefaultWebRequest();
- std::unique_ptr<Platform> platform(new DefaultPlatform(sharedAsyncExecutor, std::move(*this)));
+ std::unique_ptr<Platform> platform(new DefaultPlatform(std::move(sharedAsyncExecutor), std::move(*this)));
return platform;
}
« no previous file with comments | « include/AdblockPlus/Platform.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld