code: Use std::span where appropriate (#6658)

* code: Use std::span when possible

* code: Prefix memcpy and memcmp with std::
This commit is contained in:
GPUCode 2023-07-07 01:52:40 +03:00 committed by GitHub
parent 4ccd9f24fb
commit cf9bb90ae3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
106 changed files with 362 additions and 329 deletions

View file

@ -8,6 +8,7 @@
#include <atomic>
#include <functional>
#include <memory>
#include <span>
#include <string>
#include <unordered_map>
#include <vector>
@ -230,7 +231,7 @@ public:
/// Retrieves a process from the current list of processes.
std::shared_ptr<Process> GetProcessById(u32 process_id) const;
const std::vector<std::shared_ptr<Process>>& GetProcessList() const {
std::span<const std::shared_ptr<Process>> GetProcessList() const {
return process_list;
}

View file

@ -543,13 +543,15 @@ void SVC::ExitProcess() {
current_process->status = ProcessStatus::Exited;
// Stop all the process threads that are currently waiting for objects.
auto& thread_list = kernel.GetCurrentThreadManager().GetThreadList();
const auto thread_list = kernel.GetCurrentThreadManager().GetThreadList();
for (auto& thread : thread_list) {
if (thread->owner_process.lock() != current_process)
if (thread->owner_process.lock() != current_process) {
continue;
}
if (thread.get() == kernel.GetCurrentThreadManager().GetCurrentThread())
if (thread.get() == kernel.GetCurrentThreadManager().GetCurrentThread()) {
continue;
}
// TODO(Subv): When are the other running/ready threads terminated?
ASSERT_MSG(thread->status == ThreadStatus::WaitSynchAny ||
@ -695,7 +697,7 @@ ResultCode SVC::OpenThread(Handle* out_handle, Handle process_handle, u32 thread
}
for (u32 core_id = 0; core_id < system.GetNumCores(); core_id++) {
auto& thread_list = kernel.GetThreadManager(core_id).GetThreadList();
const auto thread_list = kernel.GetThreadManager(core_id).GetThreadList();
for (auto& thread : thread_list) {
if (thread->owner_process.lock() == process && thread.get()->thread_id == thread_id) {
auto result_handle = kernel.GetCurrentProcess()->handle_table.Create(thread);
@ -2092,7 +2094,7 @@ ResultCode SVC::ControlProcess(Handle process_handle, u32 process_OP, u32 varg2,
}
case ControlProcessOP::PROCESSOP_SCHEDULE_THREADS_WITHOUT_TLS_MAGIC: {
for (u32 core_id = 0; core_id < system.GetNumCores(); core_id++) {
auto& thread_list = kernel.GetThreadManager(core_id).GetThreadList();
const auto thread_list = kernel.GetThreadManager(core_id).GetThreadList();
for (auto& thread : thread_list) {
if (thread->owner_process.lock() != process) {
continue;

View file

@ -304,7 +304,7 @@ void ThreadManager::DebugThreadQueue() {
* alloc_needed: Whether there's a need to allocate a new TLS page (All pages are full).
*/
static std::tuple<std::size_t, std::size_t, bool> GetFreeThreadLocalSlot(
const std::vector<std::bitset<8>>& tls_slots) {
std::span<const std::bitset<8>> tls_slots) {
// Iterate over all the allocated pages, and try to find one where not all slots are used.
for (std::size_t page = 0; page < tls_slots.size(); ++page) {
const auto& page_tls_slots = tls_slots[page];
@ -527,7 +527,7 @@ ThreadManager::~ThreadManager() {
}
}
const std::vector<std::shared_ptr<Thread>>& ThreadManager::GetThreadList() {
std::span<const std::shared_ptr<Thread>> ThreadManager::GetThreadList() {
return thread_list;
}

View file

@ -5,6 +5,7 @@
#pragma once
#include <memory>
#include <span>
#include <string>
#include <unordered_map>
#include <vector>
@ -113,7 +114,7 @@ public:
/**
* Get a const reference to the thread list for debug use
*/
const std::vector<std::shared_ptr<Thread>>& GetThreadList();
std::span<const std::shared_ptr<Thread>> GetThreadList();
void SetCPU(ARM_Interface& cpu_) {
cpu = &cpu_;