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

Side by Side Diff: include/AdblockPlus/JsEngine.h

Issue 29367507: Issue #3595 - Add an actual scheduler; use joined threads for file system
Patch Set: Created Dec. 14, 2016, 5:38 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | libadblockplus.gyp » ('j') | src/JsEngine.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #ifndef ADBLOCK_PLUS_JS_ENGINE_H 18 #ifndef ADBLOCK_PLUS_JS_ENGINE_H
19 #define ADBLOCK_PLUS_JS_ENGINE_H 19 #define ADBLOCK_PLUS_JS_ENGINE_H
20 20
21 #include <functional> 21 #include <functional>
22 #include <map> 22 #include <map>
23 #include <memory>
23 #include <stdexcept> 24 #include <stdexcept>
24 #include <stdint.h> 25 #include <stdint.h>
25 #include <string> 26 #include <string>
26 #include <AdblockPlus/AppInfo.h> 27 #include <AdblockPlus/AppInfo.h>
27 #include <AdblockPlus/LogSystem.h> 28 #include <AdblockPlus/LogSystem.h>
28 #include <AdblockPlus/FileSystem.h> 29 #include <AdblockPlus/FileSystem.h>
29 #include <AdblockPlus/JsValue.h> 30 #include <AdblockPlus/JsValue.h>
30 #include <AdblockPlus/WebRequest.h> 31 #include <AdblockPlus/WebRequest.h>
31 32
32 namespace v8 33 namespace v8
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 ScopedV8Isolate& operator=(const ScopedV8Isolate&); 67 ScopedV8Isolate& operator=(const ScopedV8Isolate&);
67 68
68 v8::Isolate* isolate; 69 v8::Isolate* isolate;
69 }; 70 };
70 71
71 /** 72 /**
72 * Shared smart pointer to ScopedV8Isolate instance; 73 * Shared smart pointer to ScopedV8Isolate instance;
73 */ 74 */
74 typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr; 75 typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr;
75 76
77 struct ImmediateSingleUseThreadType {}; ///< Marker class for scheduling polic y
78 extern const ImmediateSingleUseThreadType ImmediateSingleUseThread; ///< Dummy constant for scheduling policy
sergei 2017/01/20 13:08:13 Since it's not used I would propose to remove any
79
76 /** 80 /**
77 * JavaScript engine used by `FilterEngine`, wraps v8. 81 * JavaScript engine used by `FilterEngine`, wraps v8.
78 */ 82 */
79 class JsEngine : public std::enable_shared_from_this<JsEngine> 83 class JsEngine : public std::enable_shared_from_this<JsEngine>
80 { 84 {
81 friend class JsValue; 85 friend class JsValue;
82 friend class JsContext; 86 friend class JsContext;
83 87
84 public: 88 public:
85 /** 89 /**
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 * Evaluates a JavaScript expression. 130 * Evaluates a JavaScript expression.
127 * @param source JavaScript expression to evaluate. 131 * @param source JavaScript expression to evaluate.
128 * @param filename Optional file name for the expression, used in error 132 * @param filename Optional file name for the expression, used in error
129 * messages. 133 * messages.
130 * @return Result of the evaluated expression. 134 * @return Result of the evaluated expression.
131 */ 135 */
132 JsValuePtr Evaluate(const std::string& source, 136 JsValuePtr Evaluate(const std::string& source,
133 const std::string& filename = ""); 137 const std::string& filename = "");
134 138
135 /** 139 /**
140 * Schedule a task with these policies:
141 * - timing policy: start execution immediately.
sergei 2017/01/20 13:08:12 I would remove the comment about timing policy bec
Eric 2017/03/30 17:16:58 "Immediately" simply means "at the present time, w
142 * - threading policy: run the task in a single-use thread.
143 *
144 * @param task
145 * Task to execute. All v8 handles should refer to the present engine.
146 * @param ImmediateSingleUseThreadType
147 * The schedule policy--create a new thread and discard it afterwards.
sergei 2017/01/20 13:08:12 I would remove that parameter because there is no
Eric 2017/03/30 17:16:58 This parameter is a marker, acting both as documen
148 */
149 void Schedule(std::function<void()> task, ImmediateSingleUseThreadType);
sergei 2017/01/20 13:08:13 Although it's expected that task can be copied int
Eric 2017/03/30 17:16:58 In the present code, it's passed by value intentio
sergei 2017/04/03 15:35:31 Acknowledged.
150
151 /**
152 * Block until there are no more tasks running in the scheduler.
153 *
154 * Note: this function does not prevent new tasks from being scheduled.
155 */
156 void WaitForQuietScheduler();
157
158 /**
136 * Initiates a garbage collection. 159 * Initiates a garbage collection.
137 */ 160 */
138 void Gc(); 161 void Gc();
139 162
140 //@{ 163 //@{
141 /** 164 /**
142 * Creates a new JavaScript value. 165 * Creates a new JavaScript value.
143 * @param val Value to convert. 166 * @param val Value to convert.
144 * @return New `JsValue` instance. 167 * @return New `JsValue` instance.
145 */ 168 */
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 280
258 /// Isolate must be disposed only after disposing of all objects which are 281 /// Isolate must be disposed only after disposing of all objects which are
259 /// using it. 282 /// using it.
260 ScopedV8IsolatePtr isolate; 283 ScopedV8IsolatePtr isolate;
261 284
262 FileSystemPtr fileSystem; 285 FileSystemPtr fileSystem;
263 WebRequestPtr webRequest; 286 WebRequestPtr webRequest;
264 LogSystemPtr logSystem; 287 LogSystemPtr logSystem;
265 std::unique_ptr<v8::Persistent<v8::Context>> context; 288 std::unique_ptr<v8::Persistent<v8::Context>> context;
266 EventMap eventCallbacks; 289 EventMap eventCallbacks;
290
291 // Forward declaration for PImpl idiom
sergei 2017/01/20 13:08:13 We don't need this comment.
Eric 2017/03/30 17:16:58 Yes, we do. Dangling declarations with zero docume
292 class SchedulerImpl;
293 /**
294 * Scheduler for tasks executed under the current engine.
295 *
296 * \par Invariant
297 * `bool(scheduler)` is always true
298 */
299 std::unique_ptr<SchedulerImpl> scheduler;
267 }; 300 };
268 } 301 }
269 302
270 #endif 303 #endif
OLDNEW
« no previous file with comments | « no previous file | libadblockplus.gyp » ('j') | src/JsEngine.cpp » ('J')

Powered by Google App Engine
This is Rietveld