ams: support building unit test programs on windows/linux/macos
This commit is contained in:
@@ -21,25 +21,36 @@ namespace ams::sf {
|
||||
|
||||
namespace {
|
||||
|
||||
ALWAYS_INLINE std::atomic<uintptr_t> *GetAtomicSfInlineContext(os::ThreadType *thread) {
|
||||
static_assert(sizeof(thread->atomic_sf_inline_context) >= sizeof(std::atomic<uintptr_t>));
|
||||
return reinterpret_cast<std::atomic<uintptr_t> *>(std::addressof(thread->atomic_sf_inline_context));
|
||||
}
|
||||
#if !defined(ATMOSPHERE_COMPILER_CLANG)
|
||||
ALWAYS_INLINE util::AtomicRef<uintptr_t> GetAtomicSfInlineContext(os::ThreadType *thread = os::GetCurrentThread()) {
|
||||
uintptr_t * const p = std::addressof(os::GetSdkInternalTlsArray(thread)->sf_inline_context);
|
||||
|
||||
ALWAYS_INLINE std::atomic<uintptr_t> *GetAtomicSfInlineContext() {
|
||||
return GetAtomicSfInlineContext(os::GetCurrentThread());
|
||||
return util::AtomicRef<uintptr_t>(*p);
|
||||
}
|
||||
#else
|
||||
ALWAYS_INLINE util::Atomic<uintptr_t> &GetAtomicSfInlineContext(os::ThreadType *thread = os::GetCurrentThread()) {
|
||||
uintptr_t * const p = std::addressof(os::GetSdkInternalTlsArray(thread)->sf_inline_context);
|
||||
static_assert(sizeof(std::atomic<uintptr_t>) == sizeof(uintptr_t));
|
||||
static_assert(sizeof(util::Atomic<uintptr_t>) == sizeof(std::atomic<uintptr_t>));
|
||||
|
||||
return *reinterpret_cast<util::Atomic<uintptr_t> *>(p);
|
||||
}
|
||||
#endif
|
||||
|
||||
ALWAYS_INLINE void OnSetInlineContext(os::ThreadType *thread) {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
/* Ensure that libnx receives the priority value. */
|
||||
::fsSetPriority(static_cast<::FsPriority>(::ams::sf::GetFsInlineContext(thread)));
|
||||
#else
|
||||
AMS_UNUSED(thread);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
InlineContext GetInlineContext() {
|
||||
/* Get the context. */
|
||||
uintptr_t thread_context = GetAtomicSfInlineContext()->load();
|
||||
uintptr_t thread_context = GetAtomicSfInlineContext().Load();
|
||||
|
||||
/* Copy it out. */
|
||||
InlineContext ctx;
|
||||
@@ -59,7 +70,7 @@ namespace ams::sf {
|
||||
std::memcpy(std::addressof(new_context_value), std::addressof(ctx), sizeof(ctx));
|
||||
|
||||
/* Get the old context. */
|
||||
uintptr_t old_context_value = GetAtomicSfInlineContext(cur_thread)->exchange(new_context_value);
|
||||
uintptr_t old_context_value = GetAtomicSfInlineContext(cur_thread).Exchange(new_context_value);
|
||||
|
||||
/* Convert and copy it out. */
|
||||
InlineContext old_ctx;
|
||||
@@ -71,21 +82,32 @@ namespace ams::sf {
|
||||
|
||||
namespace {
|
||||
|
||||
ALWAYS_INLINE std::atomic<u8> *GetAtomicFsInlineContext(os::ThreadType *thread) {
|
||||
static_assert(sizeof(thread->atomic_sf_inline_context) >= sizeof(std::atomic<u8>));
|
||||
return reinterpret_cast<std::atomic<u8> *>(std::addressof(thread->atomic_sf_inline_context));
|
||||
#if !defined(ATMOSPHERE_COMPILER_CLANG)
|
||||
ALWAYS_INLINE util::AtomicRef<u8> GetAtomicFsInlineContext(os::ThreadType *thread) {
|
||||
uintptr_t * const p = std::addressof(os::GetSdkInternalTlsArray(thread)->sf_inline_context);
|
||||
|
||||
return util::AtomicRef<u8>(*reinterpret_cast<u8 *>(p));
|
||||
}
|
||||
#else
|
||||
ALWAYS_INLINE util::Atomic<u8> &GetAtomicFsInlineContext(os::ThreadType *thread) {
|
||||
uintptr_t * const p = std::addressof(os::GetSdkInternalTlsArray(thread)->sf_inline_context);
|
||||
static_assert(sizeof(std::atomic<u8>) == sizeof(u8));
|
||||
static_assert(sizeof(util::Atomic<u8>) == sizeof(std::atomic<u8>));
|
||||
|
||||
return *reinterpret_cast<util::Atomic<u8> *>(reinterpret_cast<u8 *>(p));
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
u8 GetFsInlineContext(os::ThreadType *thread) {
|
||||
return GetAtomicFsInlineContext(thread)->load();
|
||||
return GetAtomicFsInlineContext(thread).Load();
|
||||
}
|
||||
|
||||
u8 SetFsInlineContext(os::ThreadType *thread, u8 ctx) {
|
||||
ON_SCOPE_EXIT { cmif::OnSetInlineContext(thread); };
|
||||
|
||||
return GetAtomicFsInlineContext(thread)->exchange(ctx);
|
||||
return GetAtomicFsInlineContext(thread).Exchange(ctx);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user