Index: include/AdblockPlus/JsEngine.h |
=================================================================== |
--- a/include/AdblockPlus/JsEngine.h |
+++ b/include/AdblockPlus/JsEngine.h |
@@ -20,6 +20,7 @@ |
#include <functional> |
#include <map> |
+#include <memory> |
#include <stdexcept> |
#include <stdint.h> |
#include <string> |
@@ -73,6 +74,9 @@ |
*/ |
typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr; |
+ struct ImmediateSingleUseThreadType {}; ///< Marker class for scheduling policy |
+ 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
|
+ |
/** |
* JavaScript engine used by `FilterEngine`, wraps v8. |
*/ |
@@ -133,6 +137,25 @@ |
const std::string& filename = ""); |
/** |
+ * Schedule a task with these policies: |
+ * - 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
|
+ * - threading policy: run the task in a single-use thread. |
+ * |
+ * @param task |
+ * Task to execute. All v8 handles should refer to the present engine. |
+ * @param ImmediateSingleUseThreadType |
+ * 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
|
+ */ |
+ 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.
|
+ |
+ /** |
+ * Block until there are no more tasks running in the scheduler. |
+ * |
+ * Note: this function does not prevent new tasks from being scheduled. |
+ */ |
+ void WaitForQuietScheduler(); |
+ |
+ /** |
* Initiates a garbage collection. |
*/ |
void Gc(); |
@@ -253,7 +276,7 @@ |
private: |
explicit JsEngine(const ScopedV8IsolatePtr& isolate); |
- JsValuePtr GetGlobalObject(); |
+ JsValuePtr GetGlobalObject(); |
/// Isolate must be disposed only after disposing of all objects which are |
/// using it. |
@@ -264,6 +287,16 @@ |
LogSystemPtr logSystem; |
std::unique_ptr<v8::Persistent<v8::Context>> context; |
EventMap eventCallbacks; |
+ |
+ // 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
|
+ class SchedulerImpl; |
+ /** |
+ * Scheduler for tasks executed under the current engine. |
+ * |
+ * \par Invariant |
+ * `bool(scheduler)` is always true |
+ */ |
+ std::unique_ptr<SchedulerImpl> scheduler; |
}; |
} |