mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-28 15:53:55 -04:00
pipeline: Add Thread::relax() for more efficient busy waiting
Equivalent to cpu_relax() or the pause instruction on x86
This commit is contained in:
parent
c3ce8164bc
commit
70c49a6416
@ -222,6 +222,20 @@ consider_yield() {
|
|||||||
ThreadImpl::consider_yield();
|
ThreadImpl::consider_yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Equivalent to the pause instruction on x86 or the yield instruction on ARM,
|
||||||
|
* to be called in spin loops.
|
||||||
|
*/
|
||||||
|
INLINE void Thread::
|
||||||
|
relax() {
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
YieldProcessor();
|
||||||
|
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64))
|
||||||
|
__asm__ __volatile__("pause");
|
||||||
|
#elif defined(__arm__) || defined(__aarch64__)
|
||||||
|
__asm__ __volatile__ ("yield" ::: "memory");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns thread statistics. The first number is the total number of context
|
* Returns thread statistics. The first number is the total number of context
|
||||||
|
@ -80,6 +80,7 @@ PUBLISHED:
|
|||||||
|
|
||||||
BLOCKING INLINE static void force_yield();
|
BLOCKING INLINE static void force_yield();
|
||||||
BLOCKING INLINE static void consider_yield();
|
BLOCKING INLINE static void consider_yield();
|
||||||
|
BLOCKING INLINE static void relax();
|
||||||
|
|
||||||
INLINE static bool get_context_switches(size_t &total, size_t &involuntary);
|
INLINE static bool get_context_switches(size_t &total, size_t &involuntary);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user