diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index b929aaa036..8720d38012 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -1654,9 +1654,8 @@ void thread_ctrl::initialize() void thread_ctrl::finalize(std::exception_ptr eptr) noexcept { - // Run atexit functions - m_task.invoke(); - m_task.reset(); + // Report pending errors + error_code::error_report(0, 0, 0, 0); #ifdef _WIN32 ULONG64 cycles{}; @@ -1695,11 +1694,6 @@ void thread_ctrl::finalize(std::exception_ptr eptr) noexcept m_jcv.notify_all(); } -void thread_ctrl::_push(task_stack task) -{ - g_tls_this_thread->m_task.push(std::move(task)); -} - bool thread_ctrl::_wait_for(u64 usec) { auto _this = g_tls_this_thread; diff --git a/Utilities/Thread.h b/Utilities/Thread.h index ad891fc8af..e0573baa95 100644 --- a/Utilities/Thread.h +++ b/Utilities/Thread.h @@ -132,7 +132,7 @@ class thread_ctrl final // Remotely set or caught exception std::exception_ptr m_exception; - // Thread initial task or atexit task + // Thread initial task task_stack m_task; // Fixed name @@ -150,9 +150,6 @@ class thread_ctrl final // Called at the thread end void finalize(std::exception_ptr) noexcept; - // Add task (atexit) - static void _push(task_stack); - // Internal waiting function, may throw. Infinite value is -1. static bool _wait_for(u64 usec); @@ -241,13 +238,6 @@ public: return g_tls_this_thread; } - // Register function at thread exit (for the current thread) - template - static inline void atexit(F&& func) - { - _push(std::forward(func)); - } - // Create detached named thread template static inline void spawn(N&& name, F&& func) diff --git a/rpcs3/Emu/Cell/Modules/sys_net_.cpp b/rpcs3/Emu/Cell/Modules/sys_net_.cpp index f94a580f24..7b76713c98 100644 --- a/rpcs3/Emu/Cell/Modules/sys_net_.cpp +++ b/rpcs3/Emu/Cell/Modules/sys_net_.cpp @@ -4,39 +4,8 @@ #include "sys_net_.h" - - LOG_CHANNEL(libnet); -struct sys_net_tls_data -{ - be_t _errno; - be_t _h_errno; - char addr[16]; -}; - -// TODO -thread_local vm::ptr g_tls_net_data{}; - -static NEVER_INLINE vm::ptr get_tls() -{ - // Allocate if not initialized - if (!g_tls_net_data) - { - g_tls_net_data.set(vm::alloc(sizeof(decltype(g_tls_net_data)::type), vm::main)); - - // Initial values - g_tls_net_data->_errno = SYS_NET_EBUSY; - - thread_ctrl::atexit([addr = g_tls_net_data.addr()] - { - vm::dealloc_verbose_nothrow(addr, vm::main); - }); - } - - return g_tls_net_data; -} - s32 sys_net_accept(s32 s, vm::ptr addr, vm::ptr paddrlen) { libnet.todo("accept(s=%d, addr=*0x%x, paddrlen=*0x%x)", s, addr, paddrlen); @@ -314,11 +283,12 @@ s32 sys_net_show_nameserver() return CELL_OK; } -vm::ptr _sys_net_errno_loc() +vm::ptr _sys_net_errno_loc(ppu_thread& ppu) { libnet.warning("_sys_net_errno_loc()"); - return get_tls().ptr(&sys_net_tls_data::_errno); + // Return fake location from system TLS area + return vm::cast(ppu.gpr[13] - 0x7030 + 0x2c); } s32 sys_net_set_resolver_configurations() @@ -388,11 +358,12 @@ s32 sys_net_finalize_network() return CELL_OK; } -vm::ptr _sys_net_h_errno_loc() +vm::ptr _sys_net_h_errno_loc(ppu_thread& ppu) { libnet.warning("_sys_net_h_errno_loc()"); - return get_tls().ptr(&sys_net_tls_data::_h_errno); + // Return fake location from system TLS area + return vm::cast(ppu.gpr[13] - 0x7030 + 0x28); } s32 sys_net_set_netemu_test_param() diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index f499238c35..6f91476440 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -1446,10 +1446,11 @@ s32 error_code::error_report(const fmt_type_info* sup, u64 arg, const fmt_type_i static thread_local std::unordered_map g_tls_error_stats; static thread_local std::string g_tls_error_str; - if (g_tls_error_stats.empty()) + if (!sup) { - thread_ctrl::atexit([] + if (!sup2) { + // Report and clean error state for (auto&& pair : g_tls_error_stats) { if (pair.second > 3) @@ -1457,7 +1458,10 @@ s32 error_code::error_report(const fmt_type_info* sup, u64 arg, const fmt_type_i LOG_ERROR(GENERAL, "Stat: %s [x%u]", pair.first, pair.second); } } - }); + + g_tls_error_stats.clear(); + return 0; + } } logs::channel* channel = &logs::GENERAL;