This repository has been archived by the owner on Aug 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
addons: integrate workers with native addons
Native addons need to use flags to indicate that they are capable of being loaded by worker threads. Native addons are unloaded if all Environments referring to it have been cleaned up, except if it also loaded by the main Environment.
- Loading branch information
Showing
9 changed files
with
258 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
const common = require('../../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const { Worker } = require('worker'); | ||
const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`); | ||
|
||
const w = new Worker(`require(${JSON.stringify(binding)});`, { eval: true }); | ||
w.on('error', common.mustCall((err) => { | ||
assert(String(err).includes( | ||
'Error: Native modules need to explicitly indicate ' + | ||
'multi-isolate/multi-thread support by using ' + | ||
'`NODE_MODULE_WORKER_ENABLED` or `NAPI_MODULE_WORKER_ENABLED` to ' + | ||
'register themselves.')); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <node.h> | ||
#include <v8.h> | ||
|
||
using v8::Context; | ||
using v8::HandleScope; | ||
using v8::Isolate; | ||
using v8::Local; | ||
using v8::Object; | ||
using v8::Value; | ||
|
||
size_t count = 0; | ||
|
||
struct statically_allocated { | ||
statically_allocated() { | ||
assert(count == 0); | ||
printf("ctor "); | ||
} | ||
~statically_allocated() { | ||
assert(count == 0); | ||
printf("dtor"); | ||
} | ||
} var; | ||
|
||
void Dummy(void*) { | ||
assert(0); | ||
} | ||
|
||
void Cleanup(void* str) { | ||
printf("%s ", static_cast<const char*>(str)); | ||
} | ||
|
||
void Init(Local<Object> exports, Local<Value> module, Local<Context> context) { | ||
node::AddEnvironmentCleanupHook( | ||
context->GetIsolate(), Cleanup, | ||
const_cast<void*>(static_cast<const void*>("cleanup"))); | ||
node::AddEnvironmentCleanupHook(context->GetIsolate(), Dummy, nullptr); | ||
node::RemoveEnvironmentCleanupHook(context->GetIsolate(), Dummy, nullptr); | ||
} | ||
|
||
NODE_MODULE_WORKER_ENABLED(binding, Init) |
Oops, something went wrong.