Revert "hoc-clk: add live vdd2, live boost clock and basic pwm dimming"
This reverts commit 15b7df8ef1.
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
#include <stratosphere/os/impl/os_internal_busy_mutex_impl.os.horizon.hpp>
|
||||
#elif defined(ATMOSPHERE_OS_WINDOWS) || defined(ATMOSPHERE_OS_LINUX) || defined(ATMOSPHERE_OS_MACOS)
|
||||
#include <stratosphere/os/impl/os_internal_busy_mutex_impl.os.generic.hpp>
|
||||
#else
|
||||
#error "Unknown OS for ams::os::impl::InternalBusyMutexImpl"
|
||||
#endif
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class InternalBusyMutex {
|
||||
private:
|
||||
InternalBusyMutexImpl m_impl;
|
||||
public:
|
||||
constexpr InternalBusyMutex() : m_impl() { /* ... */ }
|
||||
|
||||
ALWAYS_INLINE void Initialize() { m_impl.Initialize(); }
|
||||
ALWAYS_INLINE void Finalize() { m_impl.Finalize(); }
|
||||
|
||||
ALWAYS_INLINE bool IsLocked() const { return m_impl.IsLocked(); }
|
||||
|
||||
ALWAYS_INLINE void Lock() { return m_impl.Lock(); }
|
||||
ALWAYS_INLINE bool TryLock() { return m_impl.TryLock(); }
|
||||
ALWAYS_INLINE void Unlock() { return m_impl.Unlock(); }
|
||||
|
||||
ALWAYS_INLINE void lock() { return this->Lock(); }
|
||||
ALWAYS_INLINE bool try_lock() { return this->TryLock(); }
|
||||
ALWAYS_INLINE void unlock() { return this->Unlock(); }
|
||||
};
|
||||
|
||||
using InternalBusyMutexStorage = util::TypedStorage<InternalBusyMutex>;
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
|
||||
class InternalBusyMutexImpl {
|
||||
private:
|
||||
std::atomic<bool> m_value{false};
|
||||
u8 m_padding[3]{};
|
||||
public:
|
||||
constexpr InternalBusyMutexImpl() = default;
|
||||
|
||||
ALWAYS_INLINE void Initialize() { m_value.store(false, std::memory_order_relaxed); }
|
||||
|
||||
ALWAYS_INLINE void Finalize() { /* ... */ }
|
||||
|
||||
ALWAYS_INLINE bool IsLocked() const { return m_value.load(std::memory_order_acquire); }
|
||||
|
||||
ALWAYS_INLINE bool TryLock() {
|
||||
bool expected = false;
|
||||
return m_value.compare_exchange_weak(expected, true, std::memory_order_acquire, std::memory_order_acquire);
|
||||
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void Lock() {
|
||||
while (!this->TryLock()) {
|
||||
#if defined(ATMOSPHERE_ARCH_X64) || defined(ATMOSPHERE_ARCH_X86)
|
||||
_mm_pause();
|
||||
#elif defined(ATMOSPHERE_ARCH_ARM64) || defined(ATMOSPHERE_ARCH_ARM)
|
||||
__asm__ __volatile__("yield" ::: "memory");
|
||||
#else
|
||||
#error "InternalBusyMutex requires yield intrinsics"
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void Unlock() {
|
||||
m_value.store(false, std::memory_order_release);
|
||||
}
|
||||
};
|
||||
static_assert(sizeof(InternalBusyMutexImpl) == sizeof(u32));
|
||||
|
||||
#define AMS_OS_INTERNAL_BUSY_MUTEX_IMPL_CONSTANT_INITIALIZE_ARRAY_VALUES 0
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class InternalBusyMutexImpl {
|
||||
private:
|
||||
u32 m_value;
|
||||
public:
|
||||
constexpr InternalBusyMutexImpl() : m_value(0) { /* ... */ }
|
||||
|
||||
constexpr void Initialize() { m_value = 0; }
|
||||
constexpr void Finalize() { /* ... */ }
|
||||
|
||||
constexpr bool IsLocked() const { return m_value != 0; }
|
||||
|
||||
void Lock();
|
||||
bool TryLock();
|
||||
void Unlock();
|
||||
};
|
||||
|
||||
#define AMS_OS_INTERNAL_BUSY_MUTEX_IMPL_CONSTANT_INITIALIZE_ARRAY_VALUES 0
|
||||
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_condition_variable_common.hpp>
|
||||
|
||||
#if defined(AMS_OS_IMPL_USE_PTHREADS)
|
||||
#include <stratosphere/os/impl/os_internal_condition_variable_impl.pthread.hpp>
|
||||
#elif defined(ATMOSPHERE_OS_HORIZON)
|
||||
#include <stratosphere/os/impl/os_internal_condition_variable_impl.os.horizon.hpp>
|
||||
#elif defined(ATMOSPHERE_OS_WINDOWS)
|
||||
#include <stratosphere/os/impl/os_internal_condition_variable_impl.os.windows.hpp>
|
||||
#else
|
||||
#error "Unknown OS for ams::os::impl::InternalConditionVariableImpl"
|
||||
#endif
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class InternalConditionVariable {
|
||||
private:
|
||||
InternalConditionVariableImpl m_impl;
|
||||
public:
|
||||
constexpr InternalConditionVariable() : m_impl() { /* ... */ }
|
||||
|
||||
void Initialize() {
|
||||
m_impl.Initialize();
|
||||
}
|
||||
|
||||
void Finalize() {
|
||||
m_impl.Finalize();
|
||||
}
|
||||
|
||||
void Signal() {
|
||||
m_impl.Signal();
|
||||
}
|
||||
|
||||
void Broadcast() {
|
||||
m_impl.Broadcast();
|
||||
}
|
||||
|
||||
void Wait(InternalCriticalSection *cs) {
|
||||
m_impl.Wait(cs);
|
||||
}
|
||||
|
||||
ConditionVariableStatus TimedWait(InternalCriticalSection *cs, const TimeoutHelper &timeout_helper) {
|
||||
return m_impl.TimedWait(cs, timeout_helper);
|
||||
}
|
||||
};
|
||||
|
||||
using InternalConditionVariableStorage = util::TypedStorage<InternalConditionVariable>;
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_condition_variable_common.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class TimeoutHelper;
|
||||
|
||||
class InternalConditionVariableImpl {
|
||||
private:
|
||||
u32 m_value;
|
||||
public:
|
||||
constexpr InternalConditionVariableImpl() : m_value(0) { /* ... */ }
|
||||
|
||||
constexpr void Initialize() {
|
||||
m_value = 0;
|
||||
}
|
||||
constexpr void Finalize() { /* ... */ }
|
||||
|
||||
void Signal();
|
||||
void Broadcast();
|
||||
|
||||
void Wait(InternalCriticalSection *cs);
|
||||
ConditionVariableStatus TimedWait(InternalCriticalSection *cs, const TimeoutHelper &timeout_helper);
|
||||
};
|
||||
|
||||
using InternalConditionVariableStorageTypeForConstantInitialize = u32;
|
||||
|
||||
#define AMS_OS_INTERNAL_CONDITION_VARIABLE_IMPL_CONSTANT_INITIALIZER {0}
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_condition_variable_common.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class TimeoutHelper;
|
||||
|
||||
struct WindowsConditionVariable;
|
||||
|
||||
using WindowsConditionVariableStorage = util::TypedStorage<WindowsConditionVariable, sizeof(void *), alignof(void *)>;
|
||||
|
||||
#if defined(ATMOSPHERE_ARCH_X64)
|
||||
#define AMS_OS_WINDOWS_CONDITION_VARIABLE_CONSTANT_INITIALIZE_ARRAY_VALUES 0, 0
|
||||
#elif defined(ATMOSPHERE_ARCH_X86)
|
||||
#define AMS_OS_WINDOWS_CONDITION_VARIABLE_CONSTANT_INITIALIZE_ARRAY_VALUES 0
|
||||
#else
|
||||
#error "Unknown architecture for WindowsConditionVariable initializer"
|
||||
#endif
|
||||
|
||||
class InternalConditionVariableImpl {
|
||||
private:
|
||||
u32 m_value;
|
||||
public:
|
||||
union {
|
||||
s32 _arr[sizeof(WindowsConditionVariableStorage) / sizeof(s32)];
|
||||
WindowsConditionVariableStorage m_windows_cv_storage;
|
||||
};
|
||||
constexpr InternalConditionVariableImpl() : _arr{AMS_OS_WINDOWS_CONDITION_VARIABLE_CONSTANT_INITIALIZE_ARRAY_VALUES} { /* ... */ }
|
||||
constexpr ~InternalConditionVariableImpl() {
|
||||
if (!std::is_constant_evaluated()) {
|
||||
this->Finalize();
|
||||
}
|
||||
}
|
||||
|
||||
void Initialize();
|
||||
void Finalize();
|
||||
|
||||
void Signal();
|
||||
void Broadcast();
|
||||
|
||||
void Wait(InternalCriticalSection *cs);
|
||||
ConditionVariableStatus TimedWait(InternalCriticalSection *cs, const TimeoutHelper &timeout_helper);
|
||||
};
|
||||
|
||||
struct InternalConditionVariableStorageTypeForConstantInitialize { s32 _arr[sizeof(WindowsConditionVariableStorage) / sizeof(s32)]; };
|
||||
|
||||
#define AMS_OS_INTERNAL_CONDITION_VARIABLE_IMPL_CONSTANT_INITIALIZER { AMS_OS_WINDOWS_CONDITION_VARIABLE_CONSTANT_INITIALIZE_ARRAY_VALUES }
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_condition_variable_common.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class TimeoutHelper;
|
||||
|
||||
class InternalConditionVariableImpl {
|
||||
private:
|
||||
pthread_cond_t m_pthread_cond = PTHREAD_COND_INITIALIZER;
|
||||
public:
|
||||
constexpr InternalConditionVariableImpl() = default;
|
||||
|
||||
constexpr ~InternalConditionVariableImpl() {
|
||||
if (!std::is_constant_evaluated()) {
|
||||
this->Finalize();
|
||||
}
|
||||
}
|
||||
|
||||
void Initialize();
|
||||
void Finalize();
|
||||
|
||||
void Signal();
|
||||
void Broadcast();
|
||||
|
||||
void Wait(InternalCriticalSection *cs);
|
||||
ConditionVariableStatus TimedWait(InternalCriticalSection *cs, const TimeoutHelper &timeout_helper);
|
||||
};
|
||||
|
||||
using InternalConditionVariableStorageTypeForConstantInitialize = pthread_cond_t;
|
||||
|
||||
#define AMS_OS_INTERNAL_CONDITION_VARIABLE_IMPL_CONSTANT_INITIALIZER ._storage_for_constant_initialize = PTHREAD_COND_INITIALIZER
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
#if defined(AMS_OS_IMPL_USE_PTHREADS)
|
||||
#include <stratosphere/os/impl/os_internal_critical_section_impl.pthread.hpp>
|
||||
#elif defined(ATMOSPHERE_OS_HORIZON)
|
||||
#include <stratosphere/os/impl/os_internal_critical_section_impl.os.horizon.hpp>
|
||||
#elif defined(ATMOSPHERE_OS_WINDOWS)
|
||||
#include <stratosphere/os/impl/os_internal_critical_section_impl.os.windows.hpp>
|
||||
#else
|
||||
#error "Unknown OS for ams::os::impl::InternalCriticalSectionImpl"
|
||||
#endif
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class InternalCriticalSection {
|
||||
private:
|
||||
InternalCriticalSectionImpl m_impl;
|
||||
public:
|
||||
constexpr InternalCriticalSection() : m_impl() { /* ... */ }
|
||||
|
||||
void Initialize() { m_impl.Initialize(); }
|
||||
void Finalize() { m_impl.Finalize(); }
|
||||
|
||||
void Enter() { return m_impl.Enter(); }
|
||||
bool TryEnter() { return m_impl.TryEnter(); }
|
||||
void Leave() { return m_impl.Leave(); }
|
||||
|
||||
#if defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
|
||||
bool IsLockedByCurrentThread() const { return m_impl.IsLockedByCurrentThread(); }
|
||||
#endif
|
||||
|
||||
ALWAYS_INLINE void Lock() { return this->Enter(); }
|
||||
ALWAYS_INLINE bool TryLock() { return this->TryEnter(); }
|
||||
ALWAYS_INLINE void Unlock() { return this->Leave(); }
|
||||
|
||||
ALWAYS_INLINE void lock() { return this->Lock(); }
|
||||
ALWAYS_INLINE bool try_lock() { return this->TryLock(); }
|
||||
ALWAYS_INLINE void unlock() { return this->Unlock(); }
|
||||
|
||||
InternalCriticalSectionImpl *Get() {
|
||||
return std::addressof(m_impl);
|
||||
}
|
||||
|
||||
const InternalCriticalSectionImpl *Get() const {
|
||||
return std::addressof(m_impl);
|
||||
}
|
||||
};
|
||||
|
||||
using InternalCriticalSectionStorage = util::TypedStorage<InternalCriticalSection>;
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
class ReaderWriterLockHorizonImpl;
|
||||
#endif
|
||||
|
||||
class InternalConditionVariableImpl;
|
||||
|
||||
class InternalCriticalSectionImpl {
|
||||
private:
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
friend class ReaderWriterLockHorizonImpl;
|
||||
#endif
|
||||
|
||||
friend class InternalConditionVariableImpl;
|
||||
private:
|
||||
u32 m_thread_handle;
|
||||
public:
|
||||
constexpr InternalCriticalSectionImpl() : m_thread_handle(svc::InvalidHandle) { /* ... */ }
|
||||
|
||||
constexpr void Initialize() { m_thread_handle = svc::InvalidHandle; }
|
||||
constexpr void Finalize() { /* ... */ }
|
||||
|
||||
void Enter();
|
||||
bool TryEnter();
|
||||
void Leave();
|
||||
|
||||
bool IsLockedByCurrentThread() const;
|
||||
|
||||
ALWAYS_INLINE void Lock() { return this->Enter(); }
|
||||
ALWAYS_INLINE bool TryLock() { return this->TryEnter(); }
|
||||
ALWAYS_INLINE void Unlock() { return this->Leave(); }
|
||||
|
||||
ALWAYS_INLINE void lock() { return this->Lock(); }
|
||||
ALWAYS_INLINE bool try_lock() { return this->TryLock(); }
|
||||
ALWAYS_INLINE void unlock() { return this->Unlock(); }
|
||||
};
|
||||
|
||||
using InternalCriticalSectionStorageTypeForConstantInitialize = u32;
|
||||
|
||||
#define AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CONSTANT_INITIALIZER {0}
|
||||
|
||||
#define AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class InternalConditionVariableImpl;
|
||||
|
||||
struct WindowsCriticalSection;
|
||||
|
||||
using WindowsCriticalSectionStorage = util::TypedStorage<WindowsCriticalSection, 8 + 4 * sizeof(void *), alignof(void *)>;
|
||||
|
||||
#if defined(ATMOSPHERE_ARCH_X64)
|
||||
#define AMS_OS_WINDOWS_CRITICAL_SECTION_CONSTANT_INITIALIZE_ARRAY_VALUES -1, -1, -1, 0, 0, 0, 0, 0, 0, 0
|
||||
#elif defined(ATMOSPHERE_ARCH_X86)
|
||||
#define AMS_OS_WINDOWS_CRITICAL_SECTION_CONSTANT_INITIALIZE_ARRAY_VALUES -1, -1, 0, 0, 0, 0
|
||||
#else
|
||||
#error "Unknown architecture for WindowsCriticalSection initializer"
|
||||
#endif
|
||||
|
||||
class InternalCriticalSectionImpl {
|
||||
private:
|
||||
friend class InternalConditionVariableImpl;
|
||||
private:
|
||||
union {
|
||||
s32 _arr[sizeof(WindowsCriticalSectionStorage) / sizeof(s32)];
|
||||
WindowsCriticalSectionStorage m_windows_critical_section_storage;
|
||||
};
|
||||
public:
|
||||
constexpr InternalCriticalSectionImpl() : _arr{AMS_OS_WINDOWS_CRITICAL_SECTION_CONSTANT_INITIALIZE_ARRAY_VALUES} { /* ... */ }
|
||||
constexpr ~InternalCriticalSectionImpl() {
|
||||
if (!std::is_constant_evaluated()) {
|
||||
this->Finalize();
|
||||
}
|
||||
}
|
||||
|
||||
void Initialize();
|
||||
void Finalize();
|
||||
|
||||
void Enter();
|
||||
bool TryEnter();
|
||||
void Leave();
|
||||
|
||||
bool IsLockedByCurrentThread() const;
|
||||
|
||||
ALWAYS_INLINE void Lock() { return this->Enter(); }
|
||||
ALWAYS_INLINE bool TryLock() { return this->TryEnter(); }
|
||||
ALWAYS_INLINE void Unlock() { return this->Leave(); }
|
||||
|
||||
ALWAYS_INLINE void lock() { return this->Lock(); }
|
||||
ALWAYS_INLINE bool try_lock() { return this->TryLock(); }
|
||||
ALWAYS_INLINE void unlock() { return this->Unlock(); }
|
||||
};
|
||||
|
||||
struct InternalCriticalSectionStorageTypeForConstantInitialize { s32 _arr[sizeof(WindowsCriticalSectionStorage) / sizeof(s32)]; };
|
||||
|
||||
#define AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CONSTANT_INITIALIZER { AMS_OS_WINDOWS_CRITICAL_SECTION_CONSTANT_INITIALIZE_ARRAY_VALUES }
|
||||
|
||||
#define AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD
|
||||
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_common_types.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class InternalConditionVariableImpl;
|
||||
|
||||
/* NOTE: macOS (and possibly other targets) do not provide adaptive mutex. */
|
||||
#if defined(PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP)
|
||||
#define AMS_OS_IMPL_PTHREAD_MUTEX_INITIALIZER PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
|
||||
#else
|
||||
#define AMS_OS_IMPL_PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
||||
#endif
|
||||
|
||||
#if defined(ATMOSPHERE_OS_LINUX)
|
||||
#define AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD
|
||||
#else
|
||||
//#define AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD
|
||||
#endif
|
||||
|
||||
class InternalCriticalSectionImpl {
|
||||
private:
|
||||
friend class InternalConditionVariableImpl;
|
||||
private:
|
||||
pthread_mutex_t m_pthread_mutex = AMS_OS_IMPL_PTHREAD_MUTEX_INITIALIZER;
|
||||
public:
|
||||
constexpr InternalCriticalSectionImpl() = default;
|
||||
constexpr ~InternalCriticalSectionImpl() {
|
||||
if (!std::is_constant_evaluated()) {
|
||||
this->Finalize();
|
||||
}
|
||||
}
|
||||
|
||||
void Initialize();
|
||||
void Finalize();
|
||||
|
||||
void Enter();
|
||||
bool TryEnter();
|
||||
void Leave();
|
||||
|
||||
#if defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
|
||||
bool IsLockedByCurrentThread() const;
|
||||
#endif
|
||||
|
||||
ALWAYS_INLINE void Lock() { return this->Enter(); }
|
||||
ALWAYS_INLINE bool TryLock() { return this->TryEnter(); }
|
||||
ALWAYS_INLINE void Unlock() { return this->Leave(); }
|
||||
|
||||
ALWAYS_INLINE void lock() { return this->Lock(); }
|
||||
ALWAYS_INLINE bool try_lock() { return this->TryLock(); }
|
||||
ALWAYS_INLINE void unlock() { return this->Unlock(); }
|
||||
};
|
||||
|
||||
using InternalCriticalSectionStorageTypeForConstantInitialize = pthread_mutex_t;
|
||||
|
||||
#define AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CONSTANT_INITIALIZER ._storage_for_constant_initialize = AMS_OS_IMPL_PTHREAD_MUTEX_INITIALIZER
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
#include <stratosphere/os/impl/os_internal_light_event_impl.os.horizon.hpp>
|
||||
#elif defined(ATMOSPHERE_OS_WINDOWS) || defined(ATMOSPHERE_OS_LINUX) || defined(ATMOSPHERE_OS_MACOS)
|
||||
#include <stratosphere/os/impl/os_internal_light_event_impl.os.generic.hpp>
|
||||
#else
|
||||
#error "Unknown OS for ams::os::impl::InternalLightEventImpl"
|
||||
#endif
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class InternalLightEvent {
|
||||
private:
|
||||
InternalLightEventImpl m_impl;
|
||||
public:
|
||||
explicit InternalLightEvent(bool signaled) : m_impl(signaled) { /* ... */ }
|
||||
|
||||
ALWAYS_INLINE void SignalWithAutoClear() { return m_impl.SignalWithAutoClear(); }
|
||||
ALWAYS_INLINE void SignalWithManualClear() { return m_impl.SignalWithManualClear(); }
|
||||
|
||||
ALWAYS_INLINE void Clear() { return m_impl.Clear(); }
|
||||
|
||||
ALWAYS_INLINE void WaitWithAutoClear() { return m_impl.WaitWithAutoClear(); }
|
||||
ALWAYS_INLINE void WaitWithManualClear() { return m_impl.WaitWithManualClear(); }
|
||||
|
||||
ALWAYS_INLINE bool TryWaitWithAutoClear() { return m_impl.TryWaitWithAutoClear(); }
|
||||
ALWAYS_INLINE bool TryWaitWithManualClear() { return m_impl.TryWaitWithManualClear(); }
|
||||
|
||||
ALWAYS_INLINE bool TimedWaitWithAutoClear(const TimeoutHelper &timeout_helper) { return m_impl.TimedWaitWithAutoClear(timeout_helper); }
|
||||
ALWAYS_INLINE bool TimedWaitWithManualClear(const TimeoutHelper &timeout_helper) { return m_impl.TimedWaitWithManualClear(timeout_helper); }
|
||||
};
|
||||
|
||||
using InternalLightEventStorage = util::TypedStorage<InternalLightEvent>;
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_condition_variable.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class TimeoutHelper;
|
||||
|
||||
class InternalLightEventImpl {
|
||||
private:
|
||||
u16 m_counter_low;
|
||||
u8 m_counter_high;
|
||||
std::atomic<u8> m_signal_state;
|
||||
InternalCriticalSection m_cs;
|
||||
InternalConditionVariable m_cv;
|
||||
public:
|
||||
explicit InternalLightEventImpl(bool signaled) { this->Initialize(signaled); }
|
||||
~InternalLightEventImpl() { this->Finalize(); }
|
||||
|
||||
void Initialize(bool signaled);
|
||||
void Finalize();
|
||||
|
||||
void SignalWithAutoClear();
|
||||
void SignalWithManualClear();
|
||||
|
||||
void Clear();
|
||||
|
||||
void WaitWithAutoClear();
|
||||
void WaitWithManualClear();
|
||||
|
||||
bool TryWaitWithAutoClear();
|
||||
bool TryWaitWithManualClear();
|
||||
|
||||
bool TimedWaitWithAutoClear(const TimeoutHelper &timeout_helper);
|
||||
bool TimedWaitWithManualClear(const TimeoutHelper &timeout_helper);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class TimeoutHelper;
|
||||
|
||||
class InternalLightEventImpl {
|
||||
private:
|
||||
std::atomic<s32> m_state;
|
||||
u32 m_padding;
|
||||
public:
|
||||
explicit InternalLightEventImpl(bool signaled) { this->Initialize(signaled); }
|
||||
~InternalLightEventImpl() { this->Finalize(); }
|
||||
|
||||
void Initialize(bool signaled);
|
||||
void Finalize();
|
||||
|
||||
void SignalWithAutoClear();
|
||||
void SignalWithManualClear();
|
||||
|
||||
void Clear();
|
||||
|
||||
void WaitWithAutoClear();
|
||||
void WaitWithManualClear();
|
||||
|
||||
bool TryWaitWithAutoClear();
|
||||
bool TryWaitWithManualClear();
|
||||
|
||||
bool TimedWaitWithAutoClear(const TimeoutHelper &timeout_helper);
|
||||
bool TimedWaitWithManualClear(const TimeoutHelper &timeout_helper);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_impl.os.horizon.hpp>
|
||||
#elif defined(ATMOSPHERE_OS_WINDOWS)
|
||||
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_impl.os.windows.hpp>
|
||||
#elif defined(ATMOSPHERE_OS_LINUX)
|
||||
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_impl.os.linux.hpp>
|
||||
#elif defined(ATMOSPHERE_OS_MACOS)
|
||||
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_impl.os.macos.hpp>
|
||||
#else
|
||||
#error "Unknown OS for ams::os::impl::InternalReaderWriterBusyMutexImpl"
|
||||
#endif
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class InternalReaderWriterBusyMutex {
|
||||
private:
|
||||
InternalReaderWriterBusyMutexImpl m_impl;
|
||||
public:
|
||||
constexpr InternalReaderWriterBusyMutex() : m_impl() { /* ... */ }
|
||||
|
||||
ALWAYS_INLINE void AcquireReadLock() { return m_impl.AcquireReadLock(); }
|
||||
ALWAYS_INLINE void ReleaseReadLock() { return m_impl.ReleaseReadLock(); }
|
||||
|
||||
ALWAYS_INLINE void AcquireWriteLock() { return m_impl.AcquireWriteLock(); }
|
||||
ALWAYS_INLINE void ReleaseWriteLock() { return m_impl.ReleaseWriteLock(); }
|
||||
};
|
||||
|
||||
using InternalReaderWriterBusyMutexStorage = util::TypedStorage<InternalReaderWriterBusyMutex>;
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_value.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class InternalReaderWriterBusyMutexImpl {
|
||||
private:
|
||||
u32 m_value;
|
||||
public:
|
||||
constexpr InternalReaderWriterBusyMutexImpl() : m_value(0) { /* ... */ }
|
||||
|
||||
constexpr void Initialize() { m_value = 0; }
|
||||
|
||||
void AcquireReadLock();
|
||||
void ReleaseReadLock();
|
||||
|
||||
void AcquireWriteLock();
|
||||
void ReleaseWriteLock();
|
||||
};
|
||||
|
||||
#define AMS_OS_INTERNAL_READER_WRITER_BUSY_MUTEX_IMPL_CONSTANT_INITIALIZER {0}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_value.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
/* NOTE: The current implementation is based on load/linked store conditional, we should figure out how to do this on x64. */
|
||||
|
||||
class InternalReaderWriterBusyMutexImpl {
|
||||
private:
|
||||
u32 m_value;
|
||||
public:
|
||||
constexpr InternalReaderWriterBusyMutexImpl() : m_value(0) { if (!std::is_constant_evaluated()) { AMS_ABORT("TODO: Linux InternalReaderWriterBusyMutexImpl"); } }
|
||||
|
||||
constexpr void Initialize() { m_value = 0; if (!std::is_constant_evaluated()) { AMS_ABORT("TODO: Linux InternalReaderWriterBusyMutexImpl"); } }
|
||||
|
||||
void AcquireReadLock() { AMS_ABORT("TODO: Linux InternalReaderWriterBusyMutexImpl"); }
|
||||
void ReleaseReadLock() { AMS_ABORT("TODO: Linux InternalReaderWriterBusyMutexImpl"); }
|
||||
|
||||
void AcquireWriteLock() { AMS_ABORT("TODO: Linux InternalReaderWriterBusyMutexImpl"); }
|
||||
void ReleaseWriteLock() { AMS_ABORT("TODO: Linux InternalReaderWriterBusyMutexImpl"); }
|
||||
};
|
||||
|
||||
#define AMS_OS_INTERNAL_READER_WRITER_BUSY_MUTEX_IMPL_CONSTANT_INITIALIZER {0}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_value.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
/* NOTE: The current implementation is based on load/linked store conditional, we should figure out how to do this on x64. */
|
||||
|
||||
class InternalReaderWriterBusyMutexImpl {
|
||||
private:
|
||||
u32 m_value;
|
||||
public:
|
||||
constexpr InternalReaderWriterBusyMutexImpl() : m_value(0) { if (!std::is_constant_evaluated()) { AMS_ABORT("TODO: macOS InternalReaderWriterBusyMutexImpl"); } }
|
||||
|
||||
constexpr void Initialize() { m_value = 0; if (!std::is_constant_evaluated()) { AMS_ABORT("TODO: macOS InternalReaderWriterBusyMutexImpl"); } }
|
||||
|
||||
void AcquireReadLock() { AMS_ABORT("TODO: macOS InternalReaderWriterBusyMutexImpl"); }
|
||||
void ReleaseReadLock() { AMS_ABORT("TODO: macOS InternalReaderWriterBusyMutexImpl"); }
|
||||
|
||||
void AcquireWriteLock() { AMS_ABORT("TODO: macOS InternalReaderWriterBusyMutexImpl"); }
|
||||
void ReleaseWriteLock() { AMS_ABORT("TODO: macOS InternalReaderWriterBusyMutexImpl"); }
|
||||
};
|
||||
|
||||
#define AMS_OS_INTERNAL_READER_WRITER_BUSY_MUTEX_IMPL_CONSTANT_INITIALIZER {0}
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_value.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
/* NOTE: The current implementation is based on load/linked store conditional, we should figure out how to do this on x64. */
|
||||
/* We could also consider using https://docs.microsoft.com/en-us/windows/win32/sync/slim-reader-writer--srw--locks */
|
||||
|
||||
class InternalReaderWriterBusyMutexImpl {
|
||||
private:
|
||||
u32 m_value;
|
||||
public:
|
||||
constexpr InternalReaderWriterBusyMutexImpl() : m_value(0) { if (!std::is_constant_evaluated()) { AMS_ABORT("TODO: Windows InternalReaderWriterBusyMutexImpl"); } }
|
||||
|
||||
constexpr void Initialize() { m_value = 0; if (!std::is_constant_evaluated()) { AMS_ABORT("TODO: Windows InternalReaderWriterBusyMutexImpl"); } }
|
||||
|
||||
void AcquireReadLock() { AMS_ABORT("TODO: Windows InternalReaderWriterBusyMutexImpl"); }
|
||||
void ReleaseReadLock() { AMS_ABORT("TODO: Windows InternalReaderWriterBusyMutexImpl"); }
|
||||
|
||||
void AcquireWriteLock() { AMS_ABORT("TODO: Windows InternalReaderWriterBusyMutexImpl"); }
|
||||
void ReleaseWriteLock() { AMS_ABORT("TODO: Windows InternalReaderWriterBusyMutexImpl"); }
|
||||
};
|
||||
|
||||
#define AMS_OS_INTERNAL_READER_WRITER_BUSY_MUTEX_IMPL_CONSTANT_INITIALIZER {0}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON) || defined(ATMOSPHERE_OS_WINDOWS) || defined(ATMOSPHERE_OS_LINUX) || defined(ATMOSPHERE_OS_MACOS)
|
||||
class InternalReaderWriterBusyMutexValue {
|
||||
public:
|
||||
static constexpr inline u8 WriterCountMax = std::numeric_limits<u8>::max();
|
||||
|
||||
static constexpr ALWAYS_INLINE u16 GetReaderCount(u32 v) {
|
||||
return static_cast<u16>(v >> 0);
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE u8 GetWriterCurrent(u32 v) {
|
||||
return static_cast<u8>(v >> 16);
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE u8 GetWriterNext(u32 v) {
|
||||
return static_cast<u8>(v >> 24);
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE u32 IncrementWriterNext(u32 v) {
|
||||
return v + (1u << 24);
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE bool IsWriteLocked(u32 v) {
|
||||
return GetWriterCurrent(v) != GetWriterNext(v);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE u8 *GetWriterCurrentPointer(u32 *p) {
|
||||
if constexpr (util::IsLittleEndian()) {
|
||||
return reinterpret_cast<u8 *>(reinterpret_cast<uintptr_t>(p)) + 2;
|
||||
} else {
|
||||
return reinterpret_cast<u8 *>(reinterpret_cast<uintptr_t>(p)) + 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
#else
|
||||
#error "Unknown OS for ams::os::impl::InternalReaderWriterBusyMutexValue"
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#if defined(ATMOSPHERE_ARCH_X64)
|
||||
#include <xmmintrin.h>
|
||||
#include <emmintrin.h>
|
||||
#endif
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
#if defined(ATMOSPHERE_ARCH_X64)
|
||||
|
||||
ALWAYS_INLINE void FenceMemoryStoreStore() { __asm__ __volatile__("" ::: "memory"); _mm_sfence(); }
|
||||
ALWAYS_INLINE void FenceMemoryStoreLoad() { __asm__ __volatile__("" ::: "memory"); _mm_mfence(); }
|
||||
ALWAYS_INLINE void FenceMemoryStoreAny() { __asm__ __volatile__("" ::: "memory"); _mm_mfence(); }
|
||||
|
||||
ALWAYS_INLINE void FenceMemoryLoadStore() { __asm__ __volatile__("" ::: "memory"); _mm_mfence(); }
|
||||
ALWAYS_INLINE void FenceMemoryLoadLoad() { __asm__ __volatile__("" ::: "memory"); _mm_lfence(); }
|
||||
ALWAYS_INLINE void FenceMemoryLoadAny() { __asm__ __volatile__("" ::: "memory"); _mm_mfence(); }
|
||||
|
||||
ALWAYS_INLINE void FenceMemoryAnyStore() { __asm__ __volatile__("" ::: "memory"); _mm_mfence(); }
|
||||
ALWAYS_INLINE void FenceMemoryAnyLoad() { __asm__ __volatile__("" ::: "memory"); _mm_mfence(); }
|
||||
ALWAYS_INLINE void FenceMemoryAnyAny() {__asm__ __volatile__("" ::: "memory"); _mm_mfence(); }
|
||||
|
||||
#elif defined(ATMOSPHERE_ARCH_ARM64)
|
||||
|
||||
ALWAYS_INLINE void FenceMemoryStoreStore() { __asm__ __volatile__("dmb ishst" ::: "memory"); }
|
||||
ALWAYS_INLINE void FenceMemoryStoreLoad() { __asm__ __volatile__("dmb ish" ::: "memory"); }
|
||||
ALWAYS_INLINE void FenceMemoryStoreAny() { __asm__ __volatile__("dmb ish" ::: "memory"); }
|
||||
|
||||
ALWAYS_INLINE void FenceMemoryLoadStore() { __asm__ __volatile__("dmb ishld" ::: "memory"); }
|
||||
ALWAYS_INLINE void FenceMemoryLoadLoad() { __asm__ __volatile__("dmb ishld" ::: "memory"); }
|
||||
ALWAYS_INLINE void FenceMemoryLoadAny() { __asm__ __volatile__("dmb ishld" ::: "memory"); }
|
||||
|
||||
ALWAYS_INLINE void FenceMemoryAnyStore() { __asm__ __volatile__("dmb ish" ::: "memory"); }
|
||||
ALWAYS_INLINE void FenceMemoryAnyLoad() { __asm__ __volatile__("dmb ish" ::: "memory"); }
|
||||
ALWAYS_INLINE void FenceMemoryAnyAny() { __asm__ __volatile__("dmb ish" ::: "memory"); }
|
||||
|
||||
#else
|
||||
|
||||
#error "Unknown architecture for os::impl::FenceMemory* (Generic)"
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
#if defined(ATMOSPHERE_ARCH_ARM64)
|
||||
|
||||
ALWAYS_INLINE void FenceMemoryStoreStore() { __asm__ __volatile__("dmb ishst" ::: "memory"); }
|
||||
ALWAYS_INLINE void FenceMemoryStoreLoad() { __asm__ __volatile__("dmb ish" ::: "memory"); }
|
||||
ALWAYS_INLINE void FenceMemoryStoreAny() { __asm__ __volatile__("dmb ish" ::: "memory"); }
|
||||
|
||||
ALWAYS_INLINE void FenceMemoryLoadStore() { __asm__ __volatile__("dmb ishld" ::: "memory"); }
|
||||
ALWAYS_INLINE void FenceMemoryLoadLoad() { __asm__ __volatile__("dmb ishld" ::: "memory"); }
|
||||
ALWAYS_INLINE void FenceMemoryLoadAny() { __asm__ __volatile__("dmb ishld" ::: "memory"); }
|
||||
|
||||
ALWAYS_INLINE void FenceMemoryAnyStore() { __asm__ __volatile__("dmb ish" ::: "memory"); }
|
||||
ALWAYS_INLINE void FenceMemoryAnyLoad() { __asm__ __volatile__("dmb ish" ::: "memory"); }
|
||||
ALWAYS_INLINE void FenceMemoryAnyAny() { __asm__ __volatile__("dmb ish" ::: "memory"); }
|
||||
|
||||
#else
|
||||
|
||||
#error "Unknown architecture for os::impl::FenceMemory* (Horizon)"
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
int GetHostArgc();
|
||||
char **GetHostArgv();
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_barrier_types.hpp>
|
||||
#include <stratosphere/os/os_barrier_api.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class Barrier {
|
||||
NON_COPYABLE(Barrier);
|
||||
NON_MOVEABLE(Barrier);
|
||||
private:
|
||||
BarrierType m_barrier;
|
||||
public:
|
||||
explicit Barrier(int num_threads) {
|
||||
InitializeBarrier(std::addressof(m_barrier), num_threads);
|
||||
}
|
||||
|
||||
~Barrier() {
|
||||
FinalizeBarrier(std::addressof(m_barrier));
|
||||
}
|
||||
|
||||
void Await() {
|
||||
return AwaitBarrier(std::addressof(m_barrier));
|
||||
}
|
||||
|
||||
operator BarrierType &() {
|
||||
return m_barrier;
|
||||
}
|
||||
|
||||
operator const BarrierType &() const {
|
||||
return m_barrier;
|
||||
}
|
||||
|
||||
BarrierType *GetBase() {
|
||||
return std::addressof(m_barrier);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct BarrierType;
|
||||
|
||||
void InitializeBarrier(BarrierType *barrier, int num_threads);
|
||||
void FinalizeBarrier(BarrierType *barrier);
|
||||
|
||||
void AwaitBarrier(BarrierType *barrier);
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_condition_variable.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct BarrierType {
|
||||
u16 max_threads;
|
||||
u16 waiting_threads;
|
||||
u32 base_counter_lower;
|
||||
u32 base_counter_upper;
|
||||
|
||||
impl::InternalCriticalSectionStorage cs_barrier;
|
||||
impl::InternalConditionVariableStorage cv_gathered;
|
||||
};
|
||||
static_assert(std::is_trivial<BarrierType>::value);
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_busy_mutex_types.hpp>
|
||||
#include <stratosphere/os/os_busy_mutex_api.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class BusyMutex {
|
||||
NON_COPYABLE(BusyMutex);
|
||||
NON_MOVEABLE(BusyMutex);
|
||||
private:
|
||||
BusyMutexType m_mutex;
|
||||
public:
|
||||
constexpr explicit BusyMutex() : m_mutex{::ams::os::BusyMutexType::State_Initialized, nullptr, {{AMS_OS_INTERNAL_BUSY_MUTEX_IMPL_CONSTANT_INITIALIZE_ARRAY_VALUES}}} { /* ... */ }
|
||||
|
||||
~BusyMutex() { FinalizeBusyMutex(std::addressof(m_mutex)); }
|
||||
|
||||
void lock() {
|
||||
return LockBusyMutex(std::addressof(m_mutex));
|
||||
}
|
||||
|
||||
void unlock() {
|
||||
return UnlockBusyMutex(std::addressof(m_mutex));
|
||||
}
|
||||
|
||||
bool try_lock() {
|
||||
return TryLockBusyMutex(std::addressof(m_mutex));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void Lock() {
|
||||
return this->lock();
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void Unlock() {
|
||||
return this->unlock();
|
||||
}
|
||||
|
||||
ALWAYS_INLINE bool TryLock() {
|
||||
return this->try_lock();
|
||||
}
|
||||
|
||||
operator BusyMutexType &() {
|
||||
return m_mutex;
|
||||
}
|
||||
|
||||
operator const BusyMutexType &() const {
|
||||
return m_mutex;
|
||||
}
|
||||
|
||||
BusyMutexType *GetBase() {
|
||||
return std::addressof(m_mutex);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct BusyMutexType;
|
||||
|
||||
void InitializeBusyMutex(BusyMutexType *mutex);
|
||||
void FinalizeBusyMutex(BusyMutexType *mutex);
|
||||
|
||||
void LockBusyMutex(BusyMutexType *mutex);
|
||||
bool TryLockBusyMutex(BusyMutexType *mutex);
|
||||
void UnlockBusyMutex(BusyMutexType *mutex);
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_busy_mutex.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct ThreadType;
|
||||
|
||||
struct BusyMutexType {
|
||||
enum State {
|
||||
State_NotInitialized = 0,
|
||||
State_Initialized = 1,
|
||||
};
|
||||
|
||||
u8 state;
|
||||
ThreadType *owner_thread;
|
||||
union {
|
||||
s32 _arr[sizeof(impl::InternalBusyMutexStorage) / sizeof(s32)];
|
||||
impl::InternalBusyMutexStorage _storage;
|
||||
};
|
||||
};
|
||||
static_assert(std::is_trivial<BusyMutexType>::value);
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
void FlushDataCache(const void *addr, size_t size);
|
||||
void FlushEntireDataCache();
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
#if defined(ATMOSPHERE_OS_LINUX) || defined(ATMOSPHERE_OS_MACOS)
|
||||
#define AMS_OS_IMPL_USE_PTHREADS
|
||||
#elif defined(ATMOSPHERE_OS_WINDOWS)
|
||||
//#define AMS_OS_IMPL_USE_PTHREADS
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_common_config.hpp>
|
||||
|
||||
#if defined(AMS_OS_IMPL_USE_PTHREADS)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
enum class TriBool {
|
||||
False = 0,
|
||||
True = 1,
|
||||
Undefined = 2,
|
||||
};
|
||||
|
||||
enum class MessageQueueWaitKind {
|
||||
ForNotEmpty,
|
||||
ForNotFull,
|
||||
};
|
||||
|
||||
struct ProcessId {
|
||||
u64 value;
|
||||
|
||||
inline constexpr explicit operator u64() const {
|
||||
return this->value;
|
||||
}
|
||||
|
||||
/* Invalid Process ID. */
|
||||
static const ProcessId Invalid;
|
||||
};
|
||||
|
||||
inline constexpr const ProcessId ProcessId::Invalid = {static_cast<u64>(-1ull)};
|
||||
|
||||
inline constexpr const ProcessId InvalidProcessId = ProcessId::Invalid;
|
||||
|
||||
inline constexpr bool operator==(const ProcessId &lhs, const ProcessId &rhs) {
|
||||
return lhs.value == rhs.value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator!=(const ProcessId &lhs, const ProcessId &rhs) {
|
||||
return lhs.value != rhs.value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator<(const ProcessId &lhs, const ProcessId &rhs) {
|
||||
return lhs.value < rhs.value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator<=(const ProcessId &lhs, const ProcessId &rhs) {
|
||||
return lhs.value <= rhs.value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator>(const ProcessId &lhs, const ProcessId &rhs) {
|
||||
return lhs.value > rhs.value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator>=(const ProcessId &lhs, const ProcessId &rhs) {
|
||||
return lhs.value >= rhs.value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_mutex_types.hpp>
|
||||
#include <stratosphere/os/os_condition_variable_common.hpp>
|
||||
#include <stratosphere/os/os_condition_variable_types.hpp>
|
||||
#include <stratosphere/os/os_condition_variable_api.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class ConditionVariable {
|
||||
NON_COPYABLE(ConditionVariable);
|
||||
NON_MOVEABLE(ConditionVariable);
|
||||
private:
|
||||
ConditionVariableType m_cv;
|
||||
public:
|
||||
constexpr ConditionVariable() : m_cv{::ams::os::ConditionVariableType::State_Initialized, {AMS_OS_INTERNAL_CONDITION_VARIABLE_IMPL_CONSTANT_INITIALIZER}} { /* ... */ }
|
||||
|
||||
~ConditionVariable() { FinalizeConditionVariable(std::addressof(m_cv)); }
|
||||
|
||||
void Signal() {
|
||||
SignalConditionVariable(std::addressof(m_cv));
|
||||
}
|
||||
|
||||
void Broadcast() {
|
||||
BroadcastConditionVariable(std::addressof(m_cv));
|
||||
}
|
||||
|
||||
void Wait(ams::os::MutexType &mutex) {
|
||||
WaitConditionVariable(std::addressof(m_cv), std::addressof(mutex));
|
||||
}
|
||||
|
||||
ConditionVariableStatus TimedWait(ams::os::MutexType &mutex, TimeSpan timeout) {
|
||||
return TimedWaitConditionVariable(std::addressof(m_cv), std::addressof(mutex), timeout);
|
||||
}
|
||||
|
||||
operator ConditionVariableType &() {
|
||||
return m_cv;
|
||||
}
|
||||
|
||||
operator const ConditionVariableType &() const {
|
||||
return m_cv;
|
||||
}
|
||||
|
||||
ConditionVariableType *GetBase() {
|
||||
return std::addressof(m_cv);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_condition_variable_common.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct MutexType;
|
||||
struct ConditionVariableType;
|
||||
|
||||
void InitializeConditionVariable(ConditionVariableType *cv);
|
||||
void FinalizeConditionVariable(ConditionVariableType *cv);
|
||||
|
||||
void SignalConditionVariable(ConditionVariableType *cv);
|
||||
void BroadcastConditionVariable(ConditionVariableType *cv);
|
||||
|
||||
void WaitConditionVariable(ConditionVariableType *cv, MutexType *m);
|
||||
ConditionVariableStatus TimedWaitConditionVariable(ConditionVariableType *cv, MutexType *m, TimeSpan timeout);
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
enum class ConditionVariableStatus {
|
||||
TimedOut = 0,
|
||||
Success = 1,
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_condition_variable.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct ConditionVariableType {
|
||||
enum State {
|
||||
State_NotInitialized = 0,
|
||||
State_Initialized = 1,
|
||||
};
|
||||
|
||||
u8 state;
|
||||
union {
|
||||
s32 _arr[sizeof(impl::InternalConditionVariableStorage) / sizeof(s32)];
|
||||
impl::InternalConditionVariableStorage _storage;
|
||||
impl::InternalConditionVariableStorageTypeForConstantInitialize _storage_for_constant_initialize;
|
||||
};
|
||||
};
|
||||
static_assert(std::is_trivial<ConditionVariableType>::value);
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_debug_types.hpp>
|
||||
#include <stratosphere/os/os_debug_api.hpp>
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_debug_types.hpp>
|
||||
#include <stratosphere/os/os_tick.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
void GetCurrentStackInfo(uintptr_t *out_stack, size_t *out_size);
|
||||
|
||||
void QueryMemoryInfo(MemoryInfo *out);
|
||||
|
||||
Tick GetIdleTickCount();
|
||||
|
||||
int GetFreeThreadCount();
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct MemoryInfo {
|
||||
u64 total_available_memory_size;
|
||||
size_t total_used_memory_size;
|
||||
size_t total_memory_heap_size;
|
||||
size_t allocated_memory_heap_size;
|
||||
size_t program_size;
|
||||
size_t total_thread_stack_size;
|
||||
int thread_count;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_event_common.hpp>
|
||||
#include <stratosphere/os/os_event_types.hpp>
|
||||
#include <stratosphere/os/os_event_api.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class Event {
|
||||
NON_COPYABLE(Event);
|
||||
NON_MOVEABLE(Event);
|
||||
private:
|
||||
EventType m_event;
|
||||
public:
|
||||
explicit Event(EventClearMode clear_mode) {
|
||||
InitializeEvent(std::addressof(m_event), false, clear_mode);
|
||||
}
|
||||
|
||||
~Event() {
|
||||
FinalizeEvent(std::addressof(m_event));
|
||||
}
|
||||
|
||||
void Wait() {
|
||||
return WaitEvent(std::addressof(m_event));
|
||||
}
|
||||
|
||||
bool TryWait() {
|
||||
return TryWaitEvent(std::addressof(m_event));
|
||||
}
|
||||
|
||||
bool TimedWait(TimeSpan timeout) {
|
||||
return TimedWaitEvent(std::addressof(m_event), timeout);
|
||||
}
|
||||
|
||||
void Signal() {
|
||||
return SignalEvent(std::addressof(m_event));
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
return ClearEvent(std::addressof(m_event));
|
||||
}
|
||||
|
||||
operator EventType &() {
|
||||
return m_event;
|
||||
}
|
||||
|
||||
operator const EventType &() const {
|
||||
return m_event;
|
||||
}
|
||||
|
||||
EventType *GetBase() {
|
||||
return std::addressof(m_event);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_event_common.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct EventType;
|
||||
struct MultiWaitHolderType;
|
||||
|
||||
void InitializeEvent(EventType *event, bool signaled, EventClearMode clear_mode);
|
||||
void FinalizeEvent(EventType *event);
|
||||
|
||||
void SignalEvent(EventType *event);
|
||||
void WaitEvent(EventType *event);
|
||||
bool TryWaitEvent(EventType *event);
|
||||
bool TimedWaitEvent(EventType *event, TimeSpan timeout);
|
||||
void ClearEvent(EventType *event);
|
||||
|
||||
void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, EventType *event);
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
enum EventClearMode {
|
||||
EventClearMode_ManualClear = 0,
|
||||
EventClearMode_AutoClear = 1,
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_condition_variable.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
namespace impl {
|
||||
|
||||
class MultiWaitObjectList;
|
||||
|
||||
}
|
||||
|
||||
struct EventType {
|
||||
enum State {
|
||||
State_NotInitialized = 0,
|
||||
State_Initialized = 1,
|
||||
};
|
||||
|
||||
util::TypedStorage<impl::MultiWaitObjectList, sizeof(util::IntrusiveListNode), alignof(util::IntrusiveListNode)> multi_wait_object_list_storage;
|
||||
bool signaled;
|
||||
bool initially_signaled;
|
||||
u8 clear_mode;
|
||||
u8 state;
|
||||
u32 broadcast_counter_low;
|
||||
u32 broadcast_counter_high;
|
||||
|
||||
impl::InternalCriticalSectionStorage cs_event;
|
||||
impl::InternalConditionVariableStorage cv_signaled;
|
||||
};
|
||||
static_assert(std::is_trivial<EventType>::value);
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_memory_common.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
Result AllocateInsecureMemory(uintptr_t *out_address, size_t size);
|
||||
void FreeInsecureMemory(uintptr_t address, size_t size);
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_event_common.hpp>
|
||||
#include <stratosphere/os/os_interrupt_event_common.hpp>
|
||||
#include <stratosphere/os/os_interrupt_event_types.hpp>
|
||||
#include <stratosphere/os/os_interrupt_event_api.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class InterruptEvent {
|
||||
NON_COPYABLE(InterruptEvent);
|
||||
NON_MOVEABLE(InterruptEvent);
|
||||
private:
|
||||
InterruptEventType m_event;
|
||||
public:
|
||||
explicit InterruptEvent(InterruptName name, EventClearMode clear_mode) {
|
||||
InitializeInterruptEvent(std::addressof(m_event), name, clear_mode);
|
||||
}
|
||||
|
||||
~InterruptEvent() {
|
||||
FinalizeInterruptEvent(std::addressof(m_event));
|
||||
}
|
||||
|
||||
void Wait() {
|
||||
return WaitInterruptEvent(std::addressof(m_event));
|
||||
}
|
||||
|
||||
bool TryWait() {
|
||||
return TryWaitInterruptEvent(std::addressof(m_event));
|
||||
}
|
||||
|
||||
bool TimedWait(TimeSpan timeout) {
|
||||
return TimedWaitInterruptEvent(std::addressof(m_event), timeout);
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
return ClearInterruptEvent(std::addressof(m_event));
|
||||
}
|
||||
|
||||
operator InterruptEventType &() {
|
||||
return m_event;
|
||||
}
|
||||
|
||||
operator const InterruptEventType &() const {
|
||||
return m_event;
|
||||
}
|
||||
|
||||
InterruptEventType *GetBase() {
|
||||
return std::addressof(m_event);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_interrupt_event_common.hpp>
|
||||
#include <stratosphere/os/os_native_handle.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct InterruptEventType;
|
||||
struct MultiWaitHolderType;
|
||||
|
||||
void InitializeInterruptEvent(InterruptEventType *event, InterruptName name, EventClearMode clear_mode);
|
||||
void FinalizeInterruptEvent(InterruptEventType *event);
|
||||
|
||||
void WaitInterruptEvent(InterruptEventType *event);
|
||||
bool TryWaitInterruptEvent(InterruptEventType *event);
|
||||
bool TimedWaitInterruptEvent(InterruptEventType *event, TimeSpan timeout);
|
||||
void ClearInterruptEvent(InterruptEventType *event);
|
||||
|
||||
NativeHandle GetInterruptEventHandle(const InterruptEventType *event);
|
||||
|
||||
void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, InterruptEventType *event);
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
using InterruptName = s32;
|
||||
#elif defined(ATMOSPHERE_OS_WINDOWS)
|
||||
using InterruptName = const char *;
|
||||
#elif defined(ATMOSPHERE_OS_LINUX)
|
||||
using InterruptName = const char *;
|
||||
#elif defined(ATMOSPHERE_OS_MACOS)
|
||||
using InterruptName = const char *;
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_condition_variable.hpp>
|
||||
#include <stratosphere/os/os_native_handle.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
namespace impl {
|
||||
|
||||
class MultiWaitObjectList;
|
||||
class InterruptEventImpl;
|
||||
|
||||
}
|
||||
|
||||
struct InterruptEventType {
|
||||
enum State {
|
||||
State_NotInitialized = 0,
|
||||
State_Initialized = 1,
|
||||
};
|
||||
|
||||
util::TypedStorage<impl::MultiWaitObjectList, sizeof(util::IntrusiveListNode), alignof(util::IntrusiveListNode)> multi_wait_object_list_storage;
|
||||
|
||||
u8 clear_mode;
|
||||
u8 state;
|
||||
|
||||
util::TypedStorage<impl::InterruptEventImpl, sizeof(NativeHandle) * 2, alignof(NativeHandle)> impl;
|
||||
};
|
||||
static_assert(std::is_trivial<InterruptEventType>::value);
|
||||
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_io_region_types.hpp>
|
||||
#include <stratosphere/os/os_io_region_api.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class IoRegion {
|
||||
NON_COPYABLE(IoRegion);
|
||||
NON_MOVEABLE(IoRegion);
|
||||
private:
|
||||
IoRegionType m_io_region;
|
||||
public:
|
||||
constexpr IoRegion() : m_io_region{ .state = IoRegionType::State_NotInitialized } {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
IoRegion(NativeHandle io_pool_handle, uintptr_t address, size_t size, MemoryMapping mapping, MemoryPermission permission) {
|
||||
R_ABORT_UNLESS(CreateIoRegion(std::addressof(m_io_region), io_pool_handle, address, size, mapping, permission));
|
||||
}
|
||||
|
||||
IoRegion(size_t size, NativeHandle handle, bool managed) {
|
||||
this->AttachHandle(size, handle, managed);
|
||||
}
|
||||
|
||||
~IoRegion() {
|
||||
if (m_io_region.state == IoRegionType::State_NotInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_io_region.state == IoRegionType::State_Mapped) {
|
||||
this->Unmap();
|
||||
}
|
||||
|
||||
DestroyIoRegion(std::addressof(m_io_region));
|
||||
}
|
||||
|
||||
void AttachHandle(size_t size, NativeHandle handle, bool managed) {
|
||||
AttachIoRegionHandle(std::addressof(m_io_region), size, handle, managed);
|
||||
}
|
||||
|
||||
NativeHandle GetHandle() const {
|
||||
return GetIoRegionHandle(std::addressof(m_io_region));
|
||||
}
|
||||
|
||||
Result Map(void **out, MemoryPermission perm) {
|
||||
R_RETURN(MapIoRegion(out, std::addressof(m_io_region), perm));
|
||||
}
|
||||
|
||||
void Unmap() {
|
||||
UnmapIoRegion(std::addressof(m_io_region));
|
||||
}
|
||||
|
||||
operator IoRegionType &() {
|
||||
return m_io_region;
|
||||
}
|
||||
|
||||
operator const IoRegionType &() const {
|
||||
return m_io_region;
|
||||
}
|
||||
|
||||
IoRegionType *GetBase() {
|
||||
return std::addressof(m_io_region);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_memory_permission.hpp>
|
||||
#include <stratosphere/os/os_native_handle.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct IoRegionType;
|
||||
|
||||
Result CreateIoRegion(IoRegionType *io_region, NativeHandle io_pool_handle, uintptr_t address, size_t size, MemoryMapping mapping, MemoryPermission permission);
|
||||
|
||||
void AttachIoRegionHandle(IoRegionType *io_region, size_t size, NativeHandle handle, bool managed);
|
||||
os::NativeHandle DetachIoRegionHandle(IoRegionType *io_region);
|
||||
|
||||
void DestroyIoRegion(IoRegionType *io_region);
|
||||
|
||||
NativeHandle GetIoRegionHandle(const IoRegionType *io_region);
|
||||
|
||||
Result MapIoRegion(void **out, IoRegionType *io_region, MemoryPermission perm);
|
||||
void UnmapIoRegion(IoRegionType *io_region);
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
#include <stratosphere/os/os_native_handle.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct IoRegionType {
|
||||
enum State {
|
||||
State_NotInitialized = 0,
|
||||
State_Initialized = 1,
|
||||
State_Mapped = 2,
|
||||
State_Detached = 3,
|
||||
};
|
||||
|
||||
NativeHandle handle;
|
||||
u8 state;
|
||||
size_t size;
|
||||
void *mapped_address;
|
||||
bool handle_managed;
|
||||
|
||||
mutable impl::InternalCriticalSectionStorage cs_io_region;
|
||||
};
|
||||
static_assert(std::is_trivial<IoRegionType>::value);
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_event_common.hpp>
|
||||
#include <stratosphere/os/os_light_event_types.hpp>
|
||||
#include <stratosphere/os/os_light_event_api.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class LightEvent {
|
||||
NON_COPYABLE(LightEvent);
|
||||
NON_MOVEABLE(LightEvent);
|
||||
private:
|
||||
LightEventType m_event;
|
||||
public:
|
||||
explicit LightEvent(EventClearMode clear_mode) {
|
||||
InitializeLightEvent(std::addressof(m_event), false, clear_mode);
|
||||
}
|
||||
|
||||
~LightEvent() {
|
||||
FinalizeLightEvent(std::addressof(m_event));
|
||||
}
|
||||
|
||||
void Wait() {
|
||||
return WaitLightEvent(std::addressof(m_event));
|
||||
}
|
||||
|
||||
bool TryWait() {
|
||||
return TryWaitLightEvent(std::addressof(m_event));
|
||||
}
|
||||
|
||||
bool TimedWait(TimeSpan timeout) {
|
||||
return TimedWaitLightEvent(std::addressof(m_event), timeout);
|
||||
}
|
||||
|
||||
void Signal() {
|
||||
return SignalLightEvent(std::addressof(m_event));
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
return ClearLightEvent(std::addressof(m_event));
|
||||
}
|
||||
|
||||
operator LightEventType &() {
|
||||
return m_event;
|
||||
}
|
||||
|
||||
operator const LightEventType &() const {
|
||||
return m_event;
|
||||
}
|
||||
|
||||
LightEventType *GetBase() {
|
||||
return std::addressof(m_event);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_event_common.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct LightEventType;
|
||||
|
||||
void InitializeLightEvent(LightEventType *event, bool signaled, EventClearMode clear_mode);
|
||||
void FinalizeLightEvent(LightEventType *event);
|
||||
|
||||
void SignalLightEvent(LightEventType *event);
|
||||
void WaitLightEvent(LightEventType *event);
|
||||
bool TryWaitLightEvent(LightEventType *event);
|
||||
bool TimedWaitLightEvent(LightEventType *event, TimeSpan timeout);
|
||||
void ClearLightEvent(LightEventType *event);
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_light_event.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct LightEventType {
|
||||
bool is_auto_clear;
|
||||
bool is_initialized;
|
||||
|
||||
impl::InternalLightEventStorage storage;
|
||||
};
|
||||
static_assert(std::is_trivial<LightEventType>::value);
|
||||
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_light_message_queue_types.hpp>
|
||||
#include <stratosphere/os/os_light_message_queue_api.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class LightMessageQueue {
|
||||
NON_COPYABLE(LightMessageQueue);
|
||||
NON_MOVEABLE(LightMessageQueue);
|
||||
private:
|
||||
LightMessageQueueType m_mq;
|
||||
public:
|
||||
explicit LightMessageQueue(uintptr_t *buf, size_t count) {
|
||||
InitializeLightMessageQueue(std::addressof(m_mq), buf, count);
|
||||
}
|
||||
|
||||
~LightMessageQueue() { FinalizeLightMessageQueue(std::addressof(m_mq)); }
|
||||
|
||||
/* Sending (FIFO functionality) */
|
||||
void Send(uintptr_t data) {
|
||||
return SendLightMessageQueue(std::addressof(m_mq), data);
|
||||
}
|
||||
|
||||
bool TrySend(uintptr_t data) {
|
||||
return TrySendLightMessageQueue(std::addressof(m_mq), data);
|
||||
}
|
||||
|
||||
bool TimedSend(uintptr_t data, TimeSpan timeout) {
|
||||
return TimedSendLightMessageQueue(std::addressof(m_mq), data, timeout);
|
||||
}
|
||||
|
||||
/* Jamming (LIFO functionality) */
|
||||
void Jam(uintptr_t data) {
|
||||
return JamLightMessageQueue(std::addressof(m_mq), data);
|
||||
}
|
||||
|
||||
bool TryJam(uintptr_t data) {
|
||||
return TryJamLightMessageQueue(std::addressof(m_mq), data);
|
||||
}
|
||||
|
||||
bool TimedJam(uintptr_t data, TimeSpan timeout) {
|
||||
return TimedJamLightMessageQueue(std::addressof(m_mq), data, timeout);
|
||||
}
|
||||
|
||||
/* Receive functionality */
|
||||
void Receive(uintptr_t *out) {
|
||||
return ReceiveLightMessageQueue(out, std::addressof(m_mq));
|
||||
}
|
||||
|
||||
bool TryReceive(uintptr_t *out) {
|
||||
return TryReceiveLightMessageQueue(out, std::addressof(m_mq));
|
||||
}
|
||||
|
||||
bool TimedReceive(uintptr_t *out, TimeSpan timeout) {
|
||||
return TimedReceiveLightMessageQueue(out, std::addressof(m_mq), timeout);
|
||||
}
|
||||
|
||||
/* Peek functionality */
|
||||
void Peek(uintptr_t *out) const {
|
||||
return PeekLightMessageQueue(out, std::addressof(m_mq));
|
||||
}
|
||||
|
||||
bool TryPeek(uintptr_t *out) const {
|
||||
return TryPeekLightMessageQueue(out, std::addressof(m_mq));
|
||||
}
|
||||
|
||||
bool TimedPeek(uintptr_t *out, TimeSpan timeout) const {
|
||||
return TimedPeekLightMessageQueue(out, std::addressof(m_mq), timeout);
|
||||
}
|
||||
|
||||
operator LightMessageQueueType &() {
|
||||
return m_mq;
|
||||
}
|
||||
|
||||
operator const LightMessageQueueType &() const {
|
||||
return m_mq;
|
||||
}
|
||||
|
||||
LightMessageQueueType *GetBase() {
|
||||
return std::addressof(m_mq);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct LightMessageQueueType;
|
||||
|
||||
void InitializeLightMessageQueue(LightMessageQueueType *mq, uintptr_t *buffer, size_t count);
|
||||
void FinalizeLightMessageQueue(LightMessageQueueType *mq);
|
||||
|
||||
/* Sending (FIFO functionality) */
|
||||
void SendLightMessageQueue(LightMessageQueueType *mq, uintptr_t data);
|
||||
bool TrySendLightMessageQueue(LightMessageQueueType *mq, uintptr_t data);
|
||||
bool TimedSendLightMessageQueue(LightMessageQueueType *mq, uintptr_t data, TimeSpan timeout);
|
||||
|
||||
/* Jamming (LIFO functionality) */
|
||||
void JamLightMessageQueue(LightMessageQueueType *mq, uintptr_t data);
|
||||
bool TryJamLightMessageQueue(LightMessageQueueType *mq, uintptr_t data);
|
||||
bool TimedJamLightMessageQueue(LightMessageQueueType *mq, uintptr_t data, TimeSpan timeout);
|
||||
|
||||
/* Receive functionality */
|
||||
void ReceiveLightMessageQueue(uintptr_t *out, LightMessageQueueType *mq);
|
||||
bool TryReceiveLightMessageQueue(uintptr_t *out, LightMessageQueueType *mq);
|
||||
bool TimedReceiveLightMessageQueue(uintptr_t *out, LightMessageQueueType *mq, TimeSpan timeout);
|
||||
|
||||
/* Peek functionality */
|
||||
void PeekLightMessageQueue(uintptr_t *out, const LightMessageQueueType *mq);
|
||||
bool TryPeekLightMessageQueue(uintptr_t *out, const LightMessageQueueType *mq);
|
||||
bool TimedPeekLightMessageQueue(uintptr_t *out, const LightMessageQueueType *mq, TimeSpan timeout);
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_busy_mutex.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_light_event.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
namespace impl {
|
||||
|
||||
using LightMessageQueueMutex = InternalBusyMutex;
|
||||
using LightMessageQueueMutexStorage = InternalBusyMutexStorage;
|
||||
|
||||
}
|
||||
|
||||
struct LightMessageQueueType {
|
||||
enum State {
|
||||
State_NotInitialized = 0,
|
||||
State_Initialized = 1,
|
||||
};
|
||||
|
||||
uintptr_t *buffer;
|
||||
s32 capacity;
|
||||
s32 count;
|
||||
s32 offset;
|
||||
u8 state;
|
||||
|
||||
mutable impl::LightMessageQueueMutexStorage mutex_queue;
|
||||
mutable impl::InternalLightEventStorage ev_not_full;
|
||||
mutable impl::InternalLightEventStorage ev_not_empty;
|
||||
};
|
||||
static_assert(std::is_trivial<LightMessageQueueType>::value);
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_light_semaphore_types.hpp>
|
||||
#include <stratosphere/os/os_light_semaphore_api.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class LightSemaphore {
|
||||
NON_COPYABLE(LightSemaphore);
|
||||
NON_MOVEABLE(LightSemaphore);
|
||||
private:
|
||||
LightSemaphoreType m_sema;
|
||||
public:
|
||||
explicit LightSemaphore(s32 count, s32 max_count) {
|
||||
InitializeLightSemaphore(std::addressof(m_sema), count, max_count);
|
||||
}
|
||||
|
||||
~LightSemaphore() { FinalizeLightSemaphore(std::addressof(m_sema)); }
|
||||
|
||||
void Acquire() {
|
||||
return os::AcquireLightSemaphore(std::addressof(m_sema));
|
||||
}
|
||||
|
||||
bool TryAcquire() {
|
||||
return os::TryAcquireLightSemaphore(std::addressof(m_sema));
|
||||
}
|
||||
|
||||
bool TimedAcquire(TimeSpan timeout) {
|
||||
return os::TimedAcquireLightSemaphore(std::addressof(m_sema), timeout);
|
||||
}
|
||||
|
||||
void Release() {
|
||||
return os::ReleaseLightSemaphore(std::addressof(m_sema));
|
||||
}
|
||||
|
||||
void Release(s32 count) {
|
||||
return os::ReleaseLightSemaphore(std::addressof(m_sema), count);
|
||||
}
|
||||
|
||||
s32 GetCurrentCount() const {
|
||||
return os::GetCurrentLightSemaphoreCount(std::addressof(m_sema));
|
||||
}
|
||||
|
||||
operator LightSemaphoreType &() {
|
||||
return m_sema;
|
||||
}
|
||||
|
||||
operator const LightSemaphoreType &() const {
|
||||
return m_sema;
|
||||
}
|
||||
|
||||
LightSemaphoreType *GetBase() {
|
||||
return std::addressof(m_sema);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct LightSemaphoreType;
|
||||
|
||||
void InitializeLightSemaphore(LightSemaphoreType *sema, s32 count, s32 max_count);
|
||||
void FinalizeLightSemaphore(LightSemaphoreType *sema);
|
||||
|
||||
void AcquireLightSemaphore(LightSemaphoreType *sema);
|
||||
bool TryAcquireLightSemaphore(LightSemaphoreType *sema);
|
||||
bool TimedAcquireLightSemaphore(LightSemaphoreType *sema, TimeSpan timeout);
|
||||
|
||||
void ReleaseLightSemaphore(LightSemaphoreType *sema);
|
||||
void ReleaseLightSemaphore(LightSemaphoreType *sema, s32 count);
|
||||
|
||||
s32 GetCurrentLightSemaphoreCount(const LightSemaphoreType *sema);
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_busy_mutex.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_light_event.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
namespace impl {
|
||||
|
||||
using LightSemaphoreMutex = InternalBusyMutex;
|
||||
using LightSemaphoreMutexStorage = InternalBusyMutexStorage;
|
||||
|
||||
}
|
||||
|
||||
struct LightSemaphoreType {
|
||||
enum State {
|
||||
State_NotInitialized = 0,
|
||||
State_Initialized = 1,
|
||||
};
|
||||
|
||||
u8 state;
|
||||
s32 count;
|
||||
s32 max_count;
|
||||
|
||||
mutable impl::LightSemaphoreMutexStorage mutex;
|
||||
impl::InternalLightEventStorage ev_not_zero;
|
||||
};
|
||||
static_assert(std::is_trivial<LightSemaphoreType>::value);
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_common_types.hpp>
|
||||
#include <stratosphere/os/os_memory_common.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
enum MemoryAttribute {
|
||||
MemoryAttribute_Normal,
|
||||
MemoryAttribute_Uncached,
|
||||
};
|
||||
|
||||
void SetMemoryAttribute(uintptr_t address, size_t size, MemoryAttribute attr);
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
using AddressSpaceGenerateRandomFunction = u64 (*)(u64);
|
||||
|
||||
enum MemoryPermission {
|
||||
MemoryPermission_None = (0 << 0),
|
||||
MemoryPermission_ReadOnly = (1 << 0),
|
||||
MemoryPermission_WriteOnly = (1 << 1),
|
||||
MemoryPermission_ExecuteOnly = (1 << 2),
|
||||
|
||||
MemoryPermission_ReadWrite = MemoryPermission_ReadOnly | MemoryPermission_WriteOnly,
|
||||
MemoryPermission_ReadExecute = MemoryPermission_ReadOnly | MemoryPermission_ExecuteOnly,
|
||||
};
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
using MemoryMapping = svc::MemoryMapping;
|
||||
using enum svc::MemoryMapping;
|
||||
#else
|
||||
enum MemoryMapping : u32 {
|
||||
MemoryMapping_IoRegister = 0,
|
||||
MemoryMapping_Uncached = 1,
|
||||
MemoryMapping_Memory = 2,
|
||||
};
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_memory_fence_api.hpp>
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
#include <stratosphere/os/impl/os_memory_fence_api.os.horizon.hpp>
|
||||
#elif defined(ATMOSPHERE_OS_WINDOWS) || defined(ATMOSPHERE_OS_LINUX) || defined(ATMOSPHERE_OS_MACOS)
|
||||
#include <stratosphere/os/impl/os_memory_fence_api.os.generic.hpp>
|
||||
#else
|
||||
#error "Unknown os for os::MemoryFence*"
|
||||
#endif
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
ALWAYS_INLINE void FenceMemoryStoreStore() { return impl::FenceMemoryStoreStore(); }
|
||||
ALWAYS_INLINE void FenceMemoryStoreLoad() { return impl::FenceMemoryStoreLoad(); }
|
||||
ALWAYS_INLINE void FenceMemoryStoreAny() { return impl::FenceMemoryStoreAny(); }
|
||||
|
||||
ALWAYS_INLINE void FenceMemoryLoadStore() { return impl::FenceMemoryLoadStore(); }
|
||||
ALWAYS_INLINE void FenceMemoryLoadLoad() { return impl::FenceMemoryLoadLoad(); }
|
||||
ALWAYS_INLINE void FenceMemoryLoadAny() { return impl::FenceMemoryLoadAny(); }
|
||||
|
||||
ALWAYS_INLINE void FenceMemoryAnyStore() { return impl::FenceMemoryLoadStore(); }
|
||||
ALWAYS_INLINE void FenceMemoryAnyLoad() { return impl::FenceMemoryLoadLoad(); }
|
||||
ALWAYS_INLINE void FenceMemoryAnyAny() { return impl::FenceMemoryLoadAny(); }
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_memory_heap_common.hpp>
|
||||
#include <stratosphere/os/os_memory_heap_api.hpp>
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_common_types.hpp>
|
||||
#include <stratosphere/os/os_memory_heap_common.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
Result SetMemoryHeapSize(size_t size);
|
||||
|
||||
uintptr_t GetMemoryHeapAddress();
|
||||
size_t GetMemoryHeapSize();
|
||||
|
||||
Result AllocateMemoryBlock(uintptr_t *out_address, size_t size);
|
||||
void FreeMemoryBlock(uintptr_t address, size_t size);
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_common_types.hpp>
|
||||
#include <stratosphere/os/os_memory_common.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
constexpr inline size_t MemoryHeapUnitSize = 2_MB;
|
||||
constexpr inline size_t MemoryBlockUnitSize = 2_MB;
|
||||
|
||||
constexpr inline size_t MemoryPageSize = 4_KB;
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_common_types.hpp>
|
||||
#include <stratosphere/os/os_memory_common.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
void SetMemoryPermission(uintptr_t address, size_t size, MemoryPermission perm);
|
||||
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_message_queue_common.hpp>
|
||||
#include <stratosphere/os/os_message_queue_types.hpp>
|
||||
#include <stratosphere/os/os_message_queue_api.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class MessageQueue {
|
||||
NON_COPYABLE(MessageQueue);
|
||||
NON_MOVEABLE(MessageQueue);
|
||||
private:
|
||||
MessageQueueType m_mq;
|
||||
public:
|
||||
explicit MessageQueue(uintptr_t *buf, size_t count) {
|
||||
InitializeMessageQueue(std::addressof(m_mq), buf, count);
|
||||
}
|
||||
|
||||
~MessageQueue() { FinalizeMessageQueue(std::addressof(m_mq)); }
|
||||
|
||||
/* Sending (FIFO functionality) */
|
||||
void Send(uintptr_t data) {
|
||||
return SendMessageQueue(std::addressof(m_mq), data);
|
||||
}
|
||||
|
||||
bool TrySend(uintptr_t data) {
|
||||
return TrySendMessageQueue(std::addressof(m_mq), data);
|
||||
}
|
||||
|
||||
bool TimedSend(uintptr_t data, TimeSpan timeout) {
|
||||
return TimedSendMessageQueue(std::addressof(m_mq), data, timeout);
|
||||
}
|
||||
|
||||
/* Jamming (LIFO functionality) */
|
||||
void Jam(uintptr_t data) {
|
||||
return JamMessageQueue(std::addressof(m_mq), data);
|
||||
}
|
||||
|
||||
bool TryJam(uintptr_t data) {
|
||||
return TryJamMessageQueue(std::addressof(m_mq), data);
|
||||
}
|
||||
|
||||
bool TimedJam(uintptr_t data, TimeSpan timeout) {
|
||||
return TimedJamMessageQueue(std::addressof(m_mq), data, timeout);
|
||||
}
|
||||
|
||||
/* Receive functionality */
|
||||
void Receive(uintptr_t *out) {
|
||||
return ReceiveMessageQueue(out, std::addressof(m_mq));
|
||||
}
|
||||
|
||||
bool TryReceive(uintptr_t *out) {
|
||||
return TryReceiveMessageQueue(out, std::addressof(m_mq));
|
||||
}
|
||||
|
||||
bool TimedReceive(uintptr_t *out, TimeSpan timeout) {
|
||||
return TimedReceiveMessageQueue(out, std::addressof(m_mq), timeout);
|
||||
}
|
||||
|
||||
/* Peek functionality */
|
||||
void Peek(uintptr_t *out) const {
|
||||
return PeekMessageQueue(out, std::addressof(m_mq));
|
||||
}
|
||||
|
||||
bool TryPeek(uintptr_t *out) const {
|
||||
return TryPeekMessageQueue(out, std::addressof(m_mq));
|
||||
}
|
||||
|
||||
bool TimedPeek(uintptr_t *out, TimeSpan timeout) const {
|
||||
return TimedPeekMessageQueue(out, std::addressof(m_mq), timeout);
|
||||
}
|
||||
|
||||
operator MessageQueueType &() {
|
||||
return m_mq;
|
||||
}
|
||||
|
||||
operator const MessageQueueType &() const {
|
||||
return m_mq;
|
||||
}
|
||||
|
||||
MessageQueueType *GetBase() {
|
||||
return std::addressof(m_mq);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_message_queue_common.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct MessageQueueType;
|
||||
struct MultiWaitHolderType;
|
||||
|
||||
void InitializeMessageQueue(MessageQueueType *mq, uintptr_t *buffer, size_t count);
|
||||
void FinalizeMessageQueue(MessageQueueType *mq);
|
||||
|
||||
/* Sending (FIFO functionality) */
|
||||
void SendMessageQueue(MessageQueueType *mq, uintptr_t data);
|
||||
bool TrySendMessageQueue(MessageQueueType *mq, uintptr_t data);
|
||||
bool TimedSendMessageQueue(MessageQueueType *mq, uintptr_t data, TimeSpan timeout);
|
||||
|
||||
/* Jamming (LIFO functionality) */
|
||||
void JamMessageQueue(MessageQueueType *mq, uintptr_t data);
|
||||
bool TryJamMessageQueue(MessageQueueType *mq, uintptr_t data);
|
||||
bool TimedJamMessageQueue(MessageQueueType *mq, uintptr_t data, TimeSpan timeout);
|
||||
|
||||
/* Receive functionality */
|
||||
void ReceiveMessageQueue(uintptr_t *out, MessageQueueType *mq);
|
||||
bool TryReceiveMessageQueue(uintptr_t *out, MessageQueueType *mq);
|
||||
bool TimedReceiveMessageQueue(uintptr_t *out, MessageQueueType *mq, TimeSpan timeout);
|
||||
|
||||
/* Peek functionality */
|
||||
void PeekMessageQueue(uintptr_t *out, const MessageQueueType *mq);
|
||||
bool TryPeekMessageQueue(uintptr_t *out, const MessageQueueType *mq);
|
||||
bool TimedPeekMessageQueue(uintptr_t *out, const MessageQueueType *mq, TimeSpan timeout);
|
||||
|
||||
void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, MessageQueueType *event, MessageQueueWaitType wait_type);
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
enum class MessageQueueWaitType {
|
||||
ForNotFull = 1,
|
||||
ForNotEmpty = 2,
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_condition_variable.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
namespace impl {
|
||||
|
||||
class MultiWaitObjectList;
|
||||
|
||||
}
|
||||
|
||||
struct MessageQueueType {
|
||||
enum State {
|
||||
State_NotInitialized = 0,
|
||||
State_Initialized = 1,
|
||||
};
|
||||
|
||||
util::TypedStorage<impl::MultiWaitObjectList, sizeof(util::IntrusiveListNode), alignof(util::IntrusiveListNode)> waitlist_not_full;
|
||||
util::TypedStorage<impl::MultiWaitObjectList, sizeof(util::IntrusiveListNode), alignof(util::IntrusiveListNode)> waitlist_not_empty;
|
||||
uintptr_t *buffer;
|
||||
s32 capacity;
|
||||
s32 count;
|
||||
s32 offset;
|
||||
u8 state;
|
||||
|
||||
mutable impl::InternalCriticalSectionStorage cs_queue;
|
||||
mutable impl::InternalConditionVariableStorage cv_not_full;
|
||||
mutable impl::InternalConditionVariableStorage cv_not_empty;
|
||||
};
|
||||
static_assert(std::is_trivial<MessageQueueType>::value);
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_multiple_wait_types.hpp>
|
||||
#include <stratosphere/os/os_multiple_wait_api.hpp>
|
||||
#include <stratosphere/os/os_multiple_wait_utils.hpp>
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_message_queue_common.hpp>
|
||||
#include <stratosphere/os/os_native_handle.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct MultiWaitHolderType;
|
||||
struct MultiWaitType;
|
||||
|
||||
void InitializeMultiWait(MultiWaitType *multi_wait);
|
||||
void FinalizeMultiWait(MultiWaitType *multi_wait);
|
||||
|
||||
MultiWaitHolderType *WaitAny(MultiWaitType *multi_wait);
|
||||
MultiWaitHolderType *TryWaitAny(MultiWaitType *multi_wait);
|
||||
MultiWaitHolderType *TimedWaitAny(MultiWaitType *multi_wait, TimeSpan timeout);
|
||||
|
||||
void FinalizeMultiWaitHolder(MultiWaitHolderType *holder);
|
||||
|
||||
void LinkMultiWaitHolder(MultiWaitType *multi_wait, MultiWaitHolderType *holder);
|
||||
void UnlinkMultiWaitHolder(MultiWaitHolderType *holder);
|
||||
void UnlinkAllMultiWaitHolder(MultiWaitType *multi_wait);
|
||||
|
||||
void MoveAllMultiWaitHolder(MultiWaitType *dst, MultiWaitType *src);
|
||||
|
||||
void SetMultiWaitHolderUserData(MultiWaitHolderType *holder, uintptr_t user_data);
|
||||
uintptr_t GetMultiWaitHolderUserData(const MultiWaitHolderType *holder);
|
||||
|
||||
void InitializeMultiWaitHolder(MultiWaitHolderType *holder, NativeHandle handle);
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
namespace impl {
|
||||
|
||||
class MultiWaitImpl;
|
||||
struct MultiWaitHolderImpl;
|
||||
|
||||
}
|
||||
|
||||
struct MultiWaitType {
|
||||
enum State {
|
||||
State_NotInitialized,
|
||||
State_Initialized,
|
||||
};
|
||||
|
||||
u8 state;
|
||||
bool is_waiting;
|
||||
util::TypedStorage<impl::MultiWaitImpl, util::AlignUp(sizeof(util::IntrusiveListNode) + sizeof(impl::InternalCriticalSection) + 2 * sizeof(void *) + sizeof(NativeHandle), alignof(void *)), alignof(void *)> impl_storage;
|
||||
};
|
||||
static_assert(std::is_trivial<MultiWaitType>::value);
|
||||
|
||||
struct MultiWaitHolderType {
|
||||
util::TypedStorage<impl::MultiWaitHolderImpl, 2 * sizeof(util::IntrusiveListNode) + 3 * sizeof(void *), alignof(void *)> impl_storage;
|
||||
uintptr_t user_data;
|
||||
};
|
||||
static_assert(std::is_trivial<MultiWaitHolderType>::value);
|
||||
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_message_queue_common.hpp>
|
||||
#include <stratosphere/os/os_multiple_wait_api.hpp>
|
||||
#include <stratosphere/os/os_multiple_wait_types.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
namespace impl {
|
||||
|
||||
class AutoMultiWaitHolder {
|
||||
private:
|
||||
MultiWaitHolderType m_holder;
|
||||
public:
|
||||
template<typename T>
|
||||
ALWAYS_INLINE explicit AutoMultiWaitHolder(MultiWaitType *multi_wait, T &&arg) {
|
||||
InitializeMultiWaitHolder(std::addressof(m_holder), std::forward<T>(arg));
|
||||
LinkMultiWaitHolder(multi_wait, std::addressof(m_holder));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE ~AutoMultiWaitHolder() {
|
||||
UnlinkMultiWaitHolder(std::addressof(m_holder));
|
||||
FinalizeMultiWaitHolder(std::addressof(m_holder));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE std::pair<MultiWaitHolderType *, int> ConvertResult(const std::pair<MultiWaitHolderType *, int> result, int index) {
|
||||
if (result.first == std::addressof(m_holder)) {
|
||||
return std::make_pair(static_cast<MultiWaitHolderType *>(nullptr), index);
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename F>
|
||||
inline std::pair<MultiWaitHolderType *, int> WaitAnyImpl(F &&func, MultiWaitType *multi_wait, int) {
|
||||
return std::pair<MultiWaitHolderType *, int>(func(multi_wait), -1);
|
||||
}
|
||||
|
||||
template<typename F, typename T, typename... Args>
|
||||
inline std::pair<MultiWaitHolderType *, int> WaitAnyImpl(F &&func, MultiWaitType *multi_wait, int index, T &&x, Args &&... args) {
|
||||
AutoMultiWaitHolder holder(multi_wait, std::forward<T>(x));
|
||||
return holder.ConvertResult(WaitAnyImpl(std::forward<F>(func), multi_wait, index + 1, std::forward<Args>(args)...), index);
|
||||
}
|
||||
|
||||
template<typename F, typename... Args>
|
||||
inline std::pair<MultiWaitHolderType *, int> WaitAnyImpl(F &&func, MultiWaitType *multi_wait, Args &&... args) {
|
||||
return WaitAnyImpl(std::forward<F>(func), multi_wait, 0, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
class TempMultiWait {
|
||||
private:
|
||||
MultiWaitType m_multi_wait;
|
||||
public:
|
||||
ALWAYS_INLINE TempMultiWait() {
|
||||
os::InitializeMultiWait(std::addressof(m_multi_wait));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE ~TempMultiWait() {
|
||||
os::FinalizeMultiWait(std::addressof(m_multi_wait));
|
||||
}
|
||||
|
||||
MultiWaitType *Get() {
|
||||
return std::addressof(m_multi_wait);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename F, typename... Args>
|
||||
inline std::pair<MultiWaitHolderType *, int> WaitAnyImpl(F &&func, Args &&... args) {
|
||||
TempMultiWait temp_multi_wait;
|
||||
return WaitAnyImpl(std::forward<F>(func), temp_multi_wait.Get(), 0, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
using WaitAnyFunction = MultiWaitHolderType * (*)(MultiWaitType *);
|
||||
|
||||
class NotBoolButInt {
|
||||
private:
|
||||
int m_value;
|
||||
public:
|
||||
constexpr ALWAYS_INLINE NotBoolButInt(int v) : m_value(v) { /* ... */ }
|
||||
|
||||
constexpr ALWAYS_INLINE operator int() const { return m_value; }
|
||||
|
||||
explicit operator bool() const = delete;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template<typename... Args> requires (sizeof...(Args) > 0)
|
||||
inline std::pair<MultiWaitHolderType *, int> WaitAny(MultiWaitType *multi_wait, Args &&... args) {
|
||||
return impl::WaitAnyImpl(static_cast<impl::WaitAnyFunction>(&::ams::os::WaitAny), multi_wait, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args> requires (sizeof...(Args) > 0)
|
||||
inline int WaitAny(Args &&... args) {
|
||||
return impl::WaitAnyImpl(static_cast<impl::WaitAnyFunction>(&::ams::os::WaitAny), std::forward<Args>(args)...).second;
|
||||
}
|
||||
|
||||
template<typename... Args> requires (sizeof...(Args) > 0)
|
||||
inline std::pair<MultiWaitHolderType *, int> TryWaitAny(MultiWaitType *multi_wait, Args &&... args) {
|
||||
return impl::WaitAnyImpl(static_cast<impl::WaitAnyFunction>(&::ams::os::TryWaitAny), multi_wait, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args> requires (sizeof...(Args) > 0)
|
||||
inline impl::NotBoolButInt TryWaitAny(Args &&... args) {
|
||||
return impl::WaitAnyImpl(static_cast<impl::WaitAnyFunction>(&::ams::os::TryWaitAny), std::forward<Args>(args)...).second;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_mutex_common.hpp>
|
||||
#include <stratosphere/os/os_mutex_types.hpp>
|
||||
#include <stratosphere/os/os_mutex_api.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class Mutex {
|
||||
NON_COPYABLE(Mutex);
|
||||
NON_MOVEABLE(Mutex);
|
||||
private:
|
||||
MutexType m_mutex;
|
||||
public:
|
||||
constexpr explicit Mutex(bool recursive) : m_mutex{::ams::os::MutexType::State_Initialized, recursive, 0, 0, nullptr, { AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CONSTANT_INITIALIZER } } { /* ... */ }
|
||||
|
||||
~Mutex() { FinalizeMutex(std::addressof(m_mutex)); }
|
||||
|
||||
void lock() {
|
||||
return LockMutex(std::addressof(m_mutex));
|
||||
}
|
||||
|
||||
void unlock() {
|
||||
return UnlockMutex(std::addressof(m_mutex));
|
||||
}
|
||||
|
||||
bool try_lock() {
|
||||
return TryLockMutex(std::addressof(m_mutex));
|
||||
}
|
||||
|
||||
bool IsLockedByCurrentThread() const {
|
||||
return IsMutexLockedByCurrentThread(std::addressof(m_mutex));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void Lock() {
|
||||
return this->lock();
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void Unlock() {
|
||||
return this->unlock();
|
||||
}
|
||||
|
||||
ALWAYS_INLINE bool TryLock() {
|
||||
return this->try_lock();
|
||||
}
|
||||
|
||||
operator MutexType &() {
|
||||
return m_mutex;
|
||||
}
|
||||
|
||||
operator const MutexType &() const {
|
||||
return m_mutex;
|
||||
}
|
||||
|
||||
MutexType *GetBase() {
|
||||
return std::addressof(m_mutex);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_mutex_common.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct MutexType;
|
||||
|
||||
void InitializeMutex(MutexType *mutex, bool recursive, int lock_level);
|
||||
void FinalizeMutex(MutexType *mutex);
|
||||
|
||||
void LockMutex(MutexType *mutex);
|
||||
bool TryLockMutex(MutexType *mutex);
|
||||
void UnlockMutex(MutexType *mutex);
|
||||
|
||||
bool IsMutexLockedByCurrentThread(const MutexType *mutex);
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
constexpr inline s32 MutexLockLevelMin = 1;
|
||||
constexpr inline s32 MutexLockLevelMax = BITSIZEOF(s32) - 1;
|
||||
constexpr inline s32 MutexLockLevelInitial = 0;
|
||||
|
||||
constexpr inline s32 MutexRecursiveLockCountMax = (1 << BITSIZEOF(u16)) - 1;
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct ThreadType;
|
||||
|
||||
struct MutexType {
|
||||
enum State {
|
||||
State_NotInitialized = 0,
|
||||
State_Initialized = 1,
|
||||
};
|
||||
|
||||
u8 state;
|
||||
bool is_recursive;
|
||||
s32 lock_level;
|
||||
s32 nest_count;
|
||||
ThreadType *owner_thread;
|
||||
union {
|
||||
s32 _arr[sizeof(impl::InternalCriticalSectionStorage) / sizeof(s32)];
|
||||
impl::InternalCriticalSectionStorage _storage;
|
||||
impl::InternalCriticalSectionStorageTypeForConstantInitialize _storage_for_constant_initialize;
|
||||
};
|
||||
};
|
||||
static_assert(std::is_trivial<MutexType>::value);
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_native_handle_types.hpp>
|
||||
#include <stratosphere/os/os_native_handle_api.hpp>
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_native_handle_types.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
void CloseNativeHandle(NativeHandle handle);
|
||||
|
||||
NativeHandle GetCurrentProcessHandle();
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
|
||||
using NativeHandle = svc::Handle;
|
||||
static_assert(std::unsigned_integral<NativeHandle>);
|
||||
|
||||
constexpr inline NativeHandle InvalidNativeHandle = svc::InvalidHandle;
|
||||
|
||||
#elif defined(ATMOSPHERE_OS_WINDOWS)
|
||||
|
||||
using NativeHandle = void *;
|
||||
|
||||
constexpr inline NativeHandle InvalidNativeHandle = nullptr;
|
||||
|
||||
#elif defined(ATMOSPHERE_OS_LINUX) || defined(ATMOSPHERE_OS_MACOS)
|
||||
|
||||
using NativeHandle = s32;
|
||||
|
||||
constexpr inline NativeHandle InvalidNativeHandle = -1;
|
||||
|
||||
#else
|
||||
#error "Unknown OS for os::NativeHandle"
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_native_handle.hpp>
|
||||
#include <stratosphere/os/os_memory_common.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct ProcessMemoryRegion {
|
||||
u64 address;
|
||||
u64 size;
|
||||
};
|
||||
|
||||
Result MapProcessCodeMemory(u64 *out, NativeHandle handle, const ProcessMemoryRegion *regions, size_t num_regions, AddressSpaceGenerateRandomFunction generate_random);
|
||||
Result UnmapProcessCodeMemory(NativeHandle handle, u64 process_code_address, const ProcessMemoryRegion *regions, size_t num_regions);
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_native_handle.hpp>
|
||||
#include <stratosphere/ncm/ncm_program_id.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
Result GetProcessId(os::ProcessId *out, NativeHandle handle);
|
||||
|
||||
ALWAYS_INLINE ProcessId GetProcessId(NativeHandle handle) {
|
||||
ProcessId process_id;
|
||||
R_ABORT_UNLESS(GetProcessId(std::addressof(process_id), handle));
|
||||
return process_id;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE ProcessId GetCurrentProcessId() {
|
||||
return GetProcessId(GetCurrentProcessHandle());
|
||||
}
|
||||
|
||||
Result GetProgramId(ncm::ProgramId *out, NativeHandle handle);
|
||||
|
||||
ALWAYS_INLINE ncm::ProgramId GetProgramId(NativeHandle handle) {
|
||||
ncm::ProgramId program_id;
|
||||
R_ABORT_UNLESS(GetProgramId(std::addressof(program_id), handle));
|
||||
return program_id;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE ncm::ProgramId GetCurrentProgramId() {
|
||||
return GetProgramId(GetCurrentProcessHandle());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_native_handle.hpp>
|
||||
#include <stratosphere/os/os_memory_common.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
Result MapProcessMemory(void **out, NativeHandle handle, u64 process_address, size_t process_size, AddressSpaceGenerateRandomFunction generate_random);
|
||||
void UnmapProcessMemory(void *mapped_memory, NativeHandle handle, u64 process_address, size_t process_size);
|
||||
|
||||
Result SetProcessMemoryPermission(NativeHandle handle, u64 process_address, u64 process_size, MemoryPermission perm);
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_common_types.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
void GenerateRandomBytes(void *dst, size_t size);
|
||||
|
||||
/* Convenience API. */
|
||||
u32 GenerateRandomU32(u32 max = std::numeric_limits<u32>::max());
|
||||
u64 GenerateRandomU64(u64 max = std::numeric_limits<u64>::max());
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_rw_busy_mutex_types.hpp>
|
||||
#include <stratosphere/os/os_rw_busy_mutex_api.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class ReaderWriterBusyMutex {
|
||||
NON_COPYABLE(ReaderWriterBusyMutex);
|
||||
NON_MOVEABLE(ReaderWriterBusyMutex);
|
||||
private:
|
||||
ReaderWriterBusyMutexType m_rw_mutex;
|
||||
public:
|
||||
constexpr explicit ReaderWriterBusyMutex() : m_rw_mutex{ { AMS_OS_INTERNAL_READER_WRITER_BUSY_MUTEX_IMPL_CONSTANT_INITIALIZER } } { /* ... */ }
|
||||
|
||||
void AcquireReadLock() {
|
||||
return os::AcquireReadLockBusyMutex(std::addressof(m_rw_mutex));
|
||||
}
|
||||
|
||||
void ReleaseReadLock() {
|
||||
return os::ReleaseReadLockBusyMutex(std::addressof(m_rw_mutex));
|
||||
}
|
||||
|
||||
void AcquireWriteLock() {
|
||||
return os::AcquireWriteLockBusyMutex(std::addressof(m_rw_mutex));
|
||||
}
|
||||
|
||||
void ReleaseWriteLock() {
|
||||
return os::ReleaseWriteLockBusyMutex(std::addressof(m_rw_mutex));
|
||||
}
|
||||
|
||||
void lock_shared() {
|
||||
return this->AcquireReadLock();
|
||||
}
|
||||
|
||||
void unlock_shared() {
|
||||
return this->ReleaseReadLock();
|
||||
}
|
||||
|
||||
void lock() {
|
||||
return this->AcquireWriteLock();
|
||||
}
|
||||
|
||||
void unlock() {
|
||||
return this->ReleaseWriteLock();
|
||||
}
|
||||
|
||||
operator ReaderWriterBusyMutexType &() {
|
||||
return m_rw_mutex;
|
||||
}
|
||||
|
||||
operator const ReaderWriterBusyMutexType &() const {
|
||||
return m_rw_mutex;
|
||||
}
|
||||
|
||||
ReaderWriterBusyMutexType *GetBase() {
|
||||
return std::addressof(m_rw_mutex);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct ReaderWriterBusyMutexType;
|
||||
|
||||
void InitalizeReaderWriterLockBusyMutex(ReaderWriterBusyMutexType *rw_mutex);
|
||||
|
||||
void AcquireReadLockBusyMutex(ReaderWriterBusyMutexType *rw_mutex);
|
||||
void ReleaseReadLockBusyMutex(ReaderWriterBusyMutexType *rw_mutex);
|
||||
|
||||
void AcquireWriteLockBusyMutex(ReaderWriterBusyMutexType *rw_mutex);
|
||||
void ReleaseWriteLockBusyMutex(ReaderWriterBusyMutexType *rw_mutex);
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_rw_busy_mutex.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct ReaderWriterBusyMutexType {
|
||||
union {
|
||||
s32 _arr[sizeof(impl::InternalReaderWriterBusyMutexStorage) / sizeof(s32)];
|
||||
impl::InternalReaderWriterBusyMutexStorage _storage;
|
||||
};
|
||||
};
|
||||
static_assert(std::is_trivial<ReaderWriterBusyMutexType>::value);
|
||||
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_rw_lock_common.hpp>
|
||||
#include <stratosphere/os/os_rw_lock_types.hpp>
|
||||
#include <stratosphere/os/os_rw_lock_api.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class ReaderWriterLock {
|
||||
NON_COPYABLE(ReaderWriterLock);
|
||||
NON_MOVEABLE(ReaderWriterLock);
|
||||
private:
|
||||
ReaderWriterLockType m_rw_lock;
|
||||
public:
|
||||
constexpr explicit ReaderWriterLock() : m_rw_lock {{ { MakeConstantInitializedLockCount(), 0 } }, 0, ::ams::os::ReaderWriterLockType::State_Initialized, nullptr, 0, {AMS_OS_INTERNAL_CONDITION_VARIABLE_IMPL_CONSTANT_INITIALIZER}, {AMS_OS_INTERNAL_CONDITION_VARIABLE_IMPL_CONSTANT_INITIALIZER} } {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
constexpr ~ReaderWriterLock() {
|
||||
if (!std::is_constant_evaluated()) {
|
||||
os::FinalizeReaderWriterLock(std::addressof(m_rw_lock));
|
||||
}
|
||||
}
|
||||
|
||||
void AcquireReadLock() {
|
||||
return os::AcquireReadLock(std::addressof(m_rw_lock));
|
||||
}
|
||||
|
||||
bool TryAcquireReadLock() {
|
||||
return os::TryAcquireReadLock(std::addressof(m_rw_lock));
|
||||
}
|
||||
|
||||
void ReleaseReadLock() {
|
||||
return os::ReleaseReadLock(std::addressof(m_rw_lock));
|
||||
}
|
||||
|
||||
void AcquireWriteLock() {
|
||||
return os::AcquireWriteLock(std::addressof(m_rw_lock));
|
||||
}
|
||||
|
||||
bool TryAcquireWriteLock() {
|
||||
return os::TryAcquireWriteLock(std::addressof(m_rw_lock));
|
||||
}
|
||||
|
||||
void ReleaseWriteLock() {
|
||||
return os::ReleaseWriteLock(std::addressof(m_rw_lock));
|
||||
}
|
||||
|
||||
bool IsReadLockHeld() const {
|
||||
return os::IsReadLockHeld(std::addressof(m_rw_lock));
|
||||
}
|
||||
|
||||
bool IsWriteLockHeldByCurrentThread() const {
|
||||
return os::IsWriteLockHeldByCurrentThread(std::addressof(m_rw_lock));
|
||||
}
|
||||
|
||||
bool IsLockOwner() const {
|
||||
return os::IsReaderWriterLockOwnerThread(std::addressof(m_rw_lock));
|
||||
}
|
||||
|
||||
void lock_shared() {
|
||||
return this->AcquireReadLock();
|
||||
}
|
||||
|
||||
bool try_lock_shared() {
|
||||
return this->TryAcquireReadLock();
|
||||
}
|
||||
|
||||
void unlock_shared() {
|
||||
return this->ReleaseReadLock();
|
||||
}
|
||||
|
||||
void lock() {
|
||||
return this->AcquireWriteLock();
|
||||
}
|
||||
|
||||
bool try_lock() {
|
||||
return this->TryAcquireWriteLock();
|
||||
}
|
||||
|
||||
void unlock() {
|
||||
return this->ReleaseWriteLock();
|
||||
}
|
||||
|
||||
operator ReaderWriterLockType &() {
|
||||
return m_rw_lock;
|
||||
}
|
||||
|
||||
operator const ReaderWriterLockType &() const {
|
||||
return m_rw_lock;
|
||||
}
|
||||
|
||||
ReaderWriterLockType *GetBase() {
|
||||
return std::addressof(m_rw_lock);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_rw_lock_common.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct ReaderWriterLockType;
|
||||
|
||||
void InitializeReaderWriterLock(ReaderWriterLockType *rw_lock);
|
||||
void FinalizeReaderWriterLock(ReaderWriterLockType *rw_lock);
|
||||
|
||||
void AcquireReadLock(ReaderWriterLockType *rw_lock);
|
||||
bool TryAcquireReadLock(ReaderWriterLockType *rw_lock);
|
||||
void ReleaseReadLock(ReaderWriterLockType *rw_lock);
|
||||
|
||||
void AcquireWriteLock(ReaderWriterLockType *rw_lock);
|
||||
bool TryAcquireWriteLock(ReaderWriterLockType *rw_lock);
|
||||
void ReleaseWriteLock(ReaderWriterLockType *rw_lock);
|
||||
|
||||
bool IsReadLockHeld(const ReaderWriterLockType *rw_lock);
|
||||
bool IsWriteLockHeldByCurrentThread(const ReaderWriterLockType *rw_lock);
|
||||
bool IsReaderWriterLockOwnerThread(const ReaderWriterLockType *rw_lock);
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
constexpr inline s32 ReaderWriterLockCountMax = (1 << (BITSIZEOF(u16) - 1)) - 1;
|
||||
constexpr inline s32 ReaderWriterLockWaiterCountMax = (1 << BITSIZEOF(u8)) - 1;
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_condition_variable.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct ThreadType;
|
||||
|
||||
struct ReaderWriterLockType {
|
||||
enum State {
|
||||
State_NotInitialized = 0,
|
||||
State_Initialized = 1,
|
||||
};
|
||||
|
||||
struct LockCount {
|
||||
union {
|
||||
s32 _arr[sizeof(impl::InternalCriticalSectionStorage) / sizeof(s32)];
|
||||
impl::InternalCriticalSectionStorage cs_storage;
|
||||
impl::InternalCriticalSectionStorageTypeForConstantInitialize _storage_for_constant_initialize;
|
||||
};
|
||||
util::BitPack32 counter;
|
||||
};
|
||||
static_assert(util::is_pod<LockCount>::value);
|
||||
static_assert(std::is_trivial<LockCount>::value);
|
||||
|
||||
union {
|
||||
struct {
|
||||
LockCount c;
|
||||
u32 write_lock_count;
|
||||
} aligned;
|
||||
struct {
|
||||
u32 write_lock_count;
|
||||
LockCount c;
|
||||
} not_aligned;
|
||||
} lock_count;
|
||||
|
||||
u32 reserved_1;
|
||||
|
||||
u8 state;
|
||||
ThreadType *owner_thread;
|
||||
u32 reserved_2;
|
||||
|
||||
union {
|
||||
s32 _arr[sizeof(impl::InternalConditionVariableStorage) / sizeof(s32)];
|
||||
impl::InternalConditionVariableStorage _storage;
|
||||
impl::InternalConditionVariableStorageTypeForConstantInitialize _storage_for_constant_initialize;
|
||||
} cv_read_lock;
|
||||
union {
|
||||
s32 _arr[sizeof(impl::InternalConditionVariableStorage) / sizeof(s32)];
|
||||
impl::InternalConditionVariableStorage _storage;
|
||||
impl::InternalConditionVariableStorageTypeForConstantInitialize _storage_for_constant_initialize;
|
||||
} cv_write_lock;
|
||||
};
|
||||
static_assert(std::is_trivial<ReaderWriterLockType>::value);
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
consteval ReaderWriterLockType::LockCount MakeConstantInitializedLockCount() { return {}; }
|
||||
#elif defined(ATMOSPHERE_OS_WINDOWS) || defined(ATMOSPHERE_OS_LINUX) || defined(ATMOSPHERE_OS_MACOS)
|
||||
/* If windows/linux, require that the lock counter have guaranteed alignment, so that we may constant-initialize. */
|
||||
static_assert(alignof(ReaderWriterLockType) == sizeof(u64));
|
||||
consteval ReaderWriterLockType::LockCount MakeConstantInitializedLockCount() {
|
||||
return ReaderWriterLockType::LockCount {
|
||||
{ AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CONSTANT_INITIALIZER },
|
||||
{},
|
||||
};
|
||||
}
|
||||
#else
|
||||
#error "Unknown OS for constant initialized RW-lock LockCount"
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_sdk_mutex.hpp>
|
||||
#include <stratosphere/os/os_sdk_recursive_mutex.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_condition_variable.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct SdkConditionVariableType {
|
||||
union {
|
||||
s32 _arr[sizeof(impl::InternalConditionVariableStorage) / sizeof(s32)];
|
||||
impl::InternalConditionVariableStorage _storage;
|
||||
impl::InternalConditionVariableStorageTypeForConstantInitialize _storage_for_constant_initialize;
|
||||
};
|
||||
|
||||
ALWAYS_INLINE void Initialize() {
|
||||
GetReference(this->_storage).Initialize();
|
||||
}
|
||||
|
||||
void Wait(SdkMutexType &mutex);
|
||||
bool TimedWait(SdkMutexType &mutex, TimeSpan timeout);
|
||||
|
||||
void Wait(SdkRecursiveMutexType &mutex);
|
||||
bool TimedWait(SdkRecursiveMutexType &mutex, TimeSpan timeout);
|
||||
|
||||
ALWAYS_INLINE void Signal() {
|
||||
GetReference(this->_storage).Signal();
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void Broadcast() {
|
||||
GetReference(this->_storage).Broadcast();
|
||||
}
|
||||
};
|
||||
static_assert(std::is_trivial<SdkConditionVariableType>::value);
|
||||
|
||||
class SdkConditionVariable {
|
||||
private:
|
||||
SdkConditionVariableType m_cv;
|
||||
public:
|
||||
constexpr SdkConditionVariable() : m_cv{{AMS_OS_INTERNAL_CONDITION_VARIABLE_IMPL_CONSTANT_INITIALIZER}} { /* ... */ }
|
||||
|
||||
ALWAYS_INLINE void Wait(SdkMutex &m) {
|
||||
return m_cv.Wait(m.m_mutex);
|
||||
}
|
||||
|
||||
ALWAYS_INLINE bool TimedWait(SdkMutex &m, TimeSpan timeout) {
|
||||
return m_cv.TimedWait(m.m_mutex, timeout);
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void Wait(SdkRecursiveMutex &m) {
|
||||
return m_cv.Wait(m.m_mutex);
|
||||
}
|
||||
|
||||
ALWAYS_INLINE bool TimedWait(SdkRecursiveMutex &m, TimeSpan timeout) {
|
||||
return m_cv.TimedWait(m.m_mutex, timeout);
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void Signal() {
|
||||
return m_cv.Signal();
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void Broadcast() {
|
||||
return m_cv.Broadcast();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class SdkConditionVariable;
|
||||
|
||||
struct ThreadType;
|
||||
|
||||
struct SdkMutexType {
|
||||
#if !defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
|
||||
os::ThreadType *owner_thread;
|
||||
#endif
|
||||
union {
|
||||
s32 _arr[sizeof(impl::InternalCriticalSectionStorage) / sizeof(s32)];
|
||||
impl::InternalCriticalSectionStorage _storage;
|
||||
impl::InternalCriticalSectionStorageTypeForConstantInitialize _storage_for_constant_initialize;
|
||||
};
|
||||
};
|
||||
static_assert(std::is_trivial<SdkMutexType>::value);
|
||||
|
||||
void InitializeSdkMutex(SdkMutexType *mutex);
|
||||
|
||||
void LockSdkMutex(SdkMutexType *mutex);
|
||||
bool TryLockSdkMutex(SdkMutexType *mutex);
|
||||
void UnlockSdkMutex(SdkMutexType *mutex);
|
||||
|
||||
bool IsSdkMutexLockedByCurrentThread(const SdkMutexType *mutex);
|
||||
|
||||
class SdkMutex {
|
||||
private:
|
||||
friend class SdkConditionVariable;
|
||||
private:
|
||||
SdkMutexType m_mutex;
|
||||
public:
|
||||
#if defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
|
||||
constexpr SdkMutex() : m_mutex{{AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CONSTANT_INITIALIZER}} { /* ... */ }
|
||||
#else
|
||||
constexpr SdkMutex() : m_mutex{nullptr, {AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CONSTANT_INITIALIZER}} { /* ... */ }
|
||||
#endif
|
||||
|
||||
ALWAYS_INLINE void Lock() { return os::LockSdkMutex(std::addressof(m_mutex)); }
|
||||
ALWAYS_INLINE bool TryLock() { return os::TryLockSdkMutex(std::addressof(m_mutex)); }
|
||||
ALWAYS_INLINE void Unlock() { return os::UnlockSdkMutex(std::addressof(m_mutex)); }
|
||||
|
||||
ALWAYS_INLINE bool IsLockedByCurrentThread() const { return os::IsSdkMutexLockedByCurrentThread(std::addressof(m_mutex)); }
|
||||
|
||||
ALWAYS_INLINE void lock() { return this->Lock(); }
|
||||
ALWAYS_INLINE bool try_lock() { return this->TryLock(); }
|
||||
ALWAYS_INLINE void unlock() { return this->Unlock(); }
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
class SdkConditionVariable;
|
||||
|
||||
struct SdkRecursiveMutexType {
|
||||
#if !defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
|
||||
os::ThreadType *owner_thread;
|
||||
#endif
|
||||
union {
|
||||
s32 _arr[sizeof(impl::InternalCriticalSectionStorage) / sizeof(s32)];
|
||||
impl::InternalCriticalSectionStorage _storage;
|
||||
impl::InternalCriticalSectionStorageTypeForConstantInitialize _storage_for_constant_initialize;
|
||||
};
|
||||
u32 recursive_count;
|
||||
};
|
||||
static_assert(std::is_trivial<SdkRecursiveMutexType>::value);
|
||||
|
||||
void InitializeSdkRecursiveMutex(SdkRecursiveMutexType *rmutex);
|
||||
|
||||
void LockSdkRecursiveMutex(SdkRecursiveMutexType *rmutex);
|
||||
bool TryLockSdkRecursiveMutex(SdkRecursiveMutexType *rmutex);
|
||||
void UnlockSdkRecursiveMutex(SdkRecursiveMutexType *rmutex);
|
||||
|
||||
bool IsSdkRecursiveMutexLockedByCurrentThread(const SdkRecursiveMutexType *rmutex);
|
||||
|
||||
class SdkRecursiveMutex {
|
||||
private:
|
||||
friend class SdkConditionVariable;
|
||||
private:
|
||||
SdkRecursiveMutexType m_mutex;
|
||||
public:
|
||||
#if defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
|
||||
constexpr SdkRecursiveMutex() : m_mutex{ { AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CONSTANT_INITIALIZER }, 0 } { /* ... */ }
|
||||
#else
|
||||
constexpr SdkRecursiveMutex() : m_mutex{ nullptr, { AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CONSTANT_INITIALIZER }, 0 } { /* ... */ }
|
||||
#endif
|
||||
|
||||
ALWAYS_INLINE void Lock() { return os::LockSdkRecursiveMutex(std::addressof(m_mutex)); }
|
||||
ALWAYS_INLINE bool TryLock() { return os::TryLockSdkRecursiveMutex(std::addressof(m_mutex)); }
|
||||
ALWAYS_INLINE void Unlock() { return os::UnlockSdkRecursiveMutex(std::addressof(m_mutex)); }
|
||||
|
||||
ALWAYS_INLINE bool IsLockedByCurrentThread() const { return os::IsSdkRecursiveMutexLockedByCurrentThread(std::addressof(m_mutex)); }
|
||||
|
||||
ALWAYS_INLINE void lock() { return this->Lock(); }
|
||||
ALWAYS_INLINE bool try_lock() { return this->TryLock(); }
|
||||
ALWAYS_INLINE void unlock() { return this->Unlock(); }
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os/os_native_handle.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
struct MultiWaitHolderType;
|
||||
struct MultiWaitType;
|
||||
|
||||
Result SdkReplyAndReceive(os::MultiWaitHolderType **out, NativeHandle reply_target, MultiWaitType *multi_wait);
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_common_types.hpp>
|
||||
#include <stratosphere/os/os_thread_types.hpp>
|
||||
#include <stratosphere/os/os_sdk_thread_types.hpp>
|
||||
#include <stratosphere/os/os_thread_local_storage_common.hpp>
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
ALWAYS_INLINE SdkInternalTlsType *GetSdkInternalTlsArray(ThreadType *thread = os::GetCurrentThread()) {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
return std::addressof(thread->sdk_internal_tls);
|
||||
#else
|
||||
return reinterpret_cast<SdkInternalTlsType *>(std::addressof(thread->tls_value_array[TlsSlotCountMax]));
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stratosphere/os/os_sdk_thread_info_types.hpp>
|
||||
#include <stratosphere/os/os_sdk_thread_info_api.hpp>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user