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,17 +14,30 @@
* 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 {
void InitializeSdkMutex(SdkMutexType *mutex) {
/* Initialize the critical section. */
GetReference(mutex->_storage).Initialize();
/* 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)
mutex->owner_thread = nullptr;
#endif
}
bool IsSdkMutexLockedByCurrentThread(const SdkMutexType *mutex) {
#if defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
/* Check whether the critical section is held. */
return GetReference(mutex->_storage).IsLockedByCurrentThread();
#else
/* Check if the current thread is owner. */
return mutex->owner_thread == os::impl::GetCurrentThread();
#endif
}
void LockSdkMutex(SdkMutexType *mutex) {
@ -32,7 +45,12 @@ namespace ams::os {
AMS_ABORT_UNLESS(!IsSdkMutexLockedByCurrentThread(mutex));
/* Enter the critical section. */
return GetReference(mutex->_storage).Enter();
GetReference(mutex->_storage).Enter();
/* If necessary, set owner thread. */
#if !defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
mutex->owner_thread = os::impl::GetCurrentThread();
#endif
}
bool TryLockSdkMutex(SdkMutexType *mutex) {
@ -40,15 +58,29 @@ namespace ams::os {
AMS_ABORT_UNLESS(!IsSdkMutexLockedByCurrentThread(mutex));
/* Try to enter the critical section. */
return GetReference(mutex->_storage).TryEnter();
const bool res = GetReference(mutex->_storage).TryEnter();
/* If necessary, set owner thread. */
#if !defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
if (res) {
mutex->owner_thread = os::impl::GetCurrentThread();
}
#endif
return res;
}
void UnlockSdkMutex(SdkMutexType *mutex) {
/* Check pre-conditions. */
AMS_ABORT_UNLESS(IsSdkMutexLockedByCurrentThread(mutex));
/* If necessary, clear owner thread. */
#if !defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
mutex->owner_thread = nullptr;
#endif
/* Leave the critical section. */
return GetReference(mutex->_storage).Leave();
GetReference(mutex->_storage).Leave();
}
}