From e3ddcd44e7120296f7167bfe81cab20bf7533139 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Mon, 25 May 2015 21:10:28 -0700 Subject: [PATCH] Minor fixes and fixing thread names. --- src/xenia/apu/audio_system.cc | 8 +++----- src/xenia/base/mutex.h | 4 ++-- src/xenia/gpu/gl4/command_processor.cc | 4 +--- src/xenia/gpu/gl4/gl4_graphics_system.cc | 5 ----- src/xenia/kernel/objects/xthread.cc | 8 ++++---- src/xenia/memory.cc | 4 ++-- 6 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/xenia/apu/audio_system.cc b/src/xenia/apu/audio_system.cc index 165756b28..8f2c24f14 100644 --- a/src/xenia/apu/audio_system.cc +++ b/src/xenia/apu/audio_system.cc @@ -109,9 +109,10 @@ X_STATUS AudioSystem::Setup() { worker_thread_ = kernel::object_ref(new kernel::XHostThread( emulator()->kernel_state(), 128 * 1024, 0, [this]() { - this->WorkerThreadMain(); + WorkerThreadMain(); return 0; })); + worker_thread_->set_name("Audio Worker"); worker_thread_->Create(); decoder_running_ = true; @@ -121,14 +122,13 @@ X_STATUS AudioSystem::Setup() { DecoderThreadMain(); return 0; })); + decoder_thread_->set_name("Audio Decoder"); decoder_thread_->Create(); return X_STATUS_SUCCESS; } void AudioSystem::WorkerThreadMain() { - xe::threading::set_name("Audio Worker"); - // Initialize driver and ringbuffer. Initialize(); @@ -182,8 +182,6 @@ void AudioSystem::WorkerThreadMain() { } void AudioSystem::DecoderThreadMain() { - xe::threading::set_name("Audio Decoder"); - while (decoder_running_) { // Wait for the fence decoder_fence_.Wait(); diff --git a/src/xenia/base/mutex.h b/src/xenia/base/mutex.h index bbe09fc22..0368e6a46 100644 --- a/src/xenia/base/mutex.h +++ b/src/xenia/base/mutex.h @@ -71,8 +71,8 @@ class mutex { private: std::aligned_storage<_Mtx_internal_imp_size, _Mtx_internal_imp_alignment>::type _Mtx_storage; - HANDLE holding_thread_; - bool debugger_waiting_; + HANDLE holding_thread_ = nullptr; + bool debugger_waiting_ = false; _Mtx_t _Mymtx() noexcept { return (reinterpret_cast<_Mtx_t>(&_Mtx_storage)); } }; diff --git a/src/xenia/gpu/gl4/command_processor.cc b/src/xenia/gpu/gl4/command_processor.cc index ae5d09fb2..1c6f83ca1 100644 --- a/src/xenia/gpu/gl4/command_processor.cc +++ b/src/xenia/gpu/gl4/command_processor.cc @@ -20,7 +20,6 @@ #include "xenia/gpu/texture_info.h" #include "xenia/gpu/xenos.h" #include "xenia/emulator.h" -#include "xenia/kernel/objects/xthread.h" #include "xenia/profiling.h" #include "third_party/xxhash/xxhash.h" @@ -107,6 +106,7 @@ bool CommandProcessor::Initialize(std::unique_ptr context) { WorkerThreadMain(); return 0; })); + worker_thread_->set_name("GL4 Worker"); worker_thread_->Create(); return true; @@ -191,8 +191,6 @@ void CommandProcessor::ClearCaches() { } void CommandProcessor::WorkerThreadMain() { - xe::threading::set_name("GL4 Worker"); - context_->MakeCurrent(); if (!SetupGL()) { XEFATAL("Unable to setup command processor GL state"); diff --git a/src/xenia/gpu/gl4/gl4_graphics_system.cc b/src/xenia/gpu/gl4/gl4_graphics_system.cc index 26672b6b4..f8a890201 100644 --- a/src/xenia/gpu/gl4/gl4_graphics_system.cc +++ b/src/xenia/gpu/gl4/gl4_graphics_system.cc @@ -241,11 +241,6 @@ void GL4GraphicsSystem::ClearCaches() { } void GL4GraphicsSystem::MarkVblank() { - static bool thread_name_set = false; - if (!thread_name_set) { - thread_name_set = true; - Profiler::ThreadEnter("GL4 Vsync Timer"); - } SCOPE_profile_cpu_f("gpu"); // Increment vblank counter (so the game sees us making progress). diff --git a/src/xenia/kernel/objects/xthread.cc b/src/xenia/kernel/objects/xthread.cc index 5deb7892f..70d545313 100644 --- a/src/xenia/kernel/objects/xthread.cc +++ b/src/xenia/kernel/objects/xthread.cc @@ -66,6 +66,10 @@ XThread::XThread(KernelState* kernel_state, uint32_t stack_size, event_ = object_ref(new XEvent(kernel_state)); event_->Initialize(true, false); + char thread_name[32]; + snprintf(thread_name, xe::countof(thread_name), "XThread%04X", handle()); + set_name(thread_name); + // The kernel does not take a reference. We must unregister in the dtor. kernel_state_->RegisterThread(this); } @@ -259,10 +263,6 @@ X_STATUS XThread::Create() { return return_code; } - char thread_name[32]; - snprintf(thread_name, xe::countof(thread_name), "XThread%04X", handle()); - set_name(thread_name); - uint32_t proc_mask = creation_params_.creation_flags >> 24; if (proc_mask) { SetAffinity(proc_mask); diff --git a/src/xenia/memory.cc b/src/xenia/memory.cc index ec3a9a47c..dc6c7e133 100644 --- a/src/xenia/memory.cc +++ b/src/xenia/memory.cc @@ -639,7 +639,7 @@ bool BaseHeap::AllocRange(uint32_t low_address, uint32_t high_address, uint32_t high_page_number = (high_address - heap_base_) / page_size_; low_page_number = std::min(uint32_t(page_table_.size()) - 1, low_page_number); high_page_number = - std::min(uint32_t(page_table_.size()) - 1, high_page_number) - page_count; + std::min(uint32_t(page_table_.size()) - 1, high_page_number); std::lock_guard lock(heap_mutex_); @@ -683,7 +683,7 @@ bool BaseHeap::AllocRange(uint32_t low_address, uint32_t high_address, } } else { for (uint32_t base_page_number = low_page_number; - base_page_number <= high_page_number; + base_page_number <= high_page_number - page_count; base_page_number += page_scan_stride) { bool is_free = page_table_[base_page_number].state == 0; if (page_table_[base_page_number].state != 0) {