Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 Platform::Platform(CreationParameters&& creationParameters) | 45 Platform::Platform(CreationParameters&& creationParameters) |
46 { | 46 { |
47 ASSIGN_PLATFORM_PARAM(logSystem); | 47 ASSIGN_PLATFORM_PARAM(logSystem); |
48 ASSIGN_PLATFORM_PARAM(timer); | 48 ASSIGN_PLATFORM_PARAM(timer); |
49 ASSIGN_PLATFORM_PARAM(fileSystem); | 49 ASSIGN_PLATFORM_PARAM(fileSystem); |
50 ASSIGN_PLATFORM_PARAM(webRequest); | 50 ASSIGN_PLATFORM_PARAM(webRequest); |
51 } | 51 } |
52 | 52 |
53 Platform::~Platform() | 53 Platform::~Platform() |
54 { | 54 { |
55 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); | |
56 logSystem.reset(); | |
57 timer.reset(); | |
sergei
2017/09/13 19:20:53
I'm afraid here is a dead lock:
Let's say `interfa
hub
2017/09/13 19:50:49
Good catch.
| |
58 fileSystem.reset(); | |
59 webRequest.reset(); | |
60 } | 55 } |
61 | 56 |
62 void Platform::SetUpJsEngine(const AppInfo& appInfo, std::unique_ptr<IV8IsolateP rovider> isolate) | 57 void Platform::SetUpJsEngine(const AppInfo& appInfo, std::unique_ptr<IV8IsolateP rovider> isolate) |
63 { | 58 { |
64 std::lock_guard<std::mutex> lock(modulesMutex); | 59 std::lock_guard<std::mutex> lock(modulesMutex); |
65 if (jsEngine) | 60 if (jsEngine) |
66 return; | 61 return; |
67 jsEngine = JsEngine::New(appInfo, *this, std::move(isolate)); | 62 jsEngine = JsEngine::New(appInfo, *this, std::move(isolate)); |
68 } | 63 } |
69 | 64 |
(...skipping 25 matching lines...) Expand all Loading... | |
95 } | 90 } |
96 | 91 |
97 FilterEngine& Platform::GetFilterEngine() | 92 FilterEngine& Platform::GetFilterEngine() |
98 { | 93 { |
99 CreateFilterEngineAsync(); | 94 CreateFilterEngineAsync(); |
100 return *std::shared_future<FilterEnginePtr>(filterEngine).get(); | 95 return *std::shared_future<FilterEnginePtr>(filterEngine).get(); |
101 } | 96 } |
102 | 97 |
103 void Platform::WithTimer(const WithTimerCallback& callback) | 98 void Platform::WithTimer(const WithTimerCallback& callback) |
104 { | 99 { |
105 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); | |
106 if (timer && callback) | 100 if (timer && callback) |
107 callback(*timer); | 101 callback(*timer); |
108 } | 102 } |
109 | 103 |
110 void Platform::WithFileSystem(const WithFileSystemCallback& callback) | 104 void Platform::WithFileSystem(const WithFileSystemCallback& callback) |
111 { | 105 { |
112 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); | |
113 if (fileSystem && callback) | 106 if (fileSystem && callback) |
114 callback(*fileSystem); | 107 callback(*fileSystem); |
115 } | 108 } |
116 | 109 |
117 void Platform::WithWebRequest(const WithWebRequestCallback& callback) | 110 void Platform::WithWebRequest(const WithWebRequestCallback& callback) |
118 { | 111 { |
119 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); | |
120 if (webRequest && callback) | 112 if (webRequest && callback) |
121 callback(*webRequest); | 113 callback(*webRequest); |
122 } | 114 } |
123 | 115 |
124 void Platform::WithLogSystem(const WithLogSystemCallback& callback) | 116 void Platform::WithLogSystem(const WithLogSystemCallback& callback) |
125 { | 117 { |
126 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); | |
127 if (logSystem && callback) | 118 if (logSystem && callback) |
128 callback(*logSystem); | 119 callback(*logSystem); |
129 } | 120 } |
130 | 121 |
131 namespace | 122 namespace |
132 { | 123 { |
133 class DefaultPlatform : public Platform | 124 class DefaultPlatform : public Platform |
134 { | 125 { |
135 public: | 126 public: |
136 typedef std::shared_ptr<Scheduler> AsyncExecutorPtr; | 127 typedef std::shared_ptr<Scheduler> AsyncExecutorPtr; |
137 explicit DefaultPlatform(const AsyncExecutorPtr& asyncExecutor, CreationPara meters&& creationParams) | 128 explicit DefaultPlatform(const AsyncExecutorPtr& asyncExecutor, CreationPara meters&& creationParams) |
138 : Platform(std::move(creationParams)), asyncExecutor(asyncExecutor) | 129 : Platform(std::move(creationParams)), asyncExecutor(asyncExecutor) |
139 { | 130 { |
140 } | 131 } |
141 ~DefaultPlatform() | 132 ~DefaultPlatform(); |
142 { | 133 |
143 asyncExecutor.reset(); | 134 void WithTimer(const WithTimerCallback&) override; |
144 } | 135 void WithFileSystem(const WithFileSystemCallback&) override; |
136 void WithWebRequest(const WithWebRequestCallback&) override; | |
137 void WithLogSystem(const WithLogSystemCallback&) override; | |
138 | |
145 private: | 139 private: |
146 AsyncExecutorPtr asyncExecutor; | 140 AsyncExecutorPtr asyncExecutor; |
141 std::recursive_mutex interfacesMutex; | |
147 }; | 142 }; |
143 | |
144 DefaultPlatform::~DefaultPlatform() | |
145 { | |
146 asyncExecutor.reset(); | |
147 LogSystemPtr tmpLogSystem; | |
148 TimerPtr tmpTimer; | |
149 FileSystemPtr tmpFileSystem; | |
150 WebRequestPtr tmpWebRequest; | |
151 { | |
152 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); | |
153 tmpLogSystem = std::move(logSystem); | |
154 tmpTimer = std::move(timer); | |
155 tmpFileSystem = std::move(fileSystem); | |
156 tmpWebRequest = std::move(webRequest); | |
157 } | |
158 } | |
159 | |
160 void DefaultPlatform::WithTimer(const WithTimerCallback& callback) | |
161 { | |
162 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); | |
163 Platform::WithTimer(callback); | |
164 } | |
165 | |
166 void DefaultPlatform::WithFileSystem(const WithFileSystemCallback& callback) | |
167 { | |
168 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); | |
169 Platform::WithFileSystem(callback); | |
170 } | |
171 | |
172 void DefaultPlatform::WithWebRequest(const WithWebRequestCallback& callback) | |
173 { | |
174 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); | |
175 Platform::WithWebRequest(callback); | |
176 } | |
177 | |
178 void DefaultPlatform::WithLogSystem(const WithLogSystemCallback& callback) | |
179 { | |
180 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); | |
181 Platform::WithLogSystem(callback); | |
182 } | |
148 } | 183 } |
149 | 184 |
150 Scheduler DefaultPlatformBuilder::GetDefaultAsyncExecutor() | 185 Scheduler DefaultPlatformBuilder::GetDefaultAsyncExecutor() |
151 { | 186 { |
152 if (!defaultScheduler) | 187 if (!defaultScheduler) |
153 { | 188 { |
154 asyncExecutor = std::make_shared<Scheduler>(::DummyScheduler); | 189 asyncExecutor = std::make_shared<Scheduler>(::DummyScheduler); |
155 std::weak_ptr<Scheduler> weakExecutor = asyncExecutor; | 190 std::weak_ptr<Scheduler> weakExecutor = asyncExecutor; |
156 defaultScheduler = [weakExecutor](const SchedulerTask& task) | 191 defaultScheduler = [weakExecutor](const SchedulerTask& task) |
157 { | 192 { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 CreateDefaultTimer(); | 229 CreateDefaultTimer(); |
195 if (!fileSystem) | 230 if (!fileSystem) |
196 CreateDefaultFileSystem(); | 231 CreateDefaultFileSystem(); |
197 if (!webRequest) | 232 if (!webRequest) |
198 CreateDefaultWebRequest(); | 233 CreateDefaultWebRequest(); |
199 | 234 |
200 std::unique_ptr<Platform> platform(new DefaultPlatform(asyncExecutor, std::mov e(*this))); | 235 std::unique_ptr<Platform> platform(new DefaultPlatform(asyncExecutor, std::mov e(*this))); |
201 asyncExecutor.reset(); | 236 asyncExecutor.reset(); |
202 return platform; | 237 return platform; |
203 } | 238 } |
LEFT | RIGHT |