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

Delta Between Two Patch Sets: src/Platform.cpp

Issue 29706560: Issue 5179 - Implement asynchronous executor with a controllable lifetime (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Left Patch Set: Created Feb. 23, 2018, 10:29 a.m.
Right Patch Set: address comments Created March 1, 2018, 11:14 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/AsyncExecutor.cpp ('k') | test/AsyncExecutor.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 110 }
111 111
112 void Platform::WithLogSystem(const WithLogSystemCallback& callback) 112 void Platform::WithLogSystem(const WithLogSystemCallback& callback)
113 { 113 {
114 if (logSystem && callback) 114 if (logSystem && callback)
115 callback(*logSystem); 115 callback(*logSystem);
116 } 116 }
117 117
118 namespace 118 namespace
119 { 119 {
120 class SharedAsyncExecutor { 120 class SharedAsyncExecutor {
sergei 2018/02/23 11:16:42 It's rather a compatibility thing to simplify the
121 public: 121 public:
122 SharedAsyncExecutor() 122 SharedAsyncExecutor()
123 : executor(new AsyncExecutor()) 123 : executor(new AsyncExecutor())
124 { 124 {
125 } 125 }
126 void Dispatch(const std::function<void()>& task) { 126 void Dispatch(const std::function<void()>& task) {
127 std::lock_guard<std::mutex> lock(asyncExecutorMutex); 127 std::lock_guard<std::mutex> lock(asyncExecutorMutex);
128 if (!executor) 128 if (!executor)
129 return; 129 return;
130 executor->Dispatch(task); 130 executor->Dispatch(task);
131 } 131 }
132 void Invalidate() { 132 void Invalidate() {
133 std::unique_ptr<AsyncExecutor> tmp; 133 std::unique_ptr<AsyncExecutor> tmp;
sergei 2018/02/23 11:16:42 JIC, it's needed to prevent dead locks. If `execut
134 { 134 {
135 std::lock_guard<std::mutex> lock(asyncExecutorMutex); 135 std::lock_guard<std::mutex> lock(asyncExecutorMutex);
136 tmp = move(executor); 136 tmp = move(executor);
137 } 137 }
138 } 138 }
139 private: 139 private:
140 std::mutex asyncExecutorMutex; 140 std::mutex asyncExecutorMutex;
141 std::unique_ptr<AsyncExecutor> executor; 141 std::unique_ptr<AsyncExecutor> executor;
142 }; 142 };
143 143
144 class DefaultPlatform : public Platform 144 class DefaultPlatform : public Platform
145 { 145 {
146 public: 146 public:
147 typedef std::shared_ptr<SharedAsyncExecutor> AsyncExecutorPtr; 147 typedef std::shared_ptr<SharedAsyncExecutor> AsyncExecutorPtr;
148 explicit DefaultPlatform(const std::shared_ptr<SharedAsyncExecutor>& asyncEx ecutor, CreationParameters&& creationParams) 148 explicit DefaultPlatform(const AsyncExecutorPtr& asyncExecutor, CreationPara meters&& creationParams)
hub 2018/02/23 22:59:35 Since there is `typedef std::shared_ptr<SharedAsyn
sergei 2018/03/01 11:18:37 Fixed, I somehow forgot about it ))
149 : Platform(std::move(creationParams)), asyncExecutor(asyncExecutor) 149 : Platform(std::move(creationParams)), asyncExecutor(asyncExecutor)
150 { 150 {
151 } 151 }
152 ~DefaultPlatform(); 152 ~DefaultPlatform();
153 153
154 void WithTimer(const WithTimerCallback&) override; 154 void WithTimer(const WithTimerCallback&) override;
155 void WithFileSystem(const WithFileSystemCallback&) override; 155 void WithFileSystem(const WithFileSystemCallback&) override;
156 void WithWebRequest(const WithWebRequestCallback&) override; 156 void WithWebRequest(const WithWebRequestCallback&) override;
157 void WithLogSystem(const WithLogSystemCallback&) override; 157 void WithLogSystem(const WithLogSystemCallback&) override;
158 158
159 private: 159 private:
160 std::shared_ptr<SharedAsyncExecutor> asyncExecutor; 160 AsyncExecutorPtr asyncExecutor;
161 std::recursive_mutex interfacesMutex; 161 std::recursive_mutex interfacesMutex;
162 }; 162 };
163 163
164 DefaultPlatform::~DefaultPlatform() 164 DefaultPlatform::~DefaultPlatform()
165 { 165 {
166 asyncExecutor->Invalidate(); 166 asyncExecutor->Invalidate();
167 LogSystemPtr tmpLogSystem; 167 LogSystemPtr tmpLogSystem;
168 TimerPtr tmpTimer; 168 TimerPtr tmpTimer;
169 FileSystemPtr tmpFileSystem; 169 FileSystemPtr tmpFileSystem;
170 WebRequestPtr tmpWebRequest; 170 WebRequestPtr tmpWebRequest;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 if (!timer) 241 if (!timer)
242 CreateDefaultTimer(); 242 CreateDefaultTimer();
243 if (!fileSystem) 243 if (!fileSystem)
244 CreateDefaultFileSystem(); 244 CreateDefaultFileSystem();
245 if (!webRequest) 245 if (!webRequest)
246 CreateDefaultWebRequest(); 246 CreateDefaultWebRequest();
247 247
248 std::unique_ptr<Platform> platform(new DefaultPlatform(sharedAsyncExecutor, st d::move(*this))); 248 std::unique_ptr<Platform> platform(new DefaultPlatform(sharedAsyncExecutor, st d::move(*this)));
249 return platform; 249 return platform;
250 } 250 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld