mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-07-04 16:42:14 +02:00
Stratosphere: Replace more raw loops with algorithms
This commit is contained in:
parent
c10dca48fe
commit
0de99b0006
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
|
||||
#include "iserviceobject.hpp"
|
||||
@ -51,4 +52,4 @@ class IServer : public IWaitable {
|
||||
this->get_manager()->add_waitable(this->get_new_session(session_h));
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "waitablemanagerbase.hpp"
|
||||
@ -21,13 +23,10 @@ class WaitableManager : public WaitableManagerBase {
|
||||
WaitableManager(u64 t) : waitables(0), timeout(t), has_new_items(false) { }
|
||||
~WaitableManager() override {
|
||||
/* This should call the destructor for every waitable. */
|
||||
for (auto & waitable : waitables) {
|
||||
delete waitable;
|
||||
}
|
||||
waitables.clear();
|
||||
std::for_each(waitables.begin(), waitables.end(), std::default_delete<IWaitable>{});
|
||||
}
|
||||
|
||||
virtual void add_waitable(IWaitable *waitable);
|
||||
virtual void process();
|
||||
virtual void process_until_timeout();
|
||||
};
|
||||
};
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <switch.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
#include <stratosphere/waitablemanager.hpp>
|
||||
|
||||
@ -43,14 +44,10 @@ void WaitableManager::process_internal(bool break_on_timeout) {
|
||||
|
||||
rc = this->waitables[handle_index]->handle_signaled(0);
|
||||
|
||||
for (int i = 0; i < handle_index; i++) {
|
||||
this->waitables[i]->update_priority();
|
||||
}
|
||||
std::for_each(waitables.begin(), waitables.begin() + handle_index, std::mem_fn(&IWaitable::update_priority));
|
||||
} else if (rc == 0xEA01) {
|
||||
/* Timeout. */
|
||||
for (auto & waitable : this->waitables) {
|
||||
waitable->update_priority();
|
||||
}
|
||||
std::for_each(waitables.begin(), waitables.end(), std::mem_fn(&IWaitable::update_priority));
|
||||
if (break_on_timeout) {
|
||||
return;
|
||||
}
|
||||
@ -72,9 +69,7 @@ void WaitableManager::process_internal(bool break_on_timeout) {
|
||||
/* Delete it. */
|
||||
delete to_delete;
|
||||
|
||||
for (int i = 0; i < handle_index; i++) {
|
||||
this->waitables[i]->update_priority();
|
||||
}
|
||||
std::for_each(waitables.begin(), waitables.begin() + handle_index, std::mem_fn(&IWaitable::update_priority));
|
||||
}
|
||||
|
||||
/* Do deferred callback for each waitable. */
|
||||
@ -92,4 +87,4 @@ void WaitableManager::process() {
|
||||
|
||||
void WaitableManager::process_until_timeout() {
|
||||
WaitableManager::process_internal(true);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
#include <switch.h>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdio>
|
||||
#include "ldr_launch_queue.hpp"
|
||||
|
||||
static LaunchQueue::LaunchItem g_launch_queue[LAUNCH_QUEUE_SIZE] = {0};
|
||||
static std::array<LaunchQueue::LaunchItem, LAUNCH_QUEUE_SIZE> g_launch_queue = {0};
|
||||
|
||||
Result LaunchQueue::add(u64 tid, const char *args, u64 arg_size) {
|
||||
if(arg_size > LAUNCH_QUEUE_ARG_SIZE_MAX) {
|
||||
|
@ -190,7 +190,7 @@ bool Registration::IsNroAlreadyLoaded(u64 index, u8 *build_id) {
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < NRO_INFO_MAX; i++) {
|
||||
if (target_process->nro_infos[i].in_use && std::memcmp(target_process->nro_infos[i].build_id, build_id, 0x20) == 0) {
|
||||
if (target_process->nro_infos[i].in_use && std::equal(build_id, build_id + 0x20, target_process->nro_infos[i].build_id)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@
|
||||
#include <stratosphere/servicesession.hpp>
|
||||
#include "sm_registration.hpp"
|
||||
|
||||
static Registration::Process g_process_list[REGISTRATION_LIST_MAX_PROCESS] = {0};
|
||||
static Registration::Service g_service_list[REGISTRATION_LIST_MAX_SERVICE] = {0};
|
||||
static std::array<Registration::Process, REGISTRATION_LIST_MAX_PROCESS> g_process_list = {0};
|
||||
static std::array<Registration::Service, REGISTRATION_LIST_MAX_SERVICE> g_service_list = {0};
|
||||
|
||||
static u64 g_initial_process_id_low = 0;
|
||||
static u64 g_initial_process_id_high = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user