Add Platform::Yield
This commit is contained in:
@@ -748,6 +748,11 @@ void AndroidPlatform::Sleep(int32 milliseconds)
|
|||||||
usleep(milliseconds * 1000);
|
usleep(milliseconds * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AndroidPlatform::Yield()
|
||||||
|
{
|
||||||
|
pthread_yield();
|
||||||
|
}
|
||||||
|
|
||||||
double AndroidPlatform::GetTimeSeconds()
|
double AndroidPlatform::GetTimeSeconds()
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ public:
|
|||||||
static void SetThreadPriority(ThreadPriority priority);
|
static void SetThreadPriority(ThreadPriority priority);
|
||||||
static void SetThreadAffinityMask(uint64 affinityMask);
|
static void SetThreadAffinityMask(uint64 affinityMask);
|
||||||
static void Sleep(int32 milliseconds);
|
static void Sleep(int32 milliseconds);
|
||||||
|
static void Yield();
|
||||||
static double GetTimeSeconds();
|
static double GetTimeSeconds();
|
||||||
static uint64 GetTimeCycles();
|
static uint64 GetTimeCycles();
|
||||||
FORCE_INLINE static uint64 GetClockFrequency()
|
FORCE_INLINE static uint64 GetClockFrequency()
|
||||||
|
|||||||
@@ -293,6 +293,11 @@ void ApplePlatform::Sleep(int32 milliseconds)
|
|||||||
usleep(milliseconds * 1000);
|
usleep(milliseconds * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ApplePlatform::Yield()
|
||||||
|
{
|
||||||
|
pthread_yield();
|
||||||
|
}
|
||||||
|
|
||||||
double ApplePlatform::GetTimeSeconds()
|
double ApplePlatform::GetTimeSeconds()
|
||||||
{
|
{
|
||||||
return SecondsPerCycle * mach_absolute_time();
|
return SecondsPerCycle * mach_absolute_time();
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ public:
|
|||||||
static void SetThreadPriority(ThreadPriority priority);
|
static void SetThreadPriority(ThreadPriority priority);
|
||||||
static void SetThreadAffinityMask(uint64 affinityMask);
|
static void SetThreadAffinityMask(uint64 affinityMask);
|
||||||
static void Sleep(int32 milliseconds);
|
static void Sleep(int32 milliseconds);
|
||||||
|
static void Yield();
|
||||||
static double GetTimeSeconds();
|
static double GetTimeSeconds();
|
||||||
static uint64 GetTimeCycles();
|
static uint64 GetTimeCycles();
|
||||||
static uint64 GetClockFrequency();
|
static uint64 GetClockFrequency();
|
||||||
|
|||||||
@@ -436,11 +436,16 @@ public:
|
|||||||
static void SetThreadAffinityMask(uint64 affinityMask) = delete;
|
static void SetThreadAffinityMask(uint64 affinityMask) = delete;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Suspends the execution of the current thread until the time-out interval elapses
|
/// Suspends the execution of the current thread until the time-out interval elapses.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="milliseconds">The time interval for which execution is to be suspended, in milliseconds.</param>
|
/// <param name="milliseconds">The time interval for which execution is to be suspended, in milliseconds.</param>
|
||||||
static void Sleep(int32 milliseconds) = delete;
|
static void Sleep(int32 milliseconds) = delete;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Yields the execution of the current thread to another thread that is ready to run on the current processor.
|
||||||
|
/// </summary>
|
||||||
|
static void Yield() = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current time in seconds.
|
/// Gets the current time in seconds.
|
||||||
|
|||||||
@@ -1836,6 +1836,11 @@ void LinuxPlatform::Sleep(int32 milliseconds)
|
|||||||
usleep(milliseconds * 1000);
|
usleep(milliseconds * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LinuxPlatform::Yield()
|
||||||
|
{
|
||||||
|
pthread_yield();
|
||||||
|
}
|
||||||
|
|
||||||
double LinuxPlatform::GetTimeSeconds()
|
double LinuxPlatform::GetTimeSeconds()
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ public:
|
|||||||
static void SetThreadPriority(ThreadPriority priority);
|
static void SetThreadPriority(ThreadPriority priority);
|
||||||
static void SetThreadAffinityMask(uint64 affinityMask);
|
static void SetThreadAffinityMask(uint64 affinityMask);
|
||||||
static void Sleep(int32 milliseconds);
|
static void Sleep(int32 milliseconds);
|
||||||
|
static void Yield();
|
||||||
static double GetTimeSeconds();
|
static double GetTimeSeconds();
|
||||||
static uint64 GetTimeCycles();
|
static uint64 GetTimeCycles();
|
||||||
FORCE_INLINE static uint64 GetClockFrequency()
|
FORCE_INLINE static uint64 GetClockFrequency()
|
||||||
|
|||||||
@@ -68,6 +68,7 @@
|
|||||||
#undef CreateMutex
|
#undef CreateMutex
|
||||||
#undef DrawState
|
#undef DrawState
|
||||||
#undef LoadLibrary
|
#undef LoadLibrary
|
||||||
|
#undef Yield
|
||||||
#undef GetEnvironmentVariable
|
#undef GetEnvironmentVariable
|
||||||
#undef SetEnvironmentVariable
|
#undef SetEnvironmentVariable
|
||||||
|
|
||||||
|
|||||||
@@ -400,6 +400,11 @@ void Win32Platform::Sleep(int32 milliseconds)
|
|||||||
WaitForSingleObject(timer, INFINITE);
|
WaitForSingleObject(timer, INFINITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Win32Platform::Yield()
|
||||||
|
{
|
||||||
|
SwitchToThread();
|
||||||
|
}
|
||||||
|
|
||||||
double Win32Platform::GetTimeSeconds()
|
double Win32Platform::GetTimeSeconds()
|
||||||
{
|
{
|
||||||
LARGE_INTEGER counter;
|
LARGE_INTEGER counter;
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ public:
|
|||||||
static void SetThreadPriority(ThreadPriority priority);
|
static void SetThreadPriority(ThreadPriority priority);
|
||||||
static void SetThreadAffinityMask(uint64 affinityMask);
|
static void SetThreadAffinityMask(uint64 affinityMask);
|
||||||
static void Sleep(int32 milliseconds);
|
static void Sleep(int32 milliseconds);
|
||||||
|
static void Yield();
|
||||||
static double GetTimeSeconds();
|
static double GetTimeSeconds();
|
||||||
static uint64 GetTimeCycles();
|
static uint64 GetTimeCycles();
|
||||||
static uint64 GetClockFrequency();
|
static uint64 GetClockFrequency();
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ private:
|
|||||||
// Wait for all threads to stop adding items before resizing can happen
|
// Wait for all threads to stop adding items before resizing can happen
|
||||||
RETRY:
|
RETRY:
|
||||||
while (Platform::AtomicRead(&_threadsAdding))
|
while (Platform::AtomicRead(&_threadsAdding))
|
||||||
Platform::Sleep(0);
|
Platform::Yield();
|
||||||
|
|
||||||
// Thread-safe resizing
|
// Thread-safe resizing
|
||||||
_locker.Lock();
|
_locker.Lock();
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ RETRY:
|
|||||||
{
|
{
|
||||||
// Someone else is doing opposite operation so wait for it's end
|
// Someone else is doing opposite operation so wait for it's end
|
||||||
// TODO: use ConditionVariable+CriticalSection to prevent active-waiting
|
// TODO: use ConditionVariable+CriticalSection to prevent active-waiting
|
||||||
Platform::Sleep(0);
|
Platform::Yield();
|
||||||
goto RETRY;
|
goto RETRY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ RETRY:
|
|||||||
if (exclusively && Platform::AtomicRead(thisCounter) != 0)
|
if (exclusively && Platform::AtomicRead(thisCounter) != 0)
|
||||||
{
|
{
|
||||||
// Someone else is doing opposite operation so wait for it's end
|
// Someone else is doing opposite operation so wait for it's end
|
||||||
Platform::Sleep(0);
|
Platform::Yield();
|
||||||
goto RETRY;
|
goto RETRY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user