mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-06 23:54:03 +00:00
Change file folder "platform" to "tastpool"
Signed-off-by: DaiH <daihuina1@huawei.com> 1. Change file folder "platform" to "tastpool" 2. Change class "platform" to "tastpool" https: //gitee.com/openharmony/ark_js_runtime/issues/I4Z7EU Change-Id: Ife3f2a9e52a02e5046e3ccd936f1993aa225e908
This commit is contained in:
parent
db34e6272d
commit
6efbeeaba1
6
BUILD.gn
6
BUILD.gn
@ -427,9 +427,9 @@ ecma_source = [
|
||||
"ecmascript/napi/jsnapi.cpp",
|
||||
"ecmascript/object_factory.cpp",
|
||||
"ecmascript/object_operator.cpp",
|
||||
"ecmascript/platform/platform.cpp",
|
||||
"ecmascript/platform/runner.cpp",
|
||||
"ecmascript/platform/task_queue.cpp",
|
||||
"ecmascript/taskpool/taskpool.cpp",
|
||||
"ecmascript/taskpool/runner.cpp",
|
||||
"ecmascript/taskpool/task_queue.cpp",
|
||||
"ecmascript/layout_info.cpp",
|
||||
"ecmascript/regexp/dyn_chunk.cpp",
|
||||
"ecmascript/regexp/regexp_executor.cpp",
|
||||
|
@ -37,7 +37,7 @@
|
||||
│ ├─ mem # 内存管理模块
|
||||
│ ├─ module # ECMAScript module模块
|
||||
│ ├─ napi # C++接口模块
|
||||
│ ├─ platform # 任务池
|
||||
│ ├─ taskpool # 任务池
|
||||
│ ├─ regexp # 正则引擎模块
|
||||
│ ├─ snapshot # 快照模块
|
||||
│ ├─ stubs # runtime桩函数
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <fstream>
|
||||
|
||||
#include "ecmascript/jspandafile/js_pandafile_manager.h"
|
||||
#include "ecmascript/platform/platform.h"
|
||||
#include "ecmascript/taskpool/taskpool.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
CMap<JSMethod *, struct StackInfo> CpuProfiler::staticStackInfo_ = CMap<JSMethod *, struct StackInfo>();
|
||||
@ -96,7 +96,7 @@ void CpuProfiler::StartCpuProfiler(const EcmaVM *vm, const std::string &fileName
|
||||
uint64_t ts = ProfileProcessor::GetMicrosecondsTimeStamp();
|
||||
ts = ts % TIME_CHANGE;
|
||||
SetProfileStart(ts);
|
||||
Platform::GetCurrentPlatform()->PostTask(std::make_unique<ProfileProcessor>(generator_, vm, interval_));
|
||||
Taskpool::GetCurrentTaskpool()->PostTask(std::make_unique<ProfileProcessor>(generator_, vm, interval_));
|
||||
}
|
||||
|
||||
void CpuProfiler::StopCpuProfiler()
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "ecmascript/dfx/cpu_profiler/profile_generator.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/interpreter/frame_handler.h"
|
||||
#include "ecmascript/platform/task.h"
|
||||
#include "ecmascript/taskpool/task.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
class ProfileProcessor : public Task {
|
||||
|
@ -47,7 +47,7 @@
|
||||
#include "ecmascript/mem/heap.h"
|
||||
#include "ecmascript/module/js_module_manager.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/platform/platform.h"
|
||||
#include "ecmascript/taskpool/taskpool.h"
|
||||
#include "ecmascript/regexp/regexp_parser_cache.h"
|
||||
#include "ecmascript/runtime_call_id.h"
|
||||
#ifndef PANDA_TARGET_WINDOWS
|
||||
@ -146,7 +146,7 @@ EcmaVM::EcmaVM(JSRuntimeOptions options)
|
||||
bool EcmaVM::Initialize()
|
||||
{
|
||||
ECMA_BYTRACE_NAME(BYTRACE_TAG_ARK, "EcmaVM::Initialize");
|
||||
Platform::GetCurrentPlatform()->Initialize();
|
||||
Taskpool::GetCurrentTaskpool()->Initialize();
|
||||
#ifndef PANDA_TARGET_WINDOWS
|
||||
RuntimeStubs::Initialize(thread_);
|
||||
#endif
|
||||
@ -272,7 +272,7 @@ bool EcmaVM::InitializeFinish()
|
||||
EcmaVM::~EcmaVM()
|
||||
{
|
||||
vmInitialized_ = false;
|
||||
Platform::GetCurrentPlatform()->Destroy();
|
||||
Taskpool::GetCurrentTaskpool()->Destroy();
|
||||
ClearNativeMethodsData();
|
||||
|
||||
if (runtimeStat_ != nullptr && runtimeStatEnabled_) {
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "ecmascript/mem/heap.h"
|
||||
#include "ecmascript/mem/object_xray.h"
|
||||
#include "ecmascript/mem/space.h"
|
||||
#include "ecmascript/platform/task.h"
|
||||
#include "ecmascript/taskpool/task.h"
|
||||
#include "ecmascript/snapshot/mem/snapshot_serialize.h"
|
||||
#include "include/panda_vm.h"
|
||||
#include "libpandabase/macros.h"
|
||||
@ -245,7 +245,7 @@ public:
|
||||
#if defined(ECMASCRIPT_ENABLE_THREAD_CHECK) && ECMASCRIPT_ENABLE_THREAD_CHECK
|
||||
// Exclude GC thread
|
||||
if (options_.IsEnableThreadCheck()) {
|
||||
if (!Platform::GetCurrentPlatform()->IsInThreadPool(std::this_thread::get_id()) &&
|
||||
if (!Taskpool::GetCurrentTaskpool()->IsInThreadPool(std::this_thread::get_id()) &&
|
||||
thread_->GetThreadId() != JSThread::GetCurrentThreadId()) {
|
||||
LOG(FATAL, RUNTIME) << "Fatal: ecma_vm cannot run in multi-thread!";
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "ecmascript/mem/parallel_marker-inl.h"
|
||||
#include "ecmascript/mem/space-inl.h"
|
||||
#include "ecmascript/mem/verification.h"
|
||||
#include "ecmascript/platform/platform.h"
|
||||
#include "ecmascript/taskpool/taskpool.h"
|
||||
#include "ecmascript/runtime_call_id.h"
|
||||
#include "os/mutex.h"
|
||||
|
||||
@ -45,7 +45,7 @@ void ConcurrentMarker::ConcurrentMarking()
|
||||
MEM_ALLOCATE_AND_GC_TRACE(vm_, ConcurrentMarking);
|
||||
ClockScope scope;
|
||||
InitializeMarking();
|
||||
Platform::GetCurrentPlatform()->PostTask(std::make_unique<MarkerTask>(heap_));
|
||||
Taskpool::GetCurrentTaskpool()->PostTask(std::make_unique<MarkerTask>(heap_));
|
||||
if (!heap_->IsFullMark() && heap_->IsParallelGCEnabled()) {
|
||||
heap_->PostParallelGCTask(ParallelGCTaskPhase::CONCURRENT_HANDLE_OLD_TO_NEW_TASK);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "ecmascript/mem/object_xray.h"
|
||||
#include "ecmascript/mem/parallel_work_helper.h"
|
||||
#include "ecmascript/mem/space.h"
|
||||
#include "ecmascript/platform/task.h"
|
||||
#include "ecmascript/taskpool/task.h"
|
||||
#include "os/mutex.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/mem/heap.h"
|
||||
#include "ecmascript/mem/space-inl.h"
|
||||
#include "ecmascript/platform/platform.h"
|
||||
#include "ecmascript/taskpool/taskpool.h"
|
||||
#include "ecmascript/runtime_call_id.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
@ -31,10 +31,10 @@ void ConcurrentSweeper::PostConcurrentSweepTasks(bool fullGC)
|
||||
{
|
||||
if (concurrentSweep_) {
|
||||
if (!fullGC) {
|
||||
Platform::GetCurrentPlatform()->PostTask(std::make_unique<SweeperTask>(this, OLD_SPACE));
|
||||
Taskpool::GetCurrentTaskpool()->PostTask(std::make_unique<SweeperTask>(this, OLD_SPACE));
|
||||
}
|
||||
Platform::GetCurrentPlatform()->PostTask(std::make_unique<SweeperTask>(this, NON_MOVABLE));
|
||||
Platform::GetCurrentPlatform()->PostTask(std::make_unique<SweeperTask>(this, MACHINE_CODE_SPACE));
|
||||
Taskpool::GetCurrentTaskpool()->PostTask(std::make_unique<SweeperTask>(this, NON_MOVABLE));
|
||||
Taskpool::GetCurrentTaskpool()->PostTask(std::make_unique<SweeperTask>(this, MACHINE_CODE_SPACE));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include <atomic>
|
||||
|
||||
#include "ecmascript/mem/space.h"
|
||||
#include "ecmascript/platform/task.h"
|
||||
#include "ecmascript/taskpool/task.h"
|
||||
#include "os/mutex.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -84,7 +84,7 @@ void FullGC::SweepPhases()
|
||||
{
|
||||
ECMA_BYTRACE_NAME(BYTRACE_TAG_ARK, "FullGC::SweepPhases");
|
||||
// process weak reference
|
||||
auto totalThreadCount = Platform::GetCurrentPlatform()->GetTotalThreadNum() + 1; // gc thread and main thread
|
||||
auto totalThreadCount = Taskpool::GetCurrentTaskpool()->GetTotalThreadNum() + 1; // gc thread and main thread
|
||||
for (uint32_t i = 0; i < totalThreadCount; i++) {
|
||||
ProcessQueue *queue = workList_->GetWeakReferenceQueue(i);
|
||||
|
||||
|
@ -78,7 +78,7 @@ void Heap::Initialize()
|
||||
#if defined(IS_STANDARD_SYSTEM)
|
||||
concurrentMarkingEnabled_ = false;
|
||||
#endif
|
||||
workList_ = new WorkerHelper(this, Platform::GetCurrentPlatform()->GetTotalThreadNum() + 1);
|
||||
workList_ = new WorkerHelper(this, Taskpool::GetCurrentTaskpool()->GetTotalThreadNum() + 1);
|
||||
stwYoungGC_ = new STWYoungGC(this, paralledGc_);
|
||||
fullGC_ = new FullGC(this);
|
||||
|
||||
@ -208,7 +208,7 @@ void Heap::Resume(TriggerGCType gcType)
|
||||
toSpace_->SetWaterLine();
|
||||
if (paralledGc_) {
|
||||
isClearTaskFinished_ = false;
|
||||
Platform::GetCurrentPlatform()->PostTask(std::make_unique<AsyncClearTask>(this, gcType));
|
||||
Taskpool::GetCurrentTaskpool()->PostTask(std::make_unique<AsyncClearTask>(this, gcType));
|
||||
} else {
|
||||
ReclaimRegions(gcType);
|
||||
}
|
||||
@ -546,7 +546,7 @@ void Heap::WaitConcurrentMarkingFinished()
|
||||
void Heap::PostParallelGCTask(ParallelGCTaskPhase gcTask)
|
||||
{
|
||||
IncreaseTaskCount();
|
||||
Platform::GetCurrentPlatform()->PostTask(std::make_unique<ParallelGCTask>(this, gcTask));
|
||||
Taskpool::GetCurrentTaskpool()->PostTask(std::make_unique<ParallelGCTask>(this, gcTask));
|
||||
}
|
||||
|
||||
void Heap::IncreaseTaskCount()
|
||||
@ -558,7 +558,7 @@ void Heap::IncreaseTaskCount()
|
||||
bool Heap::CheckCanDistributeTask()
|
||||
{
|
||||
os::memory::LockHolder holder(waitTaskFinishedMutex_);
|
||||
return (runningTastCount_ < Platform::GetCurrentPlatform()->GetTotalThreadNum() - 1);
|
||||
return (runningTastCount_ < Taskpool::GetCurrentTaskpool()->GetTotalThreadNum() - 1);
|
||||
}
|
||||
|
||||
void Heap::ReduceTaskCount()
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "ecmascript/mem/parallel_work_helper.h"
|
||||
#include "ecmascript/mem/linear_space.h"
|
||||
#include "ecmascript/mem/sparse_space.h"
|
||||
#include "ecmascript/platform/platform.h"
|
||||
#include "ecmascript/taskpool/taskpool.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
class EcmaVM;
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "ecmascript/mem/mark_word.h"
|
||||
#include "ecmascript/mem/region-inl.h"
|
||||
#include "ecmascript/mem/remembered_set.h"
|
||||
#include "ecmascript/platform/platform.h"
|
||||
#include "ecmascript/taskpool/taskpool.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
// Move regions with a survival rate of more than 75% to new space
|
||||
@ -121,7 +121,7 @@ int ParallelEvacuation::CalculateEvacuationThreadNum()
|
||||
{
|
||||
int length = fragments_.size();
|
||||
int regionPerThread = 8;
|
||||
int maxThreadNum = Platform::GetCurrentPlatform()->GetTotalThreadNum();
|
||||
int maxThreadNum = Taskpool::GetCurrentTaskpool()->GetTotalThreadNum();
|
||||
return std::min(std::max(1, length / regionPerThread), maxThreadNum);
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ int ParallelEvacuation::CalculateUpdateThreadNum()
|
||||
int length = fragments_.size();
|
||||
double regionPerThread = 1.0 / 4;
|
||||
length = static_cast<int>(std::pow(length, regionPerThread));
|
||||
int maxThreadNum = Platform::GetCurrentPlatform()->GetTotalThreadNum();
|
||||
int maxThreadNum = Taskpool::GetCurrentTaskpool()->GetTotalThreadNum();
|
||||
return std::min(std::max(1, length), maxThreadNum);
|
||||
}
|
||||
} // namespace panda::ecmascript
|
||||
|
@ -67,7 +67,7 @@ void ParallelEvacuation::EvacuateSpace()
|
||||
os::memory::LockHolder holder(mutex_);
|
||||
parallel_ = CalculateEvacuationThreadNum();
|
||||
for (int i = 0; i < parallel_; i++) {
|
||||
Platform::GetCurrentPlatform()->PostTask(std::make_unique<EvacuationTask>(this));
|
||||
Taskpool::GetCurrentTaskpool()->PostTask(std::make_unique<EvacuationTask>(this));
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,7 +202,7 @@ void ParallelEvacuation::UpdateReference()
|
||||
os::memory::LockHolder holder(mutex_);
|
||||
parallel_ = CalculateUpdateThreadNum();
|
||||
for (int i = 0; i < parallel_; i++) {
|
||||
Platform::GetCurrentPlatform()->PostTask(std::make_unique<UpdateReferenceTask>(this));
|
||||
Taskpool::GetCurrentTaskpool()->PostTask(std::make_unique<UpdateReferenceTask>(this));
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,7 +229,7 @@ void ParallelEvacuation::UpdateRoot()
|
||||
|
||||
void ParallelEvacuation::UpdateRecordWeakReference()
|
||||
{
|
||||
auto totalThreadCount = Platform::GetCurrentPlatform()->GetTotalThreadNum() + 1;
|
||||
auto totalThreadCount = Taskpool::GetCurrentTaskpool()->GetTotalThreadNum() + 1;
|
||||
for (uint32_t i = 0; i < totalThreadCount; i++) {
|
||||
ProcessQueue *queue = heap_->GetWorkList()->GetWeakReferenceQueue(i);
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include "ecmascript/mem/remembered_set.h"
|
||||
#include "ecmascript/mem/space.h"
|
||||
#include "ecmascript/mem/tagged_object.h"
|
||||
#include "ecmascript/platform/task.h"
|
||||
#include "ecmascript/taskpool/task.h"
|
||||
#include "os/mutex.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
#include "ecmascript/mem/mark_stack-inl.h"
|
||||
#include "ecmascript/mem/slots.h"
|
||||
#include "ecmascript/platform/platform.h"
|
||||
#include "ecmascript/taskpool/taskpool.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using SlotNeedUpdate = std::pair<TaggedObject *, ObjectSlot>;
|
||||
@ -204,8 +204,8 @@ private:
|
||||
|
||||
Heap *heap_;
|
||||
uint32_t threadNum_;
|
||||
WorkNodeHolder workList_[MAX_PLATFORM_THREAD_NUM + 1];
|
||||
ContinuousStack<JSTaggedType> *continuousQueue_[MAX_PLATFORM_THREAD_NUM + 1];
|
||||
WorkNodeHolder workList_[MAX_TASKPOOL_THREAD_NUM + 1];
|
||||
ContinuousStack<JSTaggedType> *continuousQueue_[MAX_TASKPOOL_THREAD_NUM + 1];
|
||||
GlobalWorkList globalWork_;
|
||||
uintptr_t markSpace_;
|
||||
uintptr_t spaceTop_;
|
||||
|
@ -82,7 +82,7 @@ void STWYoungGC::ParallelMarkingPhase()
|
||||
}
|
||||
heap_->WaitRunningTaskFinished();
|
||||
|
||||
auto totalThreadCount = Platform::GetCurrentPlatform()->GetTotalThreadNum() + 1; // gc thread and main thread
|
||||
auto totalThreadCount = Taskpool::GetCurrentTaskpool()->GetTotalThreadNum() + 1; // gc thread and main thread
|
||||
for (uint32_t i = 0; i < totalThreadCount; i++) {
|
||||
SlotNeedUpdate needUpdate(nullptr, ObjectSlot(0));
|
||||
while (workList_->GetSlotNeedUpdate(i, &needUpdate)) {
|
||||
@ -94,7 +94,7 @@ void STWYoungGC::ParallelMarkingPhase()
|
||||
void STWYoungGC::SweepPhases()
|
||||
{
|
||||
ECMA_BYTRACE_NAME(BYTRACE_TAG_ARK, "STWYoungGC::SweepPhases");
|
||||
auto totalThreadCount = Platform::GetCurrentPlatform()->GetTotalThreadNum() + 1; // gc thread and main thread
|
||||
auto totalThreadCount = Taskpool::GetCurrentTaskpool()->GetTotalThreadNum() + 1; // gc thread and main thread
|
||||
for (uint32_t i = 0; i < totalThreadCount; i++) {
|
||||
ProcessQueue *queue = workList_->GetWeakReferenceQueue(i);
|
||||
while (true) {
|
||||
|
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/platform/runner.h"
|
||||
#include "ecmascript/taskpool/runner.h"
|
||||
|
||||
#include "os/thread.h"
|
||||
|
@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMASCRIPT_PLATFORM_RUNNER_H
|
||||
#define ECMASCRIPT_PLATFORM_RUNNER_H
|
||||
#ifndef ECMASCRIPT_TASKPOOL_RUNNER_H
|
||||
#define ECMASCRIPT_TASKPOOL_RUNNER_H
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
@ -22,11 +22,11 @@
|
||||
#include <vector>
|
||||
|
||||
#include "ecmascript/common.h"
|
||||
#include "ecmascript/platform/task_queue.h"
|
||||
#include "ecmascript/taskpool/task_queue.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
static constexpr uint32_t MAX_PLATFORM_THREAD_NUM = 7;
|
||||
static constexpr uint32_t DEFAULT_PLATFORM_THREAD_NUM = 0;
|
||||
static constexpr uint32_t MAX_TASKPOOL_THREAD_NUM = 7;
|
||||
static constexpr uint32_t DEFAULT_TASKPOOL_THREAD_NUM = 0;
|
||||
|
||||
class Runner {
|
||||
public:
|
||||
@ -64,8 +64,8 @@ private:
|
||||
|
||||
std::vector<std::unique_ptr<std::thread>> threadPool_ {};
|
||||
TaskQueue taskQueue_ {};
|
||||
std::array<Task*, MAX_PLATFORM_THREAD_NUM + 1> runningTask_;
|
||||
std::array<Task*, MAX_TASKPOOL_THREAD_NUM + 1> runningTask_;
|
||||
uint32_t totalThreadNum_ {0};
|
||||
};
|
||||
} // namespace panda::ecmascript
|
||||
#endif // ECMASCRIPT_PLATFORM_RUNNER_H
|
||||
#endif // ECMASCRIPT_TASKPOOL_RUNNER_H
|
@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMASCRIPT_PLATFORM_TASK_H
|
||||
#define ECMASCRIPT_PLATFORM_TASK_H
|
||||
#ifndef ECMASCRIPT_TASKPOOL_TASK_H
|
||||
#define ECMASCRIPT_TASKPOOL_TASK_H
|
||||
|
||||
#include "macros.h"
|
||||
|
||||
@ -42,4 +42,4 @@ private:
|
||||
volatile bool terminate_ {false};
|
||||
};
|
||||
} // namespace panda::ecmascript
|
||||
#endif // ECMASCRIPT_PLATFORM_TASK_H
|
||||
#endif // ECMASCRIPT_TASKPOOL_TASK_H
|
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/platform/task_queue.h"
|
||||
#include "ecmascript/taskpool/task_queue.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
void TaskQueue::PostTask(std::unique_ptr<Task> task)
|
@ -13,15 +13,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMASCRIPT_PLATFORM_TASK_QUEUE_H
|
||||
#define ECMASCRIPT_PLATFORM_TASK_QUEUE_H
|
||||
#ifndef ECMASCRIPT_TASKPOOL_TASK_QUEUE_H
|
||||
#define ECMASCRIPT_TASKPOOL_TASK_QUEUE_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
|
||||
#include "ecmascript/platform/task.h"
|
||||
#include "ecmascript/taskpool/task.h"
|
||||
#include "os/mutex.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
@ -46,4 +46,4 @@ private:
|
||||
os::memory::ConditionVariable cv_;
|
||||
};
|
||||
} // namespace panda::ecmascript
|
||||
#endif // ECMASCRIPT_PLATFORM_TASK_QUEUE_H
|
||||
#endif // ECMASCRIPT_TASKPOOL_TASK_QUEUE_H
|
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/platform/platform.h"
|
||||
#include "ecmascript/taskpool/taskpool.h"
|
||||
|
||||
#ifndef PANDA_TARGET_WINDOWS
|
||||
#include "sys/sysinfo.h"
|
||||
@ -22,7 +22,7 @@
|
||||
#endif
|
||||
|
||||
namespace panda::ecmascript {
|
||||
void Platform::Initialize(int threadNum)
|
||||
void Taskpool::Initialize(int threadNum)
|
||||
{
|
||||
os::memory::LockHolder lock(mutex_);
|
||||
if (isInitialized_++ <= 0) {
|
||||
@ -30,7 +30,7 @@ void Platform::Initialize(int threadNum)
|
||||
}
|
||||
}
|
||||
|
||||
void Platform::Destroy()
|
||||
void Taskpool::Destroy()
|
||||
{
|
||||
os::memory::LockHolder lock(mutex_);
|
||||
if (isInitialized_ <= 0) {
|
||||
@ -44,10 +44,10 @@ void Platform::Destroy()
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Platform::TheMostSuitableThreadNum(uint32_t threadNum) const
|
||||
uint32_t Taskpool::TheMostSuitableThreadNum(uint32_t threadNum) const
|
||||
{
|
||||
if (threadNum > 0) {
|
||||
return std::min<uint32_t>(threadNum, MAX_PLATFORM_THREAD_NUM);
|
||||
return std::min<uint32_t>(threadNum, MAX_TASKPOOL_THREAD_NUM);
|
||||
}
|
||||
#ifndef PANDA_TARGET_WINDOWS
|
||||
uint32_t numOfCpuCore = get_nprocs() - 1;
|
||||
@ -56,6 +56,6 @@ uint32_t Platform::TheMostSuitableThreadNum(uint32_t threadNum) const
|
||||
GetSystemInfo(&info);
|
||||
uint32_t numOfCpuCore = info.dwNumberOfProcessors;
|
||||
#endif
|
||||
return std::min<uint32_t>(numOfCpuCore, MAX_PLATFORM_THREAD_NUM);
|
||||
return std::min<uint32_t>(numOfCpuCore, MAX_TASKPOOL_THREAD_NUM);
|
||||
}
|
||||
} // namespace panda::ecmascript
|
@ -13,36 +13,36 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMASCRIPT_PALTFORM_PLATFORM_H
|
||||
#define ECMASCRIPT_PALTFORM_PLATFORM_H
|
||||
#ifndef ECMASCRIPT_TASKPOOL_TASKPOOL_H
|
||||
#define ECMASCRIPT_TASKPOOL_TASKPOOL_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ecmascript/common.h"
|
||||
#include "ecmascript/platform/runner.h"
|
||||
#include "ecmascript/taskpool/runner.h"
|
||||
#include "os/mutex.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
class Platform {
|
||||
class Taskpool {
|
||||
public:
|
||||
static Platform *GetCurrentPlatform()
|
||||
static Taskpool *GetCurrentTaskpool()
|
||||
{
|
||||
static Platform platform;
|
||||
return &platform;
|
||||
static Taskpool taskpool;
|
||||
return &taskpool;
|
||||
}
|
||||
|
||||
Platform() = default;
|
||||
PUBLIC_API ~Platform()
|
||||
Taskpool() = default;
|
||||
PUBLIC_API ~Taskpool()
|
||||
{
|
||||
os::memory::LockHolder lock(mutex_);
|
||||
runner_->TerminateThread();
|
||||
isInitialized_ = 0;
|
||||
}
|
||||
|
||||
NO_COPY_SEMANTIC(Platform);
|
||||
NO_MOVE_SEMANTIC(Platform);
|
||||
NO_COPY_SEMANTIC(Taskpool);
|
||||
NO_MOVE_SEMANTIC(Taskpool);
|
||||
|
||||
void Initialize(int threadNum = DEFAULT_PLATFORM_THREAD_NUM);
|
||||
void Initialize(int threadNum = DEFAULT_TASKPOOL_THREAD_NUM);
|
||||
void Destroy();
|
||||
|
||||
void PostTask(std::unique_ptr<Task> task) const
|
Loading…
Reference in New Issue
Block a user