forked from dolphin-emu/dolphin
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dolphin-emu#11926 from JosJuice/android-host-check
Android: Re-add host thread check
- Loading branch information
Showing
6 changed files
with
92 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright 2023 Dolphin Emulator Project | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#include "jni/Host.h" | ||
|
||
#include <mutex> | ||
|
||
std::mutex HostThreadLock::s_host_identity_mutex; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2023 Dolphin Emulator Project | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#pragma once | ||
|
||
#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. | ||
struct HostThreadLock | ||
{ | ||
public: | ||
explicit HostThreadLock() : m_lock(s_host_identity_mutex) { Core::DeclareAsHostThread(); } | ||
|
||
~HostThreadLock() | ||
{ | ||
if (m_lock.owns_lock()) | ||
Core::UndeclareAsHostThread(); | ||
} | ||
|
||
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 Unlock() | ||
{ | ||
m_lock.unlock(); | ||
Core::UndeclareAsHostThread(); | ||
} | ||
|
||
private: | ||
static std::mutex s_host_identity_mutex; | ||
std::unique_lock<std::mutex> m_lock; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters