mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-20 09:55:07 -04:00
ams: support building unit test programs on windows/linux/macos
This commit is contained in:
parent
9a38be201a
commit
64a97576d0
756 changed files with 33359 additions and 9372 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue