1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

Improve cond_var notifiers

But nobody uses it anyway, so clean up includes.
This commit is contained in:
Nekotekina 2020-11-05 18:59:01 +03:00
parent 7d56069243
commit 34fa010601
20 changed files with 69 additions and 71 deletions

View File

@ -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)
{

View File

@ -9,7 +9,6 @@
#include <string_view>
#include "mutex.h"
#include "cond.h"
#include "lockless.h"
// Report error and call std::abort(), defined in main.cpp

View File

@ -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);
}
}

View File

@ -2,7 +2,6 @@
#include "types.h"
#include "util/atomic.hpp"
#include <shared_mutex>
// Lightweight condition variable
class cond_variable

View File

@ -2,7 +2,6 @@
#include "types.h"
#include "mutex.h"
#include "cond.h"
#include "util/atomic.hpp"
#include "util/typeindices.hpp"
#include "VirtualMemory.h"

View File

@ -750,7 +750,7 @@ error_code cellGemGetInfo(vm::ptr<CellGemInfo> info)
const auto gem = g_fxo->get<gem_config>();
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<float> r, vm::ptr<float> g, vm::pt
const auto gem = g_fxo->get<gem_config>();
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<u8> rumble)
const auto gem = g_fxo->get<gem_config>();
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::ptr<Ce
const auto gem = g_fxo->get<gem_config>();
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<u64> flags)
const auto gem = g_fxo->get<gem_config>();
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<u32> hue)
const auto gem = g_fxo->get<gem_config>();
std::shared_lock lock(gem->mtx);
reader_lock lock(gem->mtx);
if (!gem->state)
{

View File

@ -986,7 +986,7 @@ error_code cellSearchPrepareFile(vm::cptr<char> 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())
{

View File

@ -52,7 +52,7 @@ error_code cellVoiceConnectIPortToOPort(u32 ips, u32 ops)
const auto manager = g_fxo->get<voice_manager>();
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<u32> id, vm:
auto manager = g_fxo->get<voice_manager>();
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<voice_manager>();
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<u32> bitrate)
const auto manager = g_fxo->get<voice_manager>();
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<u16> bMuted)
const auto manager = g_fxo->get<voice_manager>();
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<void> attrValue)
const auto manager = g_fxo->get<voice_manager>();
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<CellVoiceBasePortInfo> pInfo
const auto manager = g_fxo->get<voice_manager>();
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<void> attrValue
const auto manager = g_fxo->get<voice_manager>();
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<f32> volume)
const auto manager = g_fxo->get<voice_manager>();
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<voice_manager>();
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<voice_manager>();
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<voice_manager>();
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<voice_manager>();
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<voice_manager>();
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<voice_manager>();
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<void> data, vm::ptr<u32> size
const auto manager = g_fxo->get<voice_manager>();
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<void> data, vm::ptr<u32> si
const auto manager = g_fxo->get<voice_manager>();
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<void> data, vm::ptr<u32> s
const auto manager = g_fxo->get<voice_manager>();
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<void> data, vm::ptr<u32> size
const auto manager = g_fxo->get<voice_manager>();
std::shared_lock lock(manager->mtx);
reader_lock lock(manager->mtx);
if (!manager->is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;

View File

@ -463,7 +463,7 @@ error_code sceNpTrophyRegisterContext(ppu_thread& ppu, u32 context, u32 handle,
const auto trophy_manager = g_fxo->get<sce_np_trophy_manager>();
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<u64>
const auto trophy_manager = g_fxo->get<sce_np_trophy_manager>();
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<sce_np_trophy_manager>();
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::ptr<SceNpTrophyGa
const auto trophy_manager = g_fxo->get<sce_np_trophy_manager>();
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<sce_np_trophy_manager>();
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::ptr<SceN
const auto trophy_manager = g_fxo->get<sce_np_trophy_manager>();
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<sce_np_trophy_manager>();
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<s32> perc
const auto trophy_manager = g_fxo->get<sce_np_trophy_manager>();
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<void> buffer,
const auto trophy_manager = g_fxo->get<sce_np_trophy_manager>();
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<sce_np_trophy_manager>();
std::shared_lock lock(trophy_manager->mtx);
reader_lock lock(trophy_manager->mtx);
if (!trophy_manager->is_initialized)
{

View File

@ -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)
{

View File

@ -30,6 +30,7 @@
#include <cfenv>
#include <atomic>
#include <thread>
#include <shared_mutex>
using spu_rdata_t = decltype(spu_thread::rdata);

View File

@ -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;

View File

@ -6,7 +6,6 @@
#include "Emu/CPU/CPUThread.h"
#include "Emu/Cell/ErrorCodes.h"
#include "Emu/IdManager.h"
#include <shared_mutex>
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;
}

View File

@ -27,6 +27,7 @@
#include <limits>
#include <chrono>
#include <shared_mutex>
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<lv2_socket::p2ps_i::encapsulated_tcp *>(packet_data+sizeof(u16));
hdr_ptr->checksum = 0;
hdr_ptr->checksum = tcp_checksum(reinterpret_cast<u16 *>(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<lv2_socket::p2ps_i::encapsulated_tcp*>(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<u16, nt_p2p_port> list_p2p_ports{};
std::map<u16, nt_p2p_port> 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<void> 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<int>(reinterpret_cast<sys_net_timeval*>(optval_buf.data())->tv_sec);
native_timeo.tv_usec = ::narrow<int>(reinterpret_cast<sys_net_timeval*>(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<sys_net_pollfd> fds, s32 n
signaled++;
}
}
else
else
{
// Check for fake packet for dns interceptions
const auto nph = g_fxo->get<named_thread<np_handler>>();

View File

@ -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<page_fault_event_entries>();
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())

View File

@ -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<bool is_usleep = false, bool scale = true>
template <bool IsUsleep = false, bool Scale = true>
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<u64>(usec, UINT64_MAX / 100) * 100 / g_cfg.core.clocks_scale;
}
// Clamp
usec = std::min<u64>(usec, cond_variable::max_timeout);
usec = std::min<u64>(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

View File

@ -82,7 +82,7 @@ error_code sys_timer_destroy(ppu_thread& ppu, u32 timer_id)
const auto timer = idm::withdraw<lv2_obj, lv2_timer>(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;
}

View File

@ -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)
{

View File

@ -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 <thread>
#include <deque>
#include <shared_mutex>
LOG_CHANNEL(vm_log, "VM");

View File

@ -2,7 +2,6 @@
#include "vm.h"
#include "vm_locking.h"
#include "Utilities/cond.h"
#include "util/atomic.hpp"
#include <functional>