ams: support building unit test programs on windows/linux/macos

This commit is contained in:
Michael Scire 2022-03-06 12:08:20 -08:00 committed by SciresM
parent 9a38be201a
commit 64a97576d0
756 changed files with 33359 additions and 9372 deletions

View file

@ -14,6 +14,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#if !defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
#include "impl/os_thread_manager.hpp"
#endif
namespace ams::os {
@ -23,17 +26,32 @@ namespace ams::os {
/* Set recursive count. */
rmutex->recursive_count = 0;
/* If the underlying critical section can't readily be checked, set owner thread. */
#if !defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
rmutex->owner_thread = nullptr;
#endif
}
bool IsSdkRecursiveMutexLockedByCurrentThread(const SdkRecursiveMutexType *rmutex) {
#if defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
/* Check whether the critical section is held. */
return GetReference(rmutex->_storage).IsLockedByCurrentThread();
#else
/* Check if the current thread is owner. */
return rmutex->owner_thread == os::impl::GetCurrentThread();
#endif
}
void LockSdkRecursiveMutex(SdkRecursiveMutexType *rmutex) {
/* If we don't hold the mutex, enter the critical section. */
if (!IsSdkRecursiveMutexLockedByCurrentThread(rmutex)) {
GetReference(rmutex->_storage).Enter();
/* If necessary, set owner thread. */
#if !defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
rmutex->owner_thread = os::impl::GetCurrentThread();
#endif
}
/* Increment (and check) recursive count. */
@ -47,6 +65,11 @@ namespace ams::os {
if (!GetReference(rmutex->_storage).TryEnter()) {
return false;
}
/* If necessary, set owner thread. */
#if !defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
rmutex->owner_thread = os::impl::GetCurrentThread();
#endif
}
/* Increment (and check) recursive count. */
@ -62,6 +85,11 @@ namespace ams::os {
/* Decrement recursive count, and leave critical section if we no longer hold the mutex. */
if ((--rmutex->recursive_count) == 0) {
/* If necessary, clear owner thread. */
#if !defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
rmutex->owner_thread = nullptr;
#endif
GetReference(rmutex->_storage).Leave();
}
}