Left: | ||
Right: |
OLD | NEW |
---|---|
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(); | |
55 } | 60 } |
56 | 61 |
57 void Platform::SetUpJsEngine(const AppInfo& appInfo, std::unique_ptr<IV8IsolateP rovider> isolate) | 62 void Platform::SetUpJsEngine(const AppInfo& appInfo, std::unique_ptr<IV8IsolateP rovider> isolate) |
58 { | 63 { |
59 std::lock_guard<std::mutex> lock(modulesMutex); | 64 std::lock_guard<std::mutex> lock(modulesMutex); |
60 if (jsEngine) | 65 if (jsEngine) |
61 return; | 66 return; |
62 jsEngine = JsEngine::New(appInfo, *this, std::move(isolate)); | 67 jsEngine = JsEngine::New(appInfo, *this, std::move(isolate)); |
63 } | 68 } |
64 | 69 |
(...skipping 23 matching lines...) Expand all Loading... | |
88 onCreated(*filterEngine); | 93 onCreated(*filterEngine); |
89 }, parameters); | 94 }, parameters); |
90 } | 95 } |
91 | 96 |
92 FilterEngine& Platform::GetFilterEngine() | 97 FilterEngine& Platform::GetFilterEngine() |
93 { | 98 { |
94 CreateFilterEngineAsync(); | 99 CreateFilterEngineAsync(); |
95 return *std::shared_future<FilterEnginePtr>(filterEngine).get(); | 100 return *std::shared_future<FilterEnginePtr>(filterEngine).get(); |
96 } | 101 } |
97 | 102 |
98 ITimer& Platform::GetTimer() | 103 void Platform::WithTimer(const WithTimerCallback& callback) |
99 { | 104 { |
100 return *timer; | 105 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
106 if (timer && callback) | |
107 callback(*timer); | |
101 } | 108 } |
102 | 109 |
103 IFileSystem& Platform::GetFileSystem() | 110 void Platform::WithFileSystem(const WithFileSystemCallback& callback) |
104 { | 111 { |
105 return *fileSystem; | 112 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
113 if (fileSystem && callback) | |
114 callback(*fileSystem); | |
106 } | 115 } |
107 | 116 |
108 IWebRequest& Platform::GetWebRequest() | 117 void Platform::WithWebRequest(const WithWebRequestCallback& callback) |
109 { | 118 { |
110 return *webRequest; | 119 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
120 if (webRequest && callback) | |
121 callback(*webRequest); | |
111 } | 122 } |
112 | 123 |
113 LogSystem& Platform::GetLogSystem() | 124 void Platform::WithLogSystem(const WithLogSystemCallback& callback) |
114 { | 125 { |
115 return *logSystem; | 126 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); |
127 if (logSystem && callback) | |
128 callback(*logSystem); | |
116 } | 129 } |
117 | 130 |
118 namespace | 131 namespace |
119 { | 132 { |
120 class DefaultPlatform : public Platform | 133 class DefaultPlatform : public Platform |
121 { | 134 { |
122 public: | 135 public: |
123 typedef std::shared_ptr<Scheduler> AsyncExecutorPtr; | 136 typedef std::shared_ptr<Scheduler> AsyncExecutorPtr; |
124 explicit DefaultPlatform(const AsyncExecutorPtr& asyncExecutor, CreationPara meters&& creationParams) | 137 explicit DefaultPlatform(const AsyncExecutorPtr& asyncExecutor, CreationPara meters&& creationParams) |
125 : Platform(std::move(creationParams)), asyncExecutor(asyncExecutor) | 138 : Platform(std::move(creationParams)), asyncExecutor(asyncExecutor) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 if (!timer) | 193 if (!timer) |
181 CreateDefaultTimer(); | 194 CreateDefaultTimer(); |
182 if (!fileSystem) | 195 if (!fileSystem) |
183 CreateDefaultFileSystem(); | 196 CreateDefaultFileSystem(); |
184 if (!webRequest) | 197 if (!webRequest) |
185 CreateDefaultWebRequest(); | 198 CreateDefaultWebRequest(); |
186 | 199 |
187 std::unique_ptr<Platform> platform(new DefaultPlatform(asyncExecutor, std::mov e(*this))); | 200 std::unique_ptr<Platform> platform(new DefaultPlatform(asyncExecutor, std::mov e(*this))); |
188 asyncExecutor.reset(); | 201 asyncExecutor.reset(); |
189 return platform; | 202 return platform; |
190 } | 203 } |
OLD | NEW |