mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Merge pull request #13689 from JosJuice/lock-core-any-thread
Core: Let any thread call previously host-thread-only functions
This commit is contained in:
@@ -5,37 +5,24 @@
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "Core/Core.h"
|
||||
|
||||
// The Core only supports using a single Host thread.
|
||||
// If multiple threads want to call host functions then they need to queue
|
||||
// sequentially for access.
|
||||
// TODO: The above isn't true anymore, so we should get rid of this class.
|
||||
struct HostThreadLock
|
||||
{
|
||||
explicit HostThreadLock() : m_lock(s_host_identity_mutex) { Core::DeclareAsHostThread(); }
|
||||
explicit HostThreadLock() : m_lock(s_host_identity_mutex) {}
|
||||
|
||||
~HostThreadLock()
|
||||
{
|
||||
if (m_lock.owns_lock())
|
||||
Core::UndeclareAsHostThread();
|
||||
}
|
||||
~HostThreadLock() = default;
|
||||
|
||||
HostThreadLock(const HostThreadLock& other) = delete;
|
||||
HostThreadLock(HostThreadLock&& other) = delete;
|
||||
HostThreadLock& operator=(const HostThreadLock& other) = delete;
|
||||
HostThreadLock& operator=(HostThreadLock&& other) = delete;
|
||||
|
||||
void Lock()
|
||||
{
|
||||
m_lock.lock();
|
||||
Core::DeclareAsHostThread();
|
||||
}
|
||||
void Lock() { m_lock.lock(); }
|
||||
|
||||
void Unlock()
|
||||
{
|
||||
m_lock.unlock();
|
||||
Core::UndeclareAsHostThread();
|
||||
}
|
||||
void Unlock() { m_lock.unlock(); }
|
||||
|
||||
private:
|
||||
static std::mutex s_host_identity_mutex;
|
||||
|
||||
Reference in New Issue
Block a user