[Linux/Threading] Self-suspend with condition variable instead of spin
This commit is contained in:
@@ -15,6 +15,10 @@
|
||||
#include <string>
|
||||
|
||||
#include "xenia/base/mutex.h"
|
||||
#if XE_PLATFORM_LINUX
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#endif
|
||||
#include "xenia/base/threading.h"
|
||||
#include "xenia/cpu/thread.h"
|
||||
#include "xenia/cpu/thread_state.h"
|
||||
@@ -426,6 +430,13 @@ class XThread : public XObject, public cpu::Thread {
|
||||
X_STATUS Delay(uint32_t processor_mode, uint32_t alertable,
|
||||
uint64_t interval);
|
||||
|
||||
#if XE_PLATFORM_LINUX
|
||||
// Performs self-suspension: increments suspend_count and blocks until
|
||||
// another thread calls Resume() and suspend_count reaches 0.
|
||||
// Returns the previous suspend_count value.
|
||||
uint32_t SelfSuspend();
|
||||
#endif
|
||||
|
||||
xe::threading::Thread* thread() { return thread_.get(); }
|
||||
|
||||
virtual bool Save(ByteStream* stream) override;
|
||||
@@ -467,6 +478,12 @@ class XThread : public XObject, public cpu::Thread {
|
||||
|
||||
int32_t priority_ = 0;
|
||||
|
||||
#if XE_PLATFORM_LINUX
|
||||
// Condition variable for thread self-suspension.
|
||||
std::mutex suspend_mutex_;
|
||||
std::condition_variable suspend_cv_;
|
||||
#endif
|
||||
|
||||
// Reentry context for setjmp/longjmp based stack unwinding
|
||||
std::jmp_buf reentry_jmp_buf_;
|
||||
uint32_t reentry_address_ = 0;
|
||||
|
||||
Reference in New Issue
Block a user