1
0
Fork 0

Startup V8 threads concurrently in multiple C++11 threads.

Conflicts:
	arangod/V8Server/ApplicationV8.cpp
This commit is contained in:
Max Neunhoeffer 2015-04-08 09:56:22 +02:00
parent 541b4c2f07
commit 1709a25163
2 changed files with 31 additions and 8 deletions

View File

@ -28,6 +28,10 @@
////////////////////////////////////////////////////////////////////////////////
#include "ApplicationV8.h"
#include <libplatform/libplatform.h>
#include <thread>
#include "Actions/actions.h"
#include "Aql/QueryRegistry.h"
#include "ApplicationServer/ApplicationServer.h"
@ -1056,15 +1060,16 @@ bool ApplicationV8::prepare2 () {
_contexts[DEFAULT_NAME] = new V8Context*[nrInstances];
}
for (size_t i = 0; i < nrInstances; ++i) {
bool ok = prepareV8Instance(DEFAULT_NAME, i, _useActions);
if (! ok) {
return false;
}
std::vector<std::thread> threads;
_ok = true;
for (size_t i = 0; i < nrInstances; ++i) {
threads.push_back(std::thread(&ApplicationV8::prepareV8InstanceInThread,
this, DEFAULT_NAME, i, _useActions));
}
return true;
for (size_t i = 0; i < nrInstances; ++i) {
threads[i].join();
}
return _ok;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -433,6 +433,17 @@ namespace triagens {
bool prepareV8Instance (const std::string& name, size_t i, bool useActions);
////////////////////////////////////////////////////////////////////////////////
/// @brief prepares a V8 instance, multi-threaded version calling the above
////////////////////////////////////////////////////////////////////////////////
void prepareV8InstanceInThread (const std::string& name, size_t i,
bool useAction) {
if (! prepareV8Instance(name, i, useAction)) {
_ok = false;
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief prepares the V8 server
////////////////////////////////////////////////////////////////////////////////
@ -662,7 +673,14 @@ namespace triagens {
////////////////////////////////////////////////////////////////////////////////
/// @brief the V8 platform object
////////////////////////////////////////////////////////////////////////////////
v8::Platform* _platform;
////////////////////////////////////////////////////////////////////////////////
/// @brief atomic flag to report success of multi-threaded startup
////////////////////////////////////////////////////////////////////////////////
std::atomic<bool> _ok;
};
}
}