From ed0319cfed2c99e6366aaf725d96bb28a9332e4d Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 2 Jul 2022 12:33:49 -0400 Subject: common/fiber: make fibers easier to use --- src/core/cpu_manager.cpp | 51 +++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 35 deletions(-) (limited to 'src/core/cpu_manager.cpp') diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index fd6928105..f184b904b 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -41,51 +41,32 @@ void CpuManager::Shutdown() { } } -std::function CpuManager::GetGuestThreadStartFunc() { - return GuestThreadFunction; -} - -std::function CpuManager::GetIdleThreadStartFunc() { - return IdleThreadFunction; -} - -std::function CpuManager::GetShutdownThreadStartFunc() { - return ShutdownThreadFunction; -} - -void CpuManager::GuestThreadFunction(void* cpu_manager_) { - CpuManager* cpu_manager = static_cast(cpu_manager_); - if (cpu_manager->is_multicore) { - cpu_manager->MultiCoreRunGuestThread(); +void CpuManager::GuestThreadFunction() { + if (is_multicore) { + MultiCoreRunGuestThread(); } else { - cpu_manager->SingleCoreRunGuestThread(); + SingleCoreRunGuestThread(); } } -void CpuManager::GuestRewindFunction(void* cpu_manager_) { - CpuManager* cpu_manager = static_cast(cpu_manager_); - if (cpu_manager->is_multicore) { - cpu_manager->MultiCoreRunGuestLoop(); +void CpuManager::GuestRewindFunction() { + if (is_multicore) { + MultiCoreRunGuestLoop(); } else { - cpu_manager->SingleCoreRunGuestLoop(); + SingleCoreRunGuestLoop(); } } -void CpuManager::IdleThreadFunction(void* cpu_manager_) { - CpuManager* cpu_manager = static_cast(cpu_manager_); - if (cpu_manager->is_multicore) { - cpu_manager->MultiCoreRunIdleThread(); +void CpuManager::IdleThreadFunction() { + if (is_multicore) { + MultiCoreRunIdleThread(); } else { - cpu_manager->SingleCoreRunIdleThread(); + SingleCoreRunIdleThread(); } } -void CpuManager::ShutdownThreadFunction(void* cpu_manager) { - static_cast(cpu_manager)->ShutdownThread(); -} - -void* CpuManager::GetStartFuncParameter() { - return this; +void CpuManager::ShutdownThreadFunction() { + ShutdownThread(); } /////////////////////////////////////////////////////////////////////////////// @@ -97,7 +78,7 @@ void CpuManager::MultiCoreRunGuestThread() { kernel.CurrentScheduler()->OnThreadStart(); auto* thread = kernel.CurrentScheduler()->GetSchedulerCurrentThread(); auto& host_context = thread->GetHostContext(); - host_context->SetRewindPoint(GuestRewindFunction, this); + host_context->SetRewindPoint([this] { GuestRewindFunction(); }); MultiCoreRunGuestLoop(); } @@ -134,7 +115,7 @@ void CpuManager::SingleCoreRunGuestThread() { kernel.CurrentScheduler()->OnThreadStart(); auto* thread = kernel.CurrentScheduler()->GetSchedulerCurrentThread(); auto& host_context = thread->GetHostContext(); - host_context->SetRewindPoint(GuestRewindFunction, this); + host_context->SetRewindPoint([this] { GuestRewindFunction(); }); SingleCoreRunGuestLoop(); } -- cgit v1.2.3