2023-06-11 12:06:23 +02:00
|
|
|
// Copyright 2023 Dolphin Emulator Project
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
|
|
// 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.
|
2025-05-19 12:08:10 +02:00
|
|
|
// TODO: The above isn't true anymore, so we should get rid of this class.
|
2023-06-11 12:06:23 +02:00
|
|
|
struct HostThreadLock
|
|
|
|
|
{
|
2025-05-19 12:08:10 +02:00
|
|
|
explicit HostThreadLock() : m_lock(s_host_identity_mutex) {}
|
2023-06-11 12:18:16 +02:00
|
|
|
|
2025-05-19 12:08:10 +02:00
|
|
|
~HostThreadLock() = default;
|
2023-06-11 12:18:16 +02:00
|
|
|
|
2023-06-11 12:06:23 +02:00
|
|
|
HostThreadLock(const HostThreadLock& other) = delete;
|
|
|
|
|
HostThreadLock(HostThreadLock&& other) = delete;
|
|
|
|
|
HostThreadLock& operator=(const HostThreadLock& other) = delete;
|
|
|
|
|
HostThreadLock& operator=(HostThreadLock&& other) = delete;
|
2023-06-11 12:18:16 +02:00
|
|
|
|
2025-05-19 12:08:10 +02:00
|
|
|
void Lock() { m_lock.lock(); }
|
|
|
|
|
|
|
|
|
|
void Unlock() { m_lock.unlock(); }
|
2023-06-11 12:18:16 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static std::mutex s_host_identity_mutex;
|
|
|
|
|
std::unique_lock<std::mutex> m_lock;
|
2023-06-11 12:06:23 +02:00
|
|
|
};
|