Skip to content

Commit 52f61b2

Browse files
pilipala195jianliang00
authored andcommitted
[BugFix] Guard Harmony ArkTS setup by JS thread prefix
- What changed: Added a Harmony JS thread config guard so ArkTS runtime setup is attached only when the worker name starts with Lynx_JS, and added unit coverage for matching and non-matching names. - Why it was needed: Non-JS thread configs should not run Harmony ArkTS runtime initialization. - How it was verified: Ran git diff --check, the filtered lynx_base_unittests_exec RTF target, and the filtered test binary directly. AutoSubmit: true AutoLand: release/3.9, release/3.8
1 parent 5cbe8b0 commit 52f61b2

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

core/base/harmony/threading/js_thread_config_getter_harmony.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include <napi/native_api.h>
55
#include <uv.h>
66

7+
#include <memory>
8+
#include <string>
9+
710
#include "base/include/closure.h"
811
#include "base/include/fml/message_loop.h"
912
#include "base/include/fml/thread.h"
@@ -16,6 +19,15 @@
1619
namespace lynx {
1720
namespace base {
1821
namespace {
22+
23+
bool ShouldSetupArkTSRuntime(const std::string& worker_name) {
24+
// Only setup arkts runtime for js thread.
25+
constexpr char kJSThreadName[] = "Lynx_JS";
26+
constexpr size_t kPrefixLength = sizeof(kJSThreadName) - 1;
27+
28+
return worker_name.compare(0, kPrefixLength, kJSThreadName) == 0;
29+
}
30+
1931
void SetupArkTSRuntime() {
2032
TRACE_EVENT_BEGIN(LYNX_TRACE_CATEGORY, SETUP_ARK_TS_RUNTIME);
2133
LOGI("Start setup arkts runtime.")
@@ -37,6 +49,10 @@ void SetupArkTSRuntime() {
3749
} // namespace
3850

3951
fml::Thread::ThreadConfig GetJSThreadConfig(const std::string& worker_name) {
52+
if (!ShouldSetupArkTSRuntime(worker_name)) {
53+
return fml::Thread::ThreadConfig{
54+
worker_name, fml::Thread::ThreadPriority::HIGH, nullptr};
55+
}
4056
return fml::Thread::ThreadConfig{
4157
worker_name, fml::Thread::ThreadPriority::HIGH,
4258
std::make_shared<base::closure>(

core/base/threading/task_runner_manufactor_unittest.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "core/base/threading/task_runner_manufactor.h"
55

66
#include "base/include/fml/synchronization/count_down_latch.h"
7+
#include "core/base/threading/js_thread_config_getter.h"
78
#include "third_party/googletest/googletest/include/gtest/gtest.h"
89

910
namespace lynx {
@@ -17,6 +18,30 @@ class TaskRunnerManufactorTest : public ::testing::Test {
1718
void SetUp() override { UIThread::Init(); }
1819
};
1920

21+
TEST_F(TaskRunnerManufactorTest, JSThreadConfigArkTSRuntimeSetupScope) {
22+
auto single_js_thread_config = GetJSThreadConfig("Lynx_JS");
23+
auto grouped_js_thread_config = GetJSThreadConfig("Lynx_JS0");
24+
auto grouped_js_thread_config_with_large_index =
25+
GetJSThreadConfig("Lynx_JS12");
26+
auto worker_thread_config = GetJSThreadConfig("Lynx_JS_Worker-test");
27+
auto unrelated_thread_config = GetJSThreadConfig("Lynx_TASM");
28+
29+
#if defined(OS_HARMONY)
30+
EXPECT_TRUE(single_js_thread_config.additional_setup_closure);
31+
EXPECT_TRUE(grouped_js_thread_config.additional_setup_closure);
32+
EXPECT_TRUE(
33+
grouped_js_thread_config_with_large_index.additional_setup_closure);
34+
EXPECT_TRUE(worker_thread_config.additional_setup_closure);
35+
#else
36+
EXPECT_FALSE(single_js_thread_config.additional_setup_closure);
37+
EXPECT_FALSE(grouped_js_thread_config.additional_setup_closure);
38+
EXPECT_FALSE(
39+
grouped_js_thread_config_with_large_index.additional_setup_closure);
40+
EXPECT_FALSE(worker_thread_config.additional_setup_closure);
41+
#endif
42+
EXPECT_FALSE(unrelated_thread_config.additional_setup_closure);
43+
}
44+
2045
TEST_F(TaskRunnerManufactorTest, AllOnUIThreadMode) {
2146
TaskRunnerManufactor ui_mode_manufactor =
2247
TaskRunnerManufactor(ALL_ON_UI, false, false);

0 commit comments

Comments
 (0)