Merge branch 'bugfix/thread-priorities' into develop

This commit is contained in:
ndeadly 2020-09-27 16:46:29 +02:00
commit f39c4aaa56
5 changed files with 72 additions and 3 deletions

View file

@ -0,0 +1,41 @@
/*
* Copyright (C) 2020 ndeadly
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that 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/>.
*/
#include "bluetoothmitm_utils.hpp"
namespace ams::mitm::utils {
namespace {
constexpr inline s32 TargetThreadPriorityRangeSize = svc::LowestThreadPriority - svc::HighestThreadPriority + 1;
constexpr inline s32 UserThreadPriorityOffset = 28;
constexpr inline s32 HighestTargetThreadPriority = 0;
constexpr inline s32 LowestTargetThreadPriority = TargetThreadPriorityRangeSize - 1;
}
s32 ConvertToHorizonPriority(s32 user_priority) {
const s32 horizon_priority = user_priority + UserThreadPriorityOffset;
AMS_ASSERT(HighestTargetThreadPriority <= horizon_priority && horizon_priority <= LowestTargetThreadPriority);
return horizon_priority;
}
s32 ConvertToUserPriority(s32 horizon_priority) {
AMS_ASSERT(HighestTargetThreadPriority <= horizon_priority && horizon_priority <= LowestTargetThreadPriority);
return horizon_priority - UserThreadPriorityOffset;
}
}

View file

@ -0,0 +1,24 @@
/*
* Copyright (C) 2020 ndeadly
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that 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/>.
*/
#include <stratosphere.hpp>
namespace ams::mitm::utils {
s32 ConvertToHorizonPriority(s32 user_priority);
s32 ConvertToUserPriority(s32 horizon_priority);
}

View file

@ -18,6 +18,7 @@
#include "bluetooth_circular_buffer.hpp"
#include "../btdrv_shim.h"
#include "../btdrv_mitm_flags.hpp"
#include "../../bluetoothmitm_utils.hpp"
#include "../../controllers/controller_management.hpp"
#include <atomic>
#include <mutex>
@ -33,6 +34,7 @@ namespace ams::bluetooth::hid::report {
os::ThreadType g_event_handler_thread;
alignas(os::ThreadStackAlignment) uint8_t g_event_handler_thread_stack[0x1000];
s32 g_event_handler_thread_priority = mitm::utils::ConvertToUserPriority(17);
// This is only required on fw < 7.0.0
uint8_t g_event_data_buffer[0x480];
@ -100,7 +102,7 @@ namespace ams::bluetooth::hid::report {
nullptr,
g_event_handler_thread_stack,
sizeof(g_event_handler_thread_stack),
-10
g_event_handler_thread_priority
));
g_forward_service = forward_service;

View file

@ -17,6 +17,7 @@
#include "btdrvmitm_module.hpp"
#include "btdrv_mitm_service.hpp"
#include "bluetooth/bluetooth_events.hpp"
#include "../bluetoothmitm_utils.hpp"
#include <stratosphere.hpp>
#include <memory>
@ -37,7 +38,7 @@ namespace ams::mitm::btdrv {
os::ThreadType g_btdrv_mitm_thread;
alignas(os::ThreadStackAlignment) u8 g_btdrv_mitm_thread_stack[0x2000];
constexpr s32 g_btdrv_mitm_thread_priority = 16;
s32 g_btdrv_mitm_thread_priority = utils::ConvertToUserPriority(17);
void BtdrvMitmThreadFunction(void *arg) {
R_ABORT_UNLESS(bluetooth::events::Initialize());

View file

@ -16,6 +16,7 @@
*/
#include "btmmitm_module.hpp"
#include "btm_mitm_service.hpp"
#include "../bluetoothmitm_utils.hpp"
#include <stratosphere.hpp>
#include <memory>
@ -36,7 +37,7 @@ namespace ams::mitm::btm {
os::ThreadType g_btm_mitm_thread;
alignas(os::ThreadStackAlignment) u8 g_btm_mitm_thread_stack[0x2000];
constexpr s32 g_btm_mitm_thread_priority = 34;
s32 g_btm_mitm_thread_priority = utils::ConvertToUserPriority(37);
void BtmMitmThreadFunction(void *arg) {
auto server_manager = std::make_unique<sf::hipc::ServerManager<MaxServers, ServerOptions, MaxSessions>>();