Skip to content

Commit

Permalink
src: drop homegrown thread pool, use libplatform
Browse files Browse the repository at this point in the history
Drop the homegrown thread pool that was introduced in commit 50839a0
("v8_platform: provide default v8::Platform impl") and use one from
V8's libplatform library.  Performance is comparable and it removes
a few hundred lines of code.

The calls to v8::platform::PumpMessageLoop() are currently no-ops
because V8 does not (yet?) use v8::Platform::CallOnForegroundThread().

Packagers that link against a shared libv8 now also need to make
libv8_platform available.

PR-URL: #1329
Reviewed-By: Fedor Indutny <[email protected]>
  • Loading branch information
bnoordhuis committed Apr 3, 2015
1 parent 87053e8 commit 4a801c2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 257 deletions.
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def configure_v8(o):
if options.shared_v8_libname:
o['libraries'] += ['-l%s' % options.shared_v8_libname]
elif options.shared_v8:
o['libraries'] += ['-lv8']
o['libraries'] += ['-lv8', '-lv8_platform']
if options.shared_v8_includes:
o['include_dirs'] += [options.shared_v8_includes]

Expand Down
8 changes: 6 additions & 2 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
'src/node_main.cc',
'src/node_os.cc',
'src/node_v8.cc',
'src/node_v8_platform.cc',
'src/node_stat_watcher.cc',
'src/node_watchdog.cc',
'src/node_zlib.cc',
Expand Down Expand Up @@ -312,7 +311,12 @@
'deps/v8/include/v8.h',
'deps/v8/include/v8-debug.h',
],
'dependencies': [ 'deps/v8/tools/gyp/v8.gyp:v8' ],
'dependencies': [
'deps/v8/tools/gyp/v8.gyp:v8',
'deps/v8/tools/gyp/v8.gyp:v8_libplatform',
],
# libplatform/libplatform.h includes include/v8platform.h
'include_dirs': [ 'deps/v8' ],
}],

[ 'node_shared_zlib=="false"', {
Expand Down
13 changes: 11 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "node_http_parser.h"
#include "node_javascript.h"
#include "node_version.h"
#include "node_v8_platform.h"

#if defined HAVE_PERFCTR
#include "node_counters.h"
Expand Down Expand Up @@ -38,6 +37,7 @@
#include "string_bytes.h"
#include "util.h"
#include "uv.h"
#include "libplatform/libplatform.h"
#include "v8-debug.h"
#include "v8-profiler.h"
#include "zlib.h"
Expand Down Expand Up @@ -140,6 +140,7 @@ static bool debugger_running;
static uv_async_t dispatch_debug_messages_async;

static Isolate* node_isolate = nullptr;
static v8::Platform* default_platform;

class ArrayBufferAllocator : public ArrayBuffer::Allocator {
public:
Expand Down Expand Up @@ -3824,8 +3825,11 @@ static void StartNodeInstance(void* arg) {

bool more;
do {
v8::platform::PumpMessageLoop(default_platform, isolate);
more = uv_run(env->event_loop(), UV_RUN_ONCE);

if (more == false) {
v8::platform::PumpMessageLoop(default_platform, isolate);
EmitBeforeExit(env);

// Emit `beforeExit` if the loop became alive either after emitting
Expand Down Expand Up @@ -3872,7 +3876,9 @@ int Start(int argc, char** argv) {
V8::SetEntropySource(crypto::EntropySource);
#endif

V8::InitializePlatform(new Platform(4));
const int thread_pool_size = 4;
default_platform = v8::platform::CreateDefaultPlatform(thread_pool_size);
V8::InitializePlatform(default_platform);
V8::Initialize();

int exit_code = 1;
Expand All @@ -3889,6 +3895,9 @@ int Start(int argc, char** argv) {
}
V8::Dispose();

delete default_platform;
default_platform = nullptr;

delete[] exec_argv;
exec_argv = nullptr;

Expand Down
178 changes: 0 additions & 178 deletions src/node_v8_platform.cc

This file was deleted.

74 changes: 0 additions & 74 deletions src/node_v8_platform.h

This file was deleted.

0 comments on commit 4a801c2

Please sign in to comment.