From 34fa01060198e4da2613db3ae9122ea95a9710c1 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 5 Nov 2020 18:59:01 +0300 Subject: [PATCH] Improve cond_var notifiers But nobody uses it anyway, so clean up includes. --- Utilities/Thread.cpp | 2 +- Utilities/Thread.h | 1 - Utilities/cond.cpp | 4 +-- Utilities/cond.h | 1 - Utilities/typemap.h | 1 - rpcs3/Emu/Cell/Modules/cellGem.cpp | 12 ++++---- rpcs3/Emu/Cell/Modules/cellSearch.cpp | 2 +- rpcs3/Emu/Cell/Modules/cellVoice.cpp | 38 +++++++++++++------------- rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp | 20 +++++++------- rpcs3/Emu/Cell/RawSPUThread.cpp | 2 +- rpcs3/Emu/Cell/SPUThread.cpp | 1 + rpcs3/Emu/Cell/lv2/sys_lwcond.cpp | 4 +-- rpcs3/Emu/Cell/lv2/sys_memory.cpp | 3 +- rpcs3/Emu/Cell/lv2/sys_net.cpp | 19 +++++++------ rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp | 2 +- rpcs3/Emu/Cell/lv2/sys_sync.h | 21 +++++++------- rpcs3/Emu/Cell/lv2/sys_timer.cpp | 2 +- rpcs3/Emu/Cell/lv2/sys_timer.h | 2 +- rpcs3/Emu/Memory/vm.cpp | 2 +- rpcs3/Emu/Memory/vm_reservation.h | 1 - 20 files changed, 69 insertions(+), 71 deletions(-) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index a0ed6d88fd..3af0c65454 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -1397,7 +1397,7 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) no { if (auto mem = vm::get(vm::any, addr)) { - std::shared_lock lock(pf_entries->mutex); + reader_lock lock(pf_entries->mutex); for (const auto& entry : pf_entries->entries) { diff --git a/Utilities/Thread.h b/Utilities/Thread.h index 20aa45fcc8..fdc2ae9d63 100644 --- a/Utilities/Thread.h +++ b/Utilities/Thread.h @@ -9,7 +9,6 @@ #include #include "mutex.h" -#include "cond.h" #include "lockless.h" // Report error and call std::abort(), defined in main.cpp diff --git a/Utilities/cond.cpp b/Utilities/cond.cpp index a6d976c7c0..d0901e2ff8 100644 --- a/Utilities/cond.cpp +++ b/Utilities/cond.cpp @@ -50,10 +50,10 @@ void cond_variable::imp_wake(u32 _count) noexcept if (_count > 1 || ((_old + (c_signal_mask & (0 - c_signal_mask))) & c_signal_mask) == c_signal_mask) { // Resort to notify_all if signal count reached max - m_value.notify_all(); + m_value.notify_all(c_signal_mask); } else { - m_value.notify_one(); + m_value.notify_one(c_signal_mask); } } diff --git a/Utilities/cond.h b/Utilities/cond.h index 496b9ada96..d4dd4db204 100644 --- a/Utilities/cond.h +++ b/Utilities/cond.h @@ -2,7 +2,6 @@ #include "types.h" #include "util/atomic.hpp" -#include // Lightweight condition variable class cond_variable diff --git a/Utilities/typemap.h b/Utilities/typemap.h index 34b5fe5e5a..15a0f7e5d9 100644 --- a/Utilities/typemap.h +++ b/Utilities/typemap.h @@ -2,7 +2,6 @@ #include "types.h" #include "mutex.h" -#include "cond.h" #include "util/atomic.hpp" #include "util/typeindices.hpp" #include "VirtualMemory.h" diff --git a/rpcs3/Emu/Cell/Modules/cellGem.cpp b/rpcs3/Emu/Cell/Modules/cellGem.cpp index 6560be209b..8371c45d00 100644 --- a/rpcs3/Emu/Cell/Modules/cellGem.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGem.cpp @@ -750,7 +750,7 @@ error_code cellGemGetInfo(vm::ptr info) const auto gem = g_fxo->get(); - std::shared_lock lock(gem->mtx); + reader_lock lock(gem->mtx); if (!gem->state) { @@ -798,7 +798,7 @@ error_code cellGemGetRGB(u32 gem_num, vm::ptr r, vm::ptr g, vm::pt const auto gem = g_fxo->get(); - std::shared_lock lock(gem->mtx); + reader_lock lock(gem->mtx); if (!gem->state) { @@ -824,7 +824,7 @@ error_code cellGemGetRumble(u32 gem_num, vm::ptr rumble) const auto gem = g_fxo->get(); - std::shared_lock lock(gem->mtx); + reader_lock lock(gem->mtx); if (!gem->state) { @@ -847,7 +847,7 @@ error_code cellGemGetState(u32 gem_num, u32 flag, u64 time_parameter, vm::ptrget(); - std::shared_lock lock(gem->mtx); + reader_lock lock(gem->mtx); if (!gem->state) { @@ -889,7 +889,7 @@ error_code cellGemGetStatusFlags(u32 gem_num, vm::ptr flags) const auto gem = g_fxo->get(); - std::shared_lock lock(gem->mtx); + reader_lock lock(gem->mtx); if (!gem->state) { @@ -912,7 +912,7 @@ error_code cellGemGetTrackerHue(u32 gem_num, vm::ptr hue) const auto gem = g_fxo->get(); - std::shared_lock lock(gem->mtx); + reader_lock lock(gem->mtx); if (!gem->state) { diff --git a/rpcs3/Emu/Cell/Modules/cellSearch.cpp b/rpcs3/Emu/Cell/Modules/cellSearch.cpp index c919c6942b..aa390f5b98 100644 --- a/rpcs3/Emu/Cell/Modules/cellSearch.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSearch.cpp @@ -986,7 +986,7 @@ error_code cellSearchPrepareFile(vm::cptr path) return CELL_SEARCH_ERROR_GENERIC; } - std::shared_lock lock(search->links_mutex); + reader_lock lock(search->links_mutex); auto found = search->content_links.find(path.get_ptr()); if (found != search->content_links.end()) { diff --git a/rpcs3/Emu/Cell/Modules/cellVoice.cpp b/rpcs3/Emu/Cell/Modules/cellVoice.cpp index 97ae4752d7..86df175007 100644 --- a/rpcs3/Emu/Cell/Modules/cellVoice.cpp +++ b/rpcs3/Emu/Cell/Modules/cellVoice.cpp @@ -52,7 +52,7 @@ error_code cellVoiceConnectIPortToOPort(u32 ips, u32 ops) const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -76,7 +76,7 @@ error_code cellVoiceCreateNotifyEventQueue(ppu_thread& ppu, vm::ptr id, vm: auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -209,7 +209,7 @@ error_code cellVoiceDisconnectIPortFromOPort(u32 ips, u32 ops) const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -264,7 +264,7 @@ error_code cellVoiceGetBitRate(u32 portId, vm::ptr bitrate) const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -289,7 +289,7 @@ error_code cellVoiceGetMuteFlag(u32 portId, vm::ptr bMuted) const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -309,7 +309,7 @@ error_code cellVoiceGetPortAttr(u32 portId, u32 attr, vm::ptr attrValue) const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -329,7 +329,7 @@ error_code cellVoiceGetPortInfo(u32 portId, vm::ptr pInfo const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -356,7 +356,7 @@ error_code cellVoiceGetSignalState(u32 portId, u32 attr, vm::ptr attrValue const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -376,7 +376,7 @@ error_code cellVoiceGetVolume(u32 portId, vm::ptr volume) const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -437,7 +437,7 @@ error_code cellVoicePausePort(u32 portId) const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -456,7 +456,7 @@ error_code cellVoicePausePortAll() const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -487,7 +487,7 @@ error_code cellVoiceResetPort(u32 portId) const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -506,7 +506,7 @@ error_code cellVoiceResumePort(u32 portId) const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -525,7 +525,7 @@ error_code cellVoiceResumePortAll() const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -596,7 +596,7 @@ error_code cellVoiceSetMuteFlagAll(u16 bMuted) const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -792,7 +792,7 @@ error_code cellVoiceWriteToIPort(u32 ips, vm::cptr data, vm::ptr size const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -811,7 +811,7 @@ error_code cellVoiceWriteToIPortEx(u32 ips, vm::cptr data, vm::ptr si const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -830,7 +830,7 @@ error_code cellVoiceWriteToIPortEx2(u32 ips, vm::cptr data, vm::ptr s const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; @@ -849,7 +849,7 @@ error_code cellVoiceReadFromOPort(u32 ops, vm::ptr data, vm::ptr size const auto manager = g_fxo->get(); - std::shared_lock lock(manager->mtx); + reader_lock lock(manager->mtx); if (!manager->is_init) return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT; diff --git a/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp b/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp index 825d9d388c..adb040b16c 100644 --- a/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp @@ -463,7 +463,7 @@ error_code sceNpTrophyRegisterContext(ppu_thread& ppu, u32 context, u32 handle, const auto trophy_manager = g_fxo->get(); - std::shared_lock lock(trophy_manager->mtx); + reader_lock lock(trophy_manager->mtx); if (!trophy_manager->is_initialized) { @@ -619,7 +619,7 @@ error_code sceNpTrophyGetRequiredDiskSpace(u32 context, u32 handle, vm::ptr const auto trophy_manager = g_fxo->get(); - std::shared_lock lock(trophy_manager->mtx); + reader_lock lock(trophy_manager->mtx); if (!trophy_manager->is_initialized) { @@ -675,7 +675,7 @@ error_code sceNpTrophySetSoundLevel(u32 context, u32 handle, u32 level, u64 opti const auto trophy_manager = g_fxo->get(); - std::shared_lock lock(trophy_manager->mtx); + reader_lock lock(trophy_manager->mtx); if (!trophy_manager->is_initialized) { @@ -698,7 +698,7 @@ error_code sceNpTrophyGetGameInfo(u32 context, u32 handle, vm::ptrget(); - std::shared_lock lock(trophy_manager->mtx); + reader_lock lock(trophy_manager->mtx); if (!trophy_manager->is_initialized) { @@ -810,7 +810,7 @@ error_code sceNpTrophyUnlockTrophy(u32 context, u32 handle, s32 trophyId, vm::pt const auto trophy_manager = g_fxo->get(); - std::shared_lock lock(trophy_manager->mtx); + reader_lock lock(trophy_manager->mtx); if (!trophy_manager->is_initialized) { @@ -896,7 +896,7 @@ error_code sceNpTrophyGetTrophyUnlockState(u32 context, u32 handle, vm::ptrget(); - std::shared_lock lock(trophy_manager->mtx); + reader_lock lock(trophy_manager->mtx); if (!trophy_manager->is_initialized) { @@ -1057,7 +1057,7 @@ error_code sceNpTrophyGetTrophyInfo(u32 context, u32 handle, s32 trophyId, vm::p const auto trophy_manager = g_fxo->get(); - std::shared_lock lock(trophy_manager->mtx); + reader_lock lock(trophy_manager->mtx); if (!trophy_manager->is_initialized) { @@ -1085,7 +1085,7 @@ error_code sceNpTrophyGetGameProgress(u32 context, u32 handle, vm::ptr perc const auto trophy_manager = g_fxo->get(); - std::shared_lock lock(trophy_manager->mtx); + reader_lock lock(trophy_manager->mtx); if (!trophy_manager->is_initialized) { @@ -1125,7 +1125,7 @@ error_code sceNpTrophyGetGameIcon(u32 context, u32 handle, vm::ptr buffer, const auto trophy_manager = g_fxo->get(); - std::shared_lock lock(trophy_manager->mtx); + reader_lock lock(trophy_manager->mtx); if (!trophy_manager->is_initialized) { @@ -1175,7 +1175,7 @@ error_code sceNpTrophyGetTrophyIcon(u32 context, u32 handle, s32 trophyId, vm::p const auto trophy_manager = g_fxo->get(); - std::shared_lock lock(trophy_manager->mtx); + reader_lock lock(trophy_manager->mtx); if (!trophy_manager->is_initialized) { diff --git a/rpcs3/Emu/Cell/RawSPUThread.cpp b/rpcs3/Emu/Cell/RawSPUThread.cpp index fbfc64d01b..cb0075d637 100644 --- a/rpcs3/Emu/Cell/RawSPUThread.cpp +++ b/rpcs3/Emu/Cell/RawSPUThread.cpp @@ -8,7 +8,7 @@ inline void try_start(spu_thread& spu) { - std::shared_lock lock(spu.run_ctrl_mtx); + reader_lock lock(spu.run_ctrl_mtx); if (spu.status_npc.fetch_op([](typename spu_thread::status_npc_sync_var& value) { diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 3ef0155276..84bd80b4c6 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -30,6 +30,7 @@ #include #include #include +#include using spu_rdata_t = decltype(spu_thread::rdata); diff --git a/rpcs3/Emu/Cell/lv2/sys_lwcond.cpp b/rpcs3/Emu/Cell/lv2/sys_lwcond.cpp index 3e6e60a99c..6b548f1dab 100644 --- a/rpcs3/Emu/Cell/lv2/sys_lwcond.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_lwcond.cpp @@ -358,8 +358,8 @@ error_code _sys_lwcond_queue_wait(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id break; } - std::shared_lock lock2(mutex->mutex); - + reader_lock lock2(mutex->mutex); + if (std::find(mutex->sq.cbegin(), mutex->sq.cend(), &ppu) == mutex->sq.cend()) { break; diff --git a/rpcs3/Emu/Cell/lv2/sys_memory.cpp b/rpcs3/Emu/Cell/lv2/sys_memory.cpp index d929641486..54a13df94c 100644 --- a/rpcs3/Emu/Cell/lv2/sys_memory.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_memory.cpp @@ -6,7 +6,6 @@ #include "Emu/CPU/CPUThread.h" #include "Emu/Cell/ErrorCodes.h" #include "Emu/IdManager.h" -#include LOG_CHANNEL(sys_memory); @@ -162,7 +161,7 @@ error_code sys_memory_free(cpu_thread& cpu, u32 addr) } const auto size = verify(HERE, vm::dealloc(addr)); - std::shared_lock{id_manager::g_mutex}, ct->used -= size; + reader_lock{id_manager::g_mutex}, ct->used -= size; return CELL_OK; } diff --git a/rpcs3/Emu/Cell/lv2/sys_net.cpp b/rpcs3/Emu/Cell/lv2/sys_net.cpp index b24bca0f4f..315689a646 100644 --- a/rpcs3/Emu/Cell/lv2/sys_net.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_net.cpp @@ -27,6 +27,7 @@ #include #include +#include LOG_CHANNEL(sys_net); LOG_CHANNEL(sys_net_dump); @@ -545,7 +546,7 @@ struct nt_p2p_port memcpy(packet_data+sizeof(u16), &header, sizeof(lv2_socket::p2ps_i::encapsulated_tcp)); if(datasize) memcpy(packet_data+sizeof(u16)+sizeof(lv2_socket::p2ps_i::encapsulated_tcp), data, datasize); - + auto* hdr_ptr = reinterpret_cast(packet_data+sizeof(u16)); hdr_ptr->checksum = 0; hdr_ptr->checksum = tcp_checksum(reinterpret_cast(hdr_ptr), sizeof(lv2_socket::p2ps_i::encapsulated_tcp) + datasize); @@ -585,7 +586,7 @@ struct nt_p2p_port if (sock.p2ps.status != lv2_socket::p2ps_i::stream_status::stream_connected && sock.p2ps.status != lv2_socket::p2ps_i::stream_status::stream_handshaking) return false; - + dump_packet(tcp_header); if (tcp_header->flags == lv2_socket::p2ps_i::ACK) @@ -695,7 +696,7 @@ struct nt_p2p_port if (!sock || !sock.ret) return false; - + return true; } @@ -882,7 +883,7 @@ struct nt_p2p_port } auto* tcp_header = reinterpret_cast(sp_data); - + // Validate signature & length if (tcp_header->signature != lv2_socket::p2ps_i::U2S_sig) { @@ -946,7 +947,7 @@ struct network_thread shared_mutex s_nw_mutex; shared_mutex list_p2p_ports_mutex; - std::map list_p2p_ports{}; + std::map list_p2p_ports{}; static constexpr auto thread_name = "Network Thread"; @@ -2562,7 +2563,7 @@ error_code sys_net_bnet_sendto(ppu_thread& ppu, s32 s, vm::cptr buf, u32 l cur_total_len -= cur_data_len; sock.p2ps.cur_seq += cur_data_len; } - + native_result = len; return true; } @@ -2711,7 +2712,7 @@ error_code sys_net_bnet_setsockopt(ppu_thread& ppu, s32 s, s32 level, s32 optnam if (sock.type == SYS_NET_SOCK_DGRAM_P2P || sock.type == SYS_NET_SOCK_STREAM_P2P) { return {}; - } + } if (optlen >= sizeof(s32)) { @@ -2806,7 +2807,7 @@ error_code sys_net_bnet_setsockopt(ppu_thread& ppu, s32 s, s32 level, s32 optnam #else native_timeo.tv_sec = ::narrow(reinterpret_cast(optval_buf.data())->tv_sec); native_timeo.tv_usec = ::narrow(reinterpret_cast(optval_buf.data())->tv_usec); -#endif +#endif break; } case SYS_NET_SO_LINGER: @@ -3134,7 +3135,7 @@ error_code sys_net_bnet_poll(ppu_thread& ppu, vm::ptr fds, s32 n signaled++; } } - else + else { // Check for fake packet for dns interceptions const auto nph = g_fxo->get>(); diff --git a/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp b/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp index af5117a801..5fece13330 100644 --- a/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp @@ -593,7 +593,7 @@ error_code sys_ppu_thread_get_page_fault_context(ppu_thread& ppu, u32 thread_id, // We can only get a context if the thread is being suspended for a page fault. auto pf_events = g_fxo->get(); - std::shared_lock lock(pf_events->pf_mutex); + reader_lock lock(pf_events->pf_mutex); const auto evt = pf_events->events.find(thread.ptr.get()); if (evt == pf_events->events.end()) diff --git a/rpcs3/Emu/Cell/lv2/sys_sync.h b/rpcs3/Emu/Cell/lv2/sys_sync.h index a503d3e6ac..4622cd98d2 100644 --- a/rpcs3/Emu/Cell/lv2/sys_sync.h +++ b/rpcs3/Emu/Cell/lv2/sys_sync.h @@ -2,7 +2,6 @@ #include "Utilities/mutex.h" #include "Utilities/sema.h" -#include "Utilities/cond.h" #include "Emu/CPU/CPUThread.h" #include "Emu/Cell/ErrorCodes.h" @@ -155,6 +154,8 @@ private: static bool awake_unlocked(cpu_thread*, s32 prio = enqueue_cmd); public: + static constexpr u64 max_timeout = UINT64_MAX / 1000; + static void sleep(cpu_thread& cpu, const u64 timeout = 0); static bool awake(cpu_thread* const thread, s32 prio = enqueue_cmd); @@ -289,19 +290,19 @@ public: } } - template + template static bool wait_timeout(u64 usec, cpu_thread* const cpu = {}) { - static_assert(UINT64_MAX / cond_variable::max_timeout >= 100, "max timeout is not valid for scaling"); + static_assert(UINT64_MAX / max_timeout >= 100, "max timeout is not valid for scaling"); - if constexpr (scale) + if constexpr (Scale) { // Scale time usec = std::min(usec, UINT64_MAX / 100) * 100 / g_cfg.core.clocks_scale; } // Clamp - usec = std::min(usec, cond_variable::max_timeout); + usec = std::min(usec, max_timeout); extern u64 get_system_time(); @@ -314,7 +315,7 @@ public: remaining = usec - passed; #ifdef __linux__ // NOTE: Assumption that timer initialization has succeeded - u64 host_min_quantum = is_usleep && remaining <= 1000 ? 10 : 50; + u64 host_min_quantum = IsUsleep && remaining <= 1000 ? 10 : 50; #else // Host scheduler quantum for windows (worst case) // NOTE: On ps3 this function has very high accuracy @@ -322,9 +323,9 @@ public: #endif // TODO: Tune for other non windows operating sytems - if (g_cfg.core.sleep_timers_accuracy < (is_usleep ? sleep_timers_accuracy_level::_usleep : sleep_timers_accuracy_level::_all_timers)) + if (g_cfg.core.sleep_timers_accuracy < (IsUsleep ? sleep_timers_accuracy_level::_usleep : sleep_timers_accuracy_level::_all_timers)) { - thread_ctrl::wait_for(remaining, !is_usleep); + thread_ctrl::wait_for(remaining, !IsUsleep); } else { @@ -332,10 +333,10 @@ public: { #ifdef __linux__ // Do not wait for the last quantum to avoid loss of accuracy - thread_ctrl::wait_for(remaining - ((remaining % host_min_quantum) + host_min_quantum), !is_usleep); + thread_ctrl::wait_for(remaining - ((remaining % host_min_quantum) + host_min_quantum), !IsUsleep); #else // Wait on multiple of min quantum for large durations to avoid overloading low thread cpus - thread_ctrl::wait_for(remaining - (remaining % host_min_quantum), !is_usleep); + thread_ctrl::wait_for(remaining - (remaining % host_min_quantum), !IsUsleep); #endif } else diff --git a/rpcs3/Emu/Cell/lv2/sys_timer.cpp b/rpcs3/Emu/Cell/lv2/sys_timer.cpp index 04b6223543..89bcb21d8b 100644 --- a/rpcs3/Emu/Cell/lv2/sys_timer.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_timer.cpp @@ -82,7 +82,7 @@ error_code sys_timer_destroy(ppu_thread& ppu, u32 timer_id) const auto timer = idm::withdraw(timer_id, [&](lv2_timer& timer) -> CellError { - if (std::shared_lock lock(timer.mutex); lv2_event_queue::check(timer.port)) + if (reader_lock lock(timer.mutex); lv2_event_queue::check(timer.port)) { return CELL_EISCONN; } diff --git a/rpcs3/Emu/Cell/lv2/sys_timer.h b/rpcs3/Emu/Cell/lv2/sys_timer.h index dce0f9ad31..4b98f130e5 100644 --- a/rpcs3/Emu/Cell/lv2/sys_timer.h +++ b/rpcs3/Emu/Cell/lv2/sys_timer.h @@ -40,7 +40,7 @@ struct lv2_timer_context : lv2_obj void get_information(sys_timer_information_t& info) { - std::shared_lock lock(mutex); + reader_lock lock(mutex); if (state == SYS_TIMER_STATE_RUN) { diff --git a/rpcs3/Emu/Memory/vm.cpp b/rpcs3/Emu/Memory/vm.cpp index 1f917a11a6..96c5ee845f 100644 --- a/rpcs3/Emu/Memory/vm.cpp +++ b/rpcs3/Emu/Memory/vm.cpp @@ -6,7 +6,6 @@ #include "vm_var.h" #include "Utilities/mutex.h" -#include "Utilities/cond.h" #include "Utilities/Thread.h" #include "Utilities/VirtualMemory.h" #include "Utilities/address_range.h" @@ -17,6 +16,7 @@ #include "Emu/perf_meter.hpp" #include #include +#include LOG_CHANNEL(vm_log, "VM"); diff --git a/rpcs3/Emu/Memory/vm_reservation.h b/rpcs3/Emu/Memory/vm_reservation.h index 73db620ff3..7d313e8d5a 100644 --- a/rpcs3/Emu/Memory/vm_reservation.h +++ b/rpcs3/Emu/Memory/vm_reservation.h @@ -2,7 +2,6 @@ #include "vm.h" #include "vm_locking.h" -#include "Utilities/cond.h" #include "util/atomic.hpp" #include