early-access version 2663

This commit is contained in:
pineappleEA 2022-04-08 07:23:38 +02:00
parent 9445c0b066
commit f9f5321781
12 changed files with 35 additions and 24 deletions

View File

@ -1,7 +1,7 @@
yuzu emulator early access yuzu emulator early access
============= =============
This is the source code for early-access 2662. This is the source code for early-access 2663.
## Legal Notice ## Legal Notice

View File

@ -65,12 +65,14 @@ if (MSVC)
/we4305 # 'context': truncation from 'type1' to 'type2' /we4305 # 'context': truncation from 'type1' to 'type2'
/we4388 # 'expression': signed/unsigned mismatch /we4388 # 'expression': signed/unsigned mismatch
/we4389 # 'operator': signed/unsigned mismatch /we4389 # 'operator': signed/unsigned mismatch
/we4505 # 'function': unreferenced local function has been removed
/we4547 # 'operator': operator before comma has no effect; expected operator with side-effect /we4547 # 'operator': operator before comma has no effect; expected operator with side-effect
/we4549 # 'operator1': operator before comma has no effect; did you intend 'operator2'? /we4549 # 'operator1': operator before comma has no effect; did you intend 'operator2'?
/we4555 # Expression has no effect; expected expression with side-effect /we4555 # Expression has no effect; expected expression with side-effect
/we4715 # 'function': not all control paths return a value /we4715 # 'function': not all control paths return a value
/we4834 # Discarding return value of function with 'nodiscard' attribute /we4834 # Discarding return value of function with 'nodiscard' attribute
/we5038 # data member 'member1' will be initialized after data member 'member2' /we5038 # data member 'member1' will be initialized after data member 'member2'
/we5245 # 'function': unreferenced function with internal linkage has been removed
) )
if (ARCHITECTURE_x86_64) if (ARCHITECTURE_x86_64)

View File

@ -2,10 +2,9 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <mutex>
#include "common/assert.h" #include "common/assert.h"
#include "common/fiber.h" #include "common/fiber.h"
#include "common/spin_lock.h"
#include "common/virtual_buffer.h" #include "common/virtual_buffer.h"
#include <boost/context/detail/fcontext.hpp> #include <boost/context/detail/fcontext.hpp>
@ -20,7 +19,7 @@ struct Fiber::FiberImpl {
VirtualBuffer<u8> stack; VirtualBuffer<u8> stack;
VirtualBuffer<u8> rewind_stack; VirtualBuffer<u8> rewind_stack;
std::mutex guard; SpinLock guard{};
std::function<void(void*)> entry_point; std::function<void(void*)> entry_point;
std::function<void(void*)> rewind_point; std::function<void(void*)> rewind_point;
void* rewind_parameter{}; void* rewind_parameter{};

View File

@ -8,13 +8,13 @@
#include <chrono> #include <chrono>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <mutex>
#include <optional> #include <optional>
#include <string> #include <string>
#include <thread> #include <thread>
#include <vector> #include <vector>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/spin_lock.h"
#include "common/thread.h" #include "common/thread.h"
#include "common/wall_clock.h" #include "common/wall_clock.h"
@ -149,8 +149,8 @@ private:
std::shared_ptr<EventType> ev_lost; std::shared_ptr<EventType> ev_lost;
Common::Event event{}; Common::Event event{};
Common::Event pause_event{}; Common::Event pause_event{};
std::mutex basic_lock; Common::SpinLock basic_lock{};
std::mutex advance_lock; Common::SpinLock advance_lock{};
std::unique_ptr<std::thread> timer_thread; std::unique_ptr<std::thread> timer_thread;
std::atomic<bool> paused{}; std::atomic<bool> paused{};
std::atomic<bool> paused_set{}; std::atomic<bool> paused_set{};

View File

@ -8,6 +8,7 @@
#include <vector> #include <vector>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/spin_lock.h"
#include "core/hardware_properties.h" #include "core/hardware_properties.h"
#include "core/hle/kernel/k_priority_queue.h" #include "core/hle/kernel/k_priority_queue.h"
#include "core/hle/kernel/k_scheduler_lock.h" #include "core/hle/kernel/k_scheduler_lock.h"
@ -79,7 +80,7 @@ private:
/// Lists all thread ids that aren't deleted/etc. /// Lists all thread ids that aren't deleted/etc.
std::vector<KThread*> thread_list; std::vector<KThread*> thread_list;
std::mutex global_list_guard; Common::SpinLock global_list_guard{};
}; };
} // namespace Kernel } // namespace Kernel

View File

@ -705,7 +705,7 @@ void KScheduler::Unload(KThread* thread) {
prev_thread = nullptr; prev_thread = nullptr;
} }
thread->context_guard.unlock(); thread->context_guard.Unlock();
} }
void KScheduler::Reload(KThread* thread) { void KScheduler::Reload(KThread* thread) {
@ -794,13 +794,13 @@ void KScheduler::SwitchToCurrent() {
do { do {
auto next_thread = current_thread.load(); auto next_thread = current_thread.load();
if (next_thread != nullptr) { if (next_thread != nullptr) {
const auto locked = next_thread->context_guard.try_lock(); const auto locked = next_thread->context_guard.TryLock();
if (state.needs_scheduling.load()) { if (state.needs_scheduling.load()) {
next_thread->context_guard.unlock(); next_thread->context_guard.Unlock();
break; break;
} }
if (next_thread->GetActiveCore() != core_id) { if (next_thread->GetActiveCore() != core_id) {
next_thread->context_guard.unlock(); next_thread->context_guard.Unlock();
break; break;
} }
if (!locked) { if (!locked) {

View File

@ -35,15 +35,20 @@ void ThreadPause() {
namespace Kernel { namespace Kernel {
void KSpinLock::Lock() { void KSpinLock::Lock() {
lck.lock(); while (lck.test_and_set(std::memory_order_acquire)) {
ThreadPause();
}
} }
void KSpinLock::Unlock() { void KSpinLock::Unlock() {
lck.unlock(); lck.clear(std::memory_order_release);
} }
bool KSpinLock::TryLock() { bool KSpinLock::TryLock() {
return lck.try_lock(); if (lck.test_and_set(std::memory_order_acquire)) {
return false;
}
return true;
} }
} // namespace Kernel } // namespace Kernel

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#include <mutex> #include <atomic>
#include "core/hle/kernel/k_scoped_lock.h" #include "core/hle/kernel/k_scoped_lock.h"
@ -25,7 +25,7 @@ public:
[[nodiscard]] bool TryLock(); [[nodiscard]] bool TryLock();
private: private:
std::mutex lck; std::atomic_flag lck = ATOMIC_FLAG_INIT;
}; };
// TODO(bunnei): Alias for now, in case we want to implement these accurately in the future. // TODO(bunnei): Alias for now, in case we want to implement these accurately in the future.

View File

@ -15,7 +15,6 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "common/intrusive_red_black_tree.h" #include "common/intrusive_red_black_tree.h"
#include "common/spin_lock.h"
#include "core/arm/arm_interface.h" #include "core/arm/arm_interface.h"
#include "core/hle/kernel/k_affinity_mask.h" #include "core/hle/kernel/k_affinity_mask.h"
#include "core/hle/kernel/k_light_lock.h" #include "core/hle/kernel/k_light_lock.h"
@ -763,7 +762,7 @@ private:
s8 priority_inheritance_count{}; s8 priority_inheritance_count{};
bool resource_limit_release_hint{}; bool resource_limit_release_hint{};
StackParameters stack_parameters{}; StackParameters stack_parameters{};
Common::SpinLock context_guard{}; KSpinLock context_guard{};
KSpinLock dummy_wait_lock{}; KSpinLock dummy_wait_lock{};
// For emulation // For emulation

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "common/spin_lock.h"
#include "core/arm/cpu_interrupt_handler.h" #include "core/arm/cpu_interrupt_handler.h"
#include "core/arm/dynarmic/arm_dynarmic_32.h" #include "core/arm/dynarmic/arm_dynarmic_32.h"
#include "core/arm/dynarmic/arm_dynarmic_64.h" #include "core/arm/dynarmic/arm_dynarmic_64.h"
@ -15,7 +16,7 @@ namespace Kernel {
PhysicalCore::PhysicalCore(std::size_t core_index_, Core::System& system_, KScheduler& scheduler_, PhysicalCore::PhysicalCore(std::size_t core_index_, Core::System& system_, KScheduler& scheduler_,
Core::CPUInterrupts& interrupts_) Core::CPUInterrupts& interrupts_)
: core_index{core_index_}, system{system_}, scheduler{scheduler_}, : core_index{core_index_}, system{system_}, scheduler{scheduler_},
interrupts{interrupts_}, guard{std::make_unique<std::mutex>()} { interrupts{interrupts_}, guard{std::make_unique<Common::SpinLock>()} {
#ifdef ARCHITECTURE_x86_64 #ifdef ARCHITECTURE_x86_64
// TODO(bunnei): Initialization relies on a core being available. We may later replace this with // TODO(bunnei): Initialization relies on a core being available. We may later replace this with
// a 32-bit instance of Dynarmic. This should be abstracted out to a CPU manager. // a 32-bit instance of Dynarmic. This should be abstracted out to a CPU manager.

View File

@ -6,10 +6,13 @@
#include <cstddef> #include <cstddef>
#include <memory> #include <memory>
#include <mutex>
#include "core/arm/arm_interface.h" #include "core/arm/arm_interface.h"
namespace Common {
class SpinLock;
}
namespace Kernel { namespace Kernel {
class KScheduler; class KScheduler;
} // namespace Kernel } // namespace Kernel
@ -88,7 +91,7 @@ private:
Core::System& system; Core::System& system;
Kernel::KScheduler& scheduler; Kernel::KScheduler& scheduler;
Core::CPUInterrupts& interrupts; Core::CPUInterrupts& interrupts;
std::unique_ptr<std::mutex> guard; std::unique_ptr<Common::SpinLock> guard;
std::unique_ptr<Core::ARM_Interface> arm_interface; std::unique_ptr<Core::ARM_Interface> arm_interface;
}; };

View File

@ -9,6 +9,7 @@
#include <string> #include <string>
#include <boost/container/flat_map.hpp> #include <boost/container/flat_map.hpp>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/spin_lock.h"
#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/hle_ipc.h"
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
@ -89,7 +90,7 @@ protected:
using HandlerFnP = void (Self::*)(Kernel::HLERequestContext&); using HandlerFnP = void (Self::*)(Kernel::HLERequestContext&);
/// Used to gain exclusive access to the service members, e.g. from CoreTiming thread. /// Used to gain exclusive access to the service members, e.g. from CoreTiming thread.
[[nodiscard]] std::scoped_lock<std::mutex> LockService() { [[nodiscard]] std::scoped_lock<Common::SpinLock> LockService() {
return std::scoped_lock{lock_service}; return std::scoped_lock{lock_service};
} }
@ -134,7 +135,7 @@ private:
boost::container::flat_map<u32, FunctionInfoBase> handlers_tipc; boost::container::flat_map<u32, FunctionInfoBase> handlers_tipc;
/// Used to gain exclusive access to the service members, e.g. from CoreTiming thread. /// Used to gain exclusive access to the service members, e.g. from CoreTiming thread.
std::mutex lock_service; Common::SpinLock lock_service;
}; };
/** /**