• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <atomic>
17 #include "libpandabase/os/time.h"
18 #include "plugins/ets/runtime/types/ets_primitives.h"
19 #include "runtime/include/runtime.h"
20 
21 namespace ark::ets::intrinsics::taskpool {
22 
23 static std::atomic<EtsLong> g_taskId = 1;
24 static std::atomic<EtsLong> g_taskGroupId = 1;
25 static std::atomic<EtsLong> g_seqRunnerId = 1;
26 static constexpr const char *LAUNCH = "launch";
27 
GenerateTaskId()28 extern "C" EtsLong GenerateTaskId()
29 {
30     return g_taskId++;
31 }
32 
GenerateGroupId()33 extern "C" EtsLong GenerateGroupId()
34 {
35     return g_taskGroupId++;
36 }
37 
GenerateSeqRunnerId()38 extern "C" EtsLong GenerateSeqRunnerId()
39 {
40     return g_seqRunnerId++;
41 }
42 
IsUsingLaunchMode()43 extern "C" EtsBoolean IsUsingLaunchMode()
44 {
45     const auto &taskpoolMode =
46         Runtime::GetOptions().GetTaskpoolMode(plugins::LangToRuntimeType(panda_file::SourceLang::ETS));
47 
48     bool res = (taskpoolMode == LAUNCH);
49     return ark::ets::ToEtsBoolean(res);
50 }
51 
IsSupportingInterop()52 extern "C" EtsBoolean IsSupportingInterop()
53 {
54     bool res = false;
55 #ifdef PANDA_ETS_INTEROP_JS
56     res = Runtime::GetOptions().IsTaskpoolSupportInterop(plugins::LangToRuntimeType(panda_file::SourceLang::ETS));
57 #endif /* PANDA_ETS_INTEROP_JS */
58     return ark::ets::ToEtsBoolean(res);
59 }
60 }  // namespace ark::ets::intrinsics::taskpool
61