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

Delta Between Two Patch Sets: src/Platform.cpp

Issue 29543810: Issue 5118 - Lock the platform interfaces before use (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Left Patch Set: Review feedback Created Sept. 13, 2017, 7:49 p.m.
Right Patch Set: Last details Created Sept. 13, 2017, 8:17 p.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/JsEngine.cpp ('k') | src/WebRequestJsObject.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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 class DefaultPlatform : public Platform 124 class DefaultPlatform : public Platform
125 { 125 {
126 public: 126 public:
127 typedef std::shared_ptr<Scheduler> AsyncExecutorPtr; 127 typedef std::shared_ptr<Scheduler> AsyncExecutorPtr;
128 explicit DefaultPlatform(const AsyncExecutorPtr& asyncExecutor, CreationPara meters&& creationParams) 128 explicit DefaultPlatform(const AsyncExecutorPtr& asyncExecutor, CreationPara meters&& creationParams)
129 : Platform(std::move(creationParams)), asyncExecutor(asyncExecutor) 129 : Platform(std::move(creationParams)), asyncExecutor(asyncExecutor)
130 { 130 {
131 } 131 }
132 ~DefaultPlatform(); 132 ~DefaultPlatform();
133 133
134 virtual void WithTimer(const WithTimerCallback&) override; 134 void WithTimer(const WithTimerCallback&) override;
sergei 2017/09/13 20:06:37 Could you please remove the `virtual` keyword here
hub 2017/09/13 20:17:51 Done.
135 virtual void WithFileSystem(const WithFileSystemCallback&) override; 135 void WithFileSystem(const WithFileSystemCallback&) override;
136 virtual void WithWebRequest(const WithWebRequestCallback&) override; 136 void WithWebRequest(const WithWebRequestCallback&) override;
137 virtual void WithLogSystem(const WithLogSystemCallback&) override; 137 void WithLogSystem(const WithLogSystemCallback&) override;
138 138
139 private: 139 private:
140 AsyncExecutorPtr asyncExecutor; 140 AsyncExecutorPtr asyncExecutor;
141 std::recursive_mutex interfacesMutex; 141 std::recursive_mutex interfacesMutex;
142 }; 142 };
143 143
144 DefaultPlatform::~DefaultPlatform() 144 DefaultPlatform::~DefaultPlatform()
145 { 145 {
146 asyncExecutor.reset(); 146 asyncExecutor.reset();
147 LogSystemPtr tmpLogSystem; 147 LogSystemPtr tmpLogSystem;
148 TimerPtr tmpTimer; 148 TimerPtr tmpTimer;
149 FileSystemPtr tmpFileSystem; 149 FileSystemPtr tmpFileSystem;
150 WebRequestPtr tmpWebRequest; 150 WebRequestPtr tmpWebRequest;
151 { 151 {
152 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); 152 std::lock_guard<std::recursive_mutex> lock(interfacesMutex);
153 tmpLogSystem = std::move(logSystem); 153 tmpLogSystem = std::move(logSystem);
154 tmpTimer = std::move(timer); 154 tmpTimer = std::move(timer);
155 tmpFileSystem = std::move(fileSystem); 155 tmpFileSystem = std::move(fileSystem);
156 tmpWebRequest = std::move(webRequest); 156 tmpWebRequest = std::move(webRequest);
157 } 157 }
158 tmpLogSystem.reset();
159 tmpTimer.reset();
160 tmpFileSystem.reset();
161 tmpWebRequest.reset();
sergei 2017/09/13 20:06:37 I think this calls of reset are not required.
hub 2017/09/13 20:17:51 Done.
162 } 158 }
163 159
164 void DefaultPlatform::WithTimer(const WithTimerCallback& callback) 160 void DefaultPlatform::WithTimer(const WithTimerCallback& callback)
165 { 161 {
166 std::lock_guard<std::recursive_mutex> lock(interfacesMutex); 162 std::lock_guard<std::recursive_mutex> lock(interfacesMutex);
167 Platform::WithTimer(callback); 163 Platform::WithTimer(callback);
168 } 164 }
169 165
170 void DefaultPlatform::WithFileSystem(const WithFileSystemCallback& callback) 166 void DefaultPlatform::WithFileSystem(const WithFileSystemCallback& callback)
171 { 167 {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 CreateDefaultTimer(); 229 CreateDefaultTimer();
234 if (!fileSystem) 230 if (!fileSystem)
235 CreateDefaultFileSystem(); 231 CreateDefaultFileSystem();
236 if (!webRequest) 232 if (!webRequest)
237 CreateDefaultWebRequest(); 233 CreateDefaultWebRequest();
238 234
239 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)));
240 asyncExecutor.reset(); 236 asyncExecutor.reset();
241 return platform; 237 return platform;
242 } 238 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld