Remove g_thread_count

Unnecessary global which is bad to reason about.
Possibly fix a but in SPRX loader.
This commit is contained in:
Nekotekina 2019-10-12 16:42:44 +03:00
parent 49e96b39dd
commit 8e21f4d5d4
2 changed files with 8 additions and 19 deletions

View file

@ -1653,9 +1653,6 @@ const bool s_exception_handler_set = []() -> bool
#endif #endif
// TODO
atomic_t<u32> g_thread_count(0);
thread_local DECLARE(thread_ctrl::g_tls_this_thread) = nullptr; thread_local DECLARE(thread_ctrl::g_tls_this_thread) = nullptr;
DECLARE(thread_ctrl::g_native_core_layout) { native_core_arrangement::undefined }; DECLARE(thread_ctrl::g_native_core_layout) { native_core_arrangement::undefined };
@ -1683,8 +1680,6 @@ void thread_base::initialize(bool(*wait_cb)(const void*))
return thread_ctrl::g_tls_this_thread->m_name.get(); return thread_ctrl::g_tls_this_thread->m_name.get();
}; };
++g_thread_count;
#ifdef _MSC_VER #ifdef _MSC_VER
struct THREADNAME_INFO struct THREADNAME_INFO
{ {
@ -1792,7 +1787,6 @@ void thread_base::finalize() noexcept
{ {
g_tls_log_prefix = []() -> std::string { return {}; }; g_tls_log_prefix = []() -> std::string { return {}; };
thread_ctrl::g_tls_this_thread = nullptr; thread_ctrl::g_tls_this_thread = nullptr;
--g_thread_count;
} }
void thread_ctrl::_wait_for(u64 usec, bool alert /* true */) void thread_ctrl::_wait_for(u64 usec, bool alert /* true */)

View file

@ -54,8 +54,6 @@ bool g_use_rtm;
std::string g_cfg_defaults; std::string g_cfg_defaults;
extern atomic_t<u32> g_thread_count;
extern void ppu_load_exec(const ppu_exec_object&); extern void ppu_load_exec(const ppu_exec_object&);
extern void spu_load_exec(const spu_exec_object&); extern void spu_load_exec(const spu_exec_object&);
extern void ppu_initialize(const ppu_module&); extern void ppu_initialize(const ppu_module&);
@ -1148,6 +1146,8 @@ void Emulator::Load(const std::string& title_id, bool add_only, bool force_globa
g_progr = "Compiling PPU modules"; g_progr = "Compiling PPU modules";
atomic_t<u32> worker_count = 0;
for (std::size_t i = 0; i < file_queue.size(); i++) for (std::size_t i = 0; i < file_queue.size(); i++)
{ {
const auto& path = file_queue[i].first; const auto& path = file_queue[i].first;
@ -1169,16 +1169,19 @@ void Emulator::Load(const std::string& title_id, bool add_only, bool force_globa
{ {
if (auto prx = ppu_load_prx(obj, path)) if (auto prx = ppu_load_prx(obj, path))
{ {
while (g_thread_count >= max_threads + 2) worker_count++;
while (worker_count > max_threads)
{ {
std::this_thread::sleep_for(10ms); std::this_thread::sleep_for(10ms);
} }
thread_queue.emplace("Worker " + std::to_string(thread_queue.size()), [_prx = std::move(prx)] thread_queue.emplace("Worker " + std::to_string(thread_queue.size()), [_prx = std::move(prx), &worker_count]
{ {
ppu_initialize(*_prx); ppu_initialize(*_prx);
ppu_unload_prx(*_prx); ppu_unload_prx(*_prx);
g_progr_fdone++; g_progr_fdone++;
worker_count--;
}); });
continue; continue;
@ -1788,17 +1791,9 @@ void Emulator::Stop(bool restart)
GetCallbacks().on_stop(); GetCallbacks().on_stop();
cpu_thread::stop_all(); cpu_thread::stop_all();
g_fxo->reset();
while (g_thread_count)
{
std::this_thread::sleep_for(10ms);
}
LOG_NOTICE(GENERAL, "All threads stopped...");
lv2_obj::cleanup(); lv2_obj::cleanup();
idm::clear(); idm::clear();
g_fxo->reset();
LOG_NOTICE(GENERAL, "Objects cleared..."); LOG_NOTICE(GENERAL, "Objects cleared...");