mirror of
https://github.com/cemu-project/Cemu.git
synced 2024-12-04 23:14:24 +01:00
43 lines
1014 B
C++
43 lines
1014 B
C++
|
#include "Fiber.h"
|
||
|
#if BOOST_OS_WINDOWS
|
||
|
#include <Windows.h>
|
||
|
|
||
|
thread_local Fiber* sCurrentFiber{};
|
||
|
|
||
|
Fiber::Fiber(void(*FiberEntryPoint)(void* userParam), void* userParam, void* privateData) : m_privateData(privateData)
|
||
|
{
|
||
|
HANDLE fiberHandle = CreateFiber(2 * 1024 * 1024, (LPFIBER_START_ROUTINE)FiberEntryPoint, userParam);
|
||
|
this->m_implData = (void*)fiberHandle;
|
||
|
}
|
||
|
|
||
|
Fiber::Fiber(void* privateData) : m_privateData(privateData)
|
||
|
{
|
||
|
this->m_implData = (void*)ConvertThreadToFiber(nullptr);
|
||
|
this->m_stackPtr = nullptr;
|
||
|
}
|
||
|
|
||
|
Fiber::~Fiber()
|
||
|
{
|
||
|
DeleteFiber((HANDLE)m_implData);
|
||
|
}
|
||
|
|
||
|
Fiber* Fiber::PrepareCurrentThread(void* privateData)
|
||
|
{
|
||
|
cemu_assert_debug(sCurrentFiber == nullptr); // thread already prepared
|
||
|
Fiber* currentFiber = new Fiber(privateData);
|
||
|
sCurrentFiber = currentFiber;
|
||
|
return currentFiber;
|
||
|
}
|
||
|
|
||
|
void Fiber::Switch(Fiber& targetFiber)
|
||
|
{
|
||
|
sCurrentFiber = &targetFiber;
|
||
|
SwitchToFiber((HANDLE)targetFiber.m_implData);
|
||
|
}
|
||
|
|
||
|
void* Fiber::GetFiberPrivateData()
|
||
|
{
|
||
|
return sCurrentFiber->m_privateData;
|
||
|
}
|
||
|
|
||
|
#endif
|