mirror of
https://github.com/cemu-project/Cemu.git
synced 2024-11-22 09:09:18 +01:00
Use memory barriers in Linux fiber implementation
Prevent compilers from caching TLS variables across swapcontext calls
This commit is contained in:
parent
524188bb7a
commit
62889adfde
@ -1,5 +1,6 @@
|
|||||||
#include "Fiber.h"
|
#include "Fiber.h"
|
||||||
#include <ucontext.h>
|
#include <ucontext.h>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
thread_local Fiber* sCurrentFiber{};
|
thread_local Fiber* sCurrentFiber{};
|
||||||
|
|
||||||
@ -44,7 +45,9 @@ void Fiber::Switch(Fiber& targetFiber)
|
|||||||
{
|
{
|
||||||
Fiber* leavingFiber = sCurrentFiber;
|
Fiber* leavingFiber = sCurrentFiber;
|
||||||
sCurrentFiber = &targetFiber;
|
sCurrentFiber = &targetFiber;
|
||||||
|
std::atomic_thread_fence(std::memory_order_seq_cst);
|
||||||
swapcontext((ucontext_t*)(leavingFiber->m_implData), (ucontext_t*)(targetFiber.m_implData));
|
swapcontext((ucontext_t*)(leavingFiber->m_implData), (ucontext_t*)(targetFiber.m_implData));
|
||||||
|
std::atomic_thread_fence(std::memory_order_seq_cst);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Fiber::GetFiberPrivateData()
|
void* Fiber::GetFiberPrivateData()
|
||||||
|
Loading…
Reference in New Issue
Block a user