Skip to content

Commit

Permalink
[unity]JsEnv.Build.cs增加SingleThreaded选项,用于指定v8别开线程池
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed May 28, 2024
1 parent e8b8ce0 commit 4e8d5c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions unreal/Puerts/Source/JsEnv/JsEnv.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class JsEnv : ModuleRules
private bool ThreadSafe = false;

private bool FTextAsString = true;

// v8 9.4+
private bool SingleThreaded = false;

public static bool WithSourceControl = false;

Expand Down Expand Up @@ -356,6 +359,10 @@ void MacDylib(string LibraryPath)

void ThirdParty(ReadOnlyTargetRules Target)
{
if (SingleThreaded)
{
PrivateDefinitions.Add("USING_SINGLE_THREAD_PLATFORM");
}
//Add header
string HeaderPath = Path.GetFullPath(Path.Combine(ModuleDirectory, "..", "..", "ThirdParty", "Include"));
PublicIncludePaths.AddRange(new string[] { Path.Combine(HeaderPath, "websocketpp") });
Expand Down
4 changes: 4 additions & 0 deletions unreal/Puerts/Source/JsEnv/Private/JsEnvModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,12 @@ void FJsEnvModule::StartupModule()
// This code will execute after your module is loaded into memory (but after global variables are initialized, of course.)
#if defined(WITH_NODEJS)
platform_ = node::MultiIsolatePlatform::Create(4);
#else
#if defined(USING_SINGLE_THREAD_PLATFORM)
platform_ = v8::platform::NewSingleThreadedDefaultPlatform();
#else
platform_ = v8::platform::NewDefaultPlatform();
#endif
#endif
v8::V8::InitializePlatform(platform_.get());
v8::V8::Initialize();
Expand Down

0 comments on commit 4e8d5c9

Please sign in to comment.