Move creation of web worker threads into react/jni

Summary:
Injects implementation into react/

public

Reviewed By: astreet

Differential Revision: D2905183

fb-gh-sync-id: 3ea6aaf50aabc1faae4e7a93fe92e02b033407e8
This commit is contained in:
Chris Hopman 2016-02-05 18:09:27 -08:00 committed by facebook-github-bot-2
parent f4b826d6a0
commit 52fcfc31cd
4 changed files with 7 additions and 1 deletions

View File

@ -35,7 +35,7 @@ JSCWebWorker::JSCWebWorker(int id, JSCWebWorkerOwner *owner, std::string scriptS
owner_(owner) {
ownerMessageQueueThread_ = owner->getMessageQueueThread();
CHECK(ownerMessageQueueThread_) << "Owner MessageQueue must not be null";
workerMessageQueueThread_ = WebWorkers::createWebWorkerThread(id, ownerMessageQueueThread_.get());
workerMessageQueueThread_ = WebWorkerUtil::createWebWorkerThread(id, ownerMessageQueueThread_.get());
CHECK(workerMessageQueueThread_) << "Failed to create worker thread";
workerMessageQueueThread_->runOnQueue([this] () {

View File

@ -14,6 +14,7 @@ GetCurrentMessageQueueThread getCurrentMessageQueueThread;
};
namespace WebWorkerUtil {
WebWorkerQueueFactory createWebWorkerThread;
LoadScriptFromAssets loadScriptFromAssets;
};

View File

@ -24,6 +24,9 @@ extern GetCurrentMessageQueueThread getCurrentMessageQueueThread;
};
namespace WebWorkerUtil {
using WebWorkerQueueFactory = std::function<std::unique_ptr<MessageQueueThread>(int id, MessageQueueThread* ownerMessageQueue)>;
extern WebWorkerQueueFactory createWebWorkerThread;
using LoadScriptFromAssets = std::function<std::string(const std::string& assetName)>;
extern LoadScriptFromAssets loadScriptFromAssets;
};

View File

@ -24,6 +24,7 @@
#include "JMessageQueueThread.h"
#include "JSLogging.h"
#include "JSCPerfLogging.h"
#include "WebWorkers.h"
#include <algorithm>
#ifdef WITH_FBSYSTRACE
@ -839,6 +840,7 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
return initialize(vm, [] {
// Inject some behavior into react/
ReactMarker::logMarker = bridge::logMarker;
WebWorkerUtil::createWebWorkerThread = WebWorkers::createWebWorkerThread;
WebWorkerUtil::loadScriptFromAssets =
[] (const std::string& assetName) {
return loadScriptFromAssets(assetName);