mirror of
https://github.com/libretro/parallel-gx1.git
synced 2026-11-07 04:26:01 -10:00
Waits that polled now block on an eventcount that the waited-on thread notifies: - Booting in dual core waits for the CPU thread to reach its run loop instead of polling every millisecond. - AsyncShaderCompiler::WaitUntilCompletion wakes as each worker finishes an item instead of every 33 ms. Timed sleeps go through Common::SleepUntil and SleepCurrentThreadUs, built on retro_sleep_us: the CoreTiming throttle, PrecisionTimer, real Wiimote report pacing, Bluetooth timed transfers, the Linux L2CAP connect retry and the BBA read thread's idle wait. FrameTiming::ThrottleFrame had no callers and is deleted.
103 lines
1.8 KiB
C++
103 lines
1.8 KiB
C++
// Copyright 2008 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "Common/Thread.h"
|
|
|
|
#ifdef _WIN32
|
|
#include <windows.h>
|
|
#include <processthreadsapi.h>
|
|
#else
|
|
#include <pthread.h>
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#ifdef __APPLE__
|
|
#include <mach/mach.h>
|
|
#elif defined BSD4_4 || defined __FreeBSD__ || defined __OpenBSD__
|
|
#include <pthread_np.h>
|
|
#elif defined __NetBSD__
|
|
#include <sched.h>
|
|
#elif defined __HAIKU__
|
|
#include <OS.h>
|
|
#endif
|
|
|
|
#include <retro_timers.h>
|
|
#include <rthreads/rthreads.h>
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
namespace Common
|
|
{
|
|
int CurrentThreadId()
|
|
{
|
|
#ifdef _WIN32
|
|
return GetCurrentThreadId();
|
|
#elif defined __APPLE__
|
|
return mach_thread_self();
|
|
#else
|
|
return 0;
|
|
#endif
|
|
}
|
|
|
|
void SleepCurrentThread(int ms)
|
|
{
|
|
retro_sleep(ms);
|
|
}
|
|
|
|
void SleepCurrentThreadUs(long long us)
|
|
{
|
|
if (us > 0)
|
|
retro_sleep_us((unsigned)us);
|
|
}
|
|
|
|
void YieldCPU()
|
|
{
|
|
sthread_yield();
|
|
}
|
|
|
|
void SetCurrentThreadName(const char* name)
|
|
{
|
|
sthread_setname(name);
|
|
}
|
|
|
|
#ifndef _WIN32
|
|
|
|
std::tuple<void*, size_t> GetCurrentThreadStack()
|
|
{
|
|
void* stack_addr;
|
|
size_t stack_size;
|
|
|
|
pthread_t self = pthread_self();
|
|
|
|
#ifdef __APPLE__
|
|
stack_size = pthread_get_stacksize_np(self);
|
|
stack_addr = reinterpret_cast<u8*>(pthread_get_stackaddr_np(self)) - stack_size;
|
|
#elif defined __OpenBSD__
|
|
stack_t stack;
|
|
pthread_stackseg_np(self, &stack);
|
|
|
|
stack_addr = reinterpret_cast<u8*>(stack.ss_sp) - stack.ss_size;
|
|
stack_size = stack.ss_size;
|
|
#else
|
|
pthread_attr_t attr;
|
|
|
|
#ifdef __FreeBSD__
|
|
pthread_attr_init(&attr);
|
|
pthread_attr_get_np(self, &attr);
|
|
#else
|
|
// Linux and NetBSD
|
|
pthread_getattr_np(self, &attr);
|
|
#endif
|
|
|
|
pthread_attr_getstack(&attr, &stack_addr, &stack_size);
|
|
|
|
pthread_attr_destroy(&attr);
|
|
#endif
|
|
|
|
return std::make_tuple(stack_addr, stack_size);
|
|
}
|
|
|
|
#endif
|
|
|
|
} // namespace Common
|