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

Unified Diff: src/GlobalJsObject.cpp

Issue 29367003: Issue #4711 - Rewrite legacy thread facilities
Patch Set: Created Dec. 7, 2016, 4:44 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/FilterEngine.cpp ('k') | src/Scheduler.h » ('j') | src/Scheduler.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/GlobalJsObject.cpp
===================================================================
--- a/src/GlobalJsObject.cpp
+++ b/src/GlobalJsObject.cpp
@@ -15,8 +15,9 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <stdexcept>
+#include <thread>
#include <vector>
-#include <stdexcept>
#include <AdblockPlus/JsValue.h>
@@ -24,20 +25,18 @@
#include "ConsoleJsObject.h"
#include "FileSystemJsObject.h"
#include "GlobalJsObject.h"
-#include "ConsoleJsObject.h"
Eric 2016/12/07 18:06:25 Duplicated.
+#include "Scheduler.h"
+#include "Utils.h"
#include "WebRequestJsObject.h"
-#include "Thread.h"
-#include "Utils.h"
using namespace AdblockPlus;
namespace
{
- class TimeoutThread : public Thread
+ class TimeoutTask
{
public:
- TimeoutThread(JsValueList& arguments)
- : Thread(true)
+ TimeoutTask(JsValueList& arguments)
{
if (arguments.size() < 2)
throw std::runtime_error("setTimeout requires at least 2 parameters");
@@ -52,10 +51,9 @@
functionArguments.push_back(arguments[i]);
}
- void Run()
- {
- Sleep(delay);
-
+ void operator()()
+ {
+ std::this_thread::sleep_for(std::chrono::milliseconds(delay));
function->Call(functionArguments);
}
@@ -67,20 +65,20 @@
v8::Handle<v8::Value> SetTimeoutCallback(const v8::Arguments& arguments)
{
- TimeoutThread* timeoutThread;
+ std::shared_ptr<TimeoutTask> timeoutTask;
try
{
AdblockPlus::JsValueList converted =
AdblockPlus::JsEngine::FromArguments(arguments)
->ConvertArguments(arguments);
- timeoutThread = new TimeoutThread(converted);
+ timeoutTask = std::make_shared<TimeoutTask>(converted);
}
catch (const std::exception& e)
{
v8::Isolate* isolate = arguments.GetIsolate();
return v8::ThrowException(Utils::ToV8String(isolate, e.what()));
}
- timeoutThread->Start();
+ Scheduler::StartImmediatelyInSingleUseThread(MakeHeapFunction(timeoutTask));
// We should actually return the timer ID here, which could be
// used via clearTimeout(). But since we don't seem to need
« no previous file with comments | « src/FilterEngine.cpp ('k') | src/Scheduler.h » ('j') | src/Scheduler.h » ('J')

Powered by Google App Engine
This is Rietveld