Merge pull request #4726 from FearlessTobi/port-2312

Port yuzu-emu/yuzu#2312: "general: Use deducation guides for std::lock_guard and std::unique_lock"
This commit is contained in:
Weiyi Wang 2019-04-13 18:00:09 -04:00 committed by GitHub
commit 4a206237be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 124 additions and 122 deletions

View file

@ -59,7 +59,7 @@ void EmuThread::run() {
was_active = false; was_active = false;
} else { } else {
std::unique_lock<std::mutex> lock(running_mutex); std::unique_lock lock{running_mutex};
running_cv.wait(lock, [this] { return IsRunning() || exec_step || stop_run; }); running_cv.wait(lock, [this] { return IsRunning() || exec_step || stop_run; });
} }
} }

View file

@ -49,7 +49,7 @@ public:
* @note This function is thread-safe * @note This function is thread-safe
*/ */
void SetRunning(bool running) { void SetRunning(bool running) {
std::unique_lock<std::mutex> lock(running_mutex); std::unique_lock lock{running_mutex};
this->running = running; this->running = running;
lock.unlock(); lock.unlock();
running_cv.notify_all(); running_cv.notify_all();

View file

@ -16,22 +16,22 @@ DetachedTasks::DetachedTasks() {
} }
void DetachedTasks::WaitForAllTasks() { void DetachedTasks::WaitForAllTasks() {
std::unique_lock<std::mutex> lock(mutex); std::unique_lock lock{mutex};
cv.wait(lock, [this]() { return count == 0; }); cv.wait(lock, [this]() { return count == 0; });
} }
DetachedTasks::~DetachedTasks() { DetachedTasks::~DetachedTasks() {
std::unique_lock<std::mutex> lock(mutex); std::unique_lock lock{mutex};
ASSERT(count == 0); ASSERT(count == 0);
instance = nullptr; instance = nullptr;
} }
void DetachedTasks::AddTask(std::function<void()> task) { void DetachedTasks::AddTask(std::function<void()> task) {
std::unique_lock<std::mutex> lock(instance->mutex); std::unique_lock lock{instance->mutex};
++instance->count; ++instance->count;
std::thread([task{std::move(task)}]() { std::thread([task{std::move(task)}]() {
task(); task();
std::unique_lock<std::mutex> lock(instance->mutex); std::unique_lock lock{instance->mutex};
--instance->count; --instance->count;
std::notify_all_at_thread_exit(instance->cv, std::move(lock)); std::notify_all_at_thread_exit(instance->cv, std::move(lock));
}) })

View file

@ -46,12 +46,12 @@ public:
} }
void AddBackend(std::unique_ptr<Backend> backend) { void AddBackend(std::unique_ptr<Backend> backend) {
std::lock_guard<std::mutex> lock(writing_mutex); std::lock_guard lock{writing_mutex};
backends.push_back(std::move(backend)); backends.push_back(std::move(backend));
} }
void RemoveBackend(std::string_view backend_name) { void RemoveBackend(std::string_view backend_name) {
std::lock_guard<std::mutex> lock(writing_mutex); std::lock_guard lock{writing_mutex};
const auto it = const auto it =
std::remove_if(backends.begin(), backends.end(), std::remove_if(backends.begin(), backends.end(),
[&backend_name](const auto& i) { return backend_name == i->GetName(); }); [&backend_name](const auto& i) { return backend_name == i->GetName(); });
@ -80,7 +80,7 @@ private:
backend_thread = std::thread([&] { backend_thread = std::thread([&] {
Entry entry; Entry entry;
auto write_logs = [&](Entry& e) { auto write_logs = [&](Entry& e) {
std::lock_guard<std::mutex> lock(writing_mutex); std::lock_guard lock{writing_mutex};
for (const auto& backend : backends) { for (const auto& backend : backends) {
backend->Write(e); backend->Write(e);
} }

View file

@ -16,7 +16,7 @@ namespace Common {
class Event { class Event {
public: public:
void Set() { void Set() {
std::lock_guard<std::mutex> lk(mutex); std::lock_guard lk{mutex};
if (!is_set) { if (!is_set) {
is_set = true; is_set = true;
condvar.notify_one(); condvar.notify_one();
@ -24,14 +24,14 @@ public:
} }
void Wait() { void Wait() {
std::unique_lock<std::mutex> lk(mutex); std::unique_lock lk{mutex};
condvar.wait(lk, [&] { return is_set; }); condvar.wait(lk, [&] { return is_set; });
is_set = false; is_set = false;
} }
template <class Duration> template <class Duration>
bool WaitFor(const std::chrono::duration<Duration>& time) { bool WaitFor(const std::chrono::duration<Duration>& time) {
std::unique_lock<std::mutex> lk(mutex); std::unique_lock lk(mutex);
if (!condvar.wait_for(lk, time, [this] { return is_set; })) if (!condvar.wait_for(lk, time, [this] { return is_set; }))
return false; return false;
is_set = false; is_set = false;
@ -40,7 +40,7 @@ public:
template <class Clock, class Duration> template <class Clock, class Duration>
bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) { bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) {
std::unique_lock<std::mutex> lk(mutex); std::unique_lock lk{mutex};
if (!condvar.wait_until(lk, time, [this] { return is_set; })) if (!condvar.wait_until(lk, time, [this] { return is_set; }))
return false; return false;
is_set = false; is_set = false;
@ -48,7 +48,7 @@ public:
} }
void Reset() { void Reset() {
std::unique_lock<std::mutex> lk(mutex); std::unique_lock lk{mutex};
// no other action required, since wait loops on the predicate and any lingering signal will // no other action required, since wait loops on the predicate and any lingering signal will
// get cleared on the first iteration // get cleared on the first iteration
is_set = false; is_set = false;
@ -66,7 +66,7 @@ public:
/// Blocks until all "count" threads have called Sync() /// Blocks until all "count" threads have called Sync()
void Sync() { void Sync() {
std::unique_lock<std::mutex> lk(mutex); std::unique_lock lk{mutex};
const std::size_t current_generation = generation; const std::size_t current_generation = generation;
if (++waiting == count) { if (++waiting == count) {
@ -80,7 +80,7 @@ public:
} }
std::size_t Generation() const { std::size_t Generation() const {
std::unique_lock<std::mutex> lk(mutex); std::unique_lock lk(mutex);
return generation; return generation;
} }

View file

@ -78,7 +78,7 @@ public:
T PopWait() { T PopWait() {
if (Empty()) { if (Empty()) {
std::unique_lock<std::mutex> lock(cv_mutex); std::unique_lock lock{cv_mutex};
cv.wait(lock, [this]() { return !Empty(); }); cv.wait(lock, [this]() { return !Empty(); });
} }
T t; T t;
@ -137,7 +137,7 @@ public:
template <typename Arg> template <typename Arg>
void Push(Arg&& t) { void Push(Arg&& t) {
std::lock_guard<std::mutex> lock(write_lock); std::lock_guard lock{write_lock};
spsc_queue.Push(t); spsc_queue.Push(t);
} }

View file

@ -65,14 +65,14 @@ void AnnounceMultiplayerSession::Stop() {
AnnounceMultiplayerSession::CallbackHandle AnnounceMultiplayerSession::BindErrorCallback( AnnounceMultiplayerSession::CallbackHandle AnnounceMultiplayerSession::BindErrorCallback(
std::function<void(const Common::WebResult&)> function) { std::function<void(const Common::WebResult&)> function) {
std::lock_guard<std::mutex> lock(callback_mutex); std::lock_guard lock(callback_mutex);
auto handle = std::make_shared<std::function<void(const Common::WebResult&)>>(function); auto handle = std::make_shared<std::function<void(const Common::WebResult&)>>(function);
error_callbacks.insert(handle); error_callbacks.insert(handle);
return handle; return handle;
} }
void AnnounceMultiplayerSession::UnbindErrorCallback(CallbackHandle handle) { void AnnounceMultiplayerSession::UnbindErrorCallback(CallbackHandle handle) {
std::lock_guard<std::mutex> lock(callback_mutex); std::lock_guard lock(callback_mutex);
error_callbacks.erase(handle); error_callbacks.erase(handle);
} }
@ -112,7 +112,7 @@ void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() {
UpdateBackendData(room); UpdateBackendData(room);
Common::WebResult result = backend->Update(); Common::WebResult result = backend->Update();
if (result.result_code != Common::WebResult::Code::Success) { if (result.result_code != Common::WebResult::Code::Success) {
std::lock_guard<std::mutex> lock(callback_mutex); std::lock_guard lock(callback_mutex);
for (auto callback : error_callbacks) { for (auto callback : error_callbacks) {
(*callback)(result); (*callback)(result);
} }

View file

@ -28,7 +28,7 @@ private:
explicit Device(std::weak_ptr<TouchState>&& touch_state) : touch_state(touch_state) {} explicit Device(std::weak_ptr<TouchState>&& touch_state) : touch_state(touch_state) {}
std::tuple<float, float, bool> GetStatus() const override { std::tuple<float, float, bool> GetStatus() const override {
if (auto state = touch_state.lock()) { if (auto state = touch_state.lock()) {
std::lock_guard<std::mutex> guard(state->mutex); std::lock_guard guard{state->mutex};
return std::make_tuple(state->touch_x, state->touch_y, state->touch_pressed); return std::make_tuple(state->touch_x, state->touch_y, state->touch_pressed);
} }
return std::make_tuple(0.0f, 0.0f, false); return std::make_tuple(0.0f, 0.0f, false);
@ -98,7 +98,7 @@ void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) {
if (Settings::values.toggle_3d && framebuffer_x >= framebuffer_layout.width / 2) if (Settings::values.toggle_3d && framebuffer_x >= framebuffer_layout.width / 2)
framebuffer_x -= framebuffer_layout.width / 2; framebuffer_x -= framebuffer_layout.width / 2;
std::lock_guard<std::mutex> guard(touch_state->mutex); std::lock_guard guard(touch_state->mutex);
if (Settings::values.toggle_3d) { if (Settings::values.toggle_3d) {
touch_state->touch_x = touch_state->touch_x =
static_cast<float>(framebuffer_x - framebuffer_layout.bottom_screen.left / 2) / static_cast<float>(framebuffer_x - framebuffer_layout.bottom_screen.left / 2) /
@ -117,7 +117,7 @@ void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) {
} }
void EmuWindow::TouchReleased() { void EmuWindow::TouchReleased() {
std::lock_guard<std::mutex> guard(touch_state->mutex); std::lock_guard guard{touch_state->mutex};
touch_state->touch_pressed = false; touch_state->touch_pressed = false;
touch_state->touch_x = 0; touch_state->touch_x = 0;
touch_state->touch_y = 0; touch_state->touch_y = 0;

View file

@ -1575,7 +1575,7 @@ void SVC::CallSVC(u32 immediate) {
MICROPROFILE_SCOPE(Kernel_SVC); MICROPROFILE_SCOPE(Kernel_SVC);
// Lock the global kernel mutex when we enter the kernel HLE. // Lock the global kernel mutex when we enter the kernel HLE.
std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock); std::lock_guard lock{HLE::g_hle_lock};
DEBUG_ASSERT_MSG(kernel.GetCurrentProcess()->status == ProcessStatus::Running, DEBUG_ASSERT_MSG(kernel.GetCurrentProcess()->status == ProcessStatus::Running,
"Running threads from exiting processes is unimplemented"); "Running threads from exiting processes is unimplemented");

View file

@ -41,7 +41,7 @@ constexpr u16 BroadcastNetworkNodeId = 0xFFFF;
constexpr u16 HostDestNodeId = 1; constexpr u16 HostDestNodeId = 1;
std::list<Network::WifiPacket> NWM_UDS::GetReceivedBeacons(const MacAddress& sender) { std::list<Network::WifiPacket> NWM_UDS::GetReceivedBeacons(const MacAddress& sender) {
std::lock_guard<std::mutex> lock(beacon_mutex); std::lock_guard lock(beacon_mutex);
if (sender != Network::BroadcastMac) { if (sender != Network::BroadcastMac) {
std::list<Network::WifiPacket> filtered_list; std::list<Network::WifiPacket> filtered_list;
const auto beacon = std::find_if(received_beacons.begin(), received_beacons.end(), const auto beacon = std::find_if(received_beacons.begin(), received_beacons.end(),
@ -107,7 +107,7 @@ void NWM_UDS::BroadcastNodeMap() {
} }
void NWM_UDS::HandleNodeMapPacket(const Network::WifiPacket& packet) { void NWM_UDS::HandleNodeMapPacket(const Network::WifiPacket& packet) {
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
if (connection_status.status == static_cast<u32>(NetworkStatus::ConnectedAsHost)) { if (connection_status.status == static_cast<u32>(NetworkStatus::ConnectedAsHost)) {
LOG_DEBUG(Service_NWM, "Ignored NodeMapPacket since connection_status is host"); LOG_DEBUG(Service_NWM, "Ignored NodeMapPacket since connection_status is host");
return; return;
@ -129,7 +129,7 @@ void NWM_UDS::HandleNodeMapPacket(const Network::WifiPacket& packet) {
} }
void NWM_UDS::HandleBeaconFrame(const Network::WifiPacket& packet) { void NWM_UDS::HandleBeaconFrame(const Network::WifiPacket& packet) {
std::lock_guard<std::mutex> lock(beacon_mutex); std::lock_guard lock(beacon_mutex);
const auto unique_beacon = const auto unique_beacon =
std::find_if(received_beacons.begin(), received_beacons.end(), std::find_if(received_beacons.begin(), received_beacons.end(),
[&packet](const Network::WifiPacket& new_packet) { [&packet](const Network::WifiPacket& new_packet) {
@ -153,7 +153,7 @@ void NWM_UDS::HandleAssociationResponseFrame(const Network::WifiPacket& packet)
ASSERT_MSG(std::get<AssocStatus>(assoc_result) == AssocStatus::Successful, ASSERT_MSG(std::get<AssocStatus>(assoc_result) == AssocStatus::Successful,
"Could not join network"); "Could not join network");
{ {
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
if (connection_status.status != static_cast<u32>(NetworkStatus::Connecting)) { if (connection_status.status != static_cast<u32>(NetworkStatus::Connecting)) {
LOG_DEBUG(Service_NWM, LOG_DEBUG(Service_NWM,
"Ignored AssociationResponseFrame because connection status is {}", "Ignored AssociationResponseFrame because connection status is {}",
@ -175,8 +175,8 @@ void NWM_UDS::HandleAssociationResponseFrame(const Network::WifiPacket& packet)
} }
void NWM_UDS::HandleEAPoLPacket(const Network::WifiPacket& packet) { void NWM_UDS::HandleEAPoLPacket(const Network::WifiPacket& packet) {
std::unique_lock<std::recursive_mutex> hle_lock(HLE::g_hle_lock, std::defer_lock); std::unique_lock hle_lock(HLE::g_hle_lock, std::defer_lock);
std::unique_lock<std::mutex> lock(connection_status_mutex, std::defer_lock); std::unique_lock lock(connection_status_mutex, std::defer_lock);
std::lock(hle_lock, lock); std::lock(hle_lock, lock);
if (GetEAPoLFrameType(packet.data) == EAPoLStartMagic) { if (GetEAPoLFrameType(packet.data) == EAPoLStartMagic) {
@ -295,8 +295,8 @@ void NWM_UDS::HandleEAPoLPacket(const Network::WifiPacket& packet) {
void NWM_UDS::HandleSecureDataPacket(const Network::WifiPacket& packet) { void NWM_UDS::HandleSecureDataPacket(const Network::WifiPacket& packet) {
auto secure_data = ParseSecureDataHeader(packet.data); auto secure_data = ParseSecureDataHeader(packet.data);
std::unique_lock<std::recursive_mutex> hle_lock(HLE::g_hle_lock, std::defer_lock); std::unique_lock hle_lock(HLE::g_hle_lock, std::defer_lock);
std::unique_lock<std::mutex> lock(connection_status_mutex, std::defer_lock); std::unique_lock lock(connection_status_mutex, std::defer_lock);
std::lock(hle_lock, lock); std::lock(hle_lock, lock);
if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost) && if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost) &&
@ -358,7 +358,7 @@ void NWM_UDS::StartConnectionSequence(const MacAddress& server) {
using Network::WifiPacket; using Network::WifiPacket;
WifiPacket auth_request; WifiPacket auth_request;
{ {
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
connection_status.status = static_cast<u32>(NetworkStatus::Connecting); connection_status.status = static_cast<u32>(NetworkStatus::Connecting);
// TODO(Subv): Handle timeout. // TODO(Subv): Handle timeout.
@ -378,7 +378,7 @@ void NWM_UDS::SendAssociationResponseFrame(const MacAddress& address) {
WifiPacket assoc_response; WifiPacket assoc_response;
{ {
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost)) { if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost)) {
LOG_ERROR(Service_NWM, "Connection sequence aborted, because connection status is {}", LOG_ERROR(Service_NWM, "Connection sequence aborted, because connection status is {}",
connection_status.status); connection_status.status);
@ -404,7 +404,7 @@ void NWM_UDS::HandleAuthenticationFrame(const Network::WifiPacket& packet) {
using Network::WifiPacket; using Network::WifiPacket;
WifiPacket auth_request; WifiPacket auth_request;
{ {
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost)) { if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost)) {
LOG_ERROR(Service_NWM, LOG_ERROR(Service_NWM,
"Connection sequence aborted, because connection status is {}", "Connection sequence aborted, because connection status is {}",
@ -438,8 +438,8 @@ void NWM_UDS::HandleAuthenticationFrame(const Network::WifiPacket& packet) {
void NWM_UDS::HandleDeauthenticationFrame(const Network::WifiPacket& packet) { void NWM_UDS::HandleDeauthenticationFrame(const Network::WifiPacket& packet) {
LOG_DEBUG(Service_NWM, "called"); LOG_DEBUG(Service_NWM, "called");
std::unique_lock<std::recursive_mutex> hle_lock(HLE::g_hle_lock, std::defer_lock); std::unique_lock hle_lock(HLE::g_hle_lock, std::defer_lock);
std::unique_lock<std::mutex> lock(connection_status_mutex, std::defer_lock); std::unique_lock lock(connection_status_mutex, std::defer_lock);
std::lock(hle_lock, lock); std::lock(hle_lock, lock);
if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost)) { if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost)) {
LOG_ERROR(Service_NWM, "Got deauthentication frame but we are not the host"); LOG_ERROR(Service_NWM, "Got deauthentication frame but we are not the host");
@ -633,7 +633,7 @@ ResultVal<std::shared_ptr<Kernel::Event>> NWM_UDS::Initialize(
} }
{ {
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
// Reset the connection status, it contains all zeros after initialization, // Reset the connection status, it contains all zeros after initialization,
// except for the actual status value. // except for the actual status value.
@ -686,7 +686,7 @@ void NWM_UDS::GetConnectionStatus(Kernel::HLERequestContext& ctx) {
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
{ {
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
rb.PushRaw(connection_status); rb.PushRaw(connection_status);
// Reset the bitmask of changed nodes after each call to this // Reset the bitmask of changed nodes after each call to this
@ -711,7 +711,7 @@ void NWM_UDS::GetNodeInformation(Kernel::HLERequestContext& ctx) {
} }
{ {
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
auto itr = std::find_if(node_info.begin(), node_info.end(), auto itr = std::find_if(node_info.begin(), node_info.end(),
[network_node_id](const NodeInfo& node) { [network_node_id](const NodeInfo& node) {
return node.network_node_id == network_node_id; return node.network_node_id == network_node_id;
@ -770,7 +770,7 @@ void NWM_UDS::Bind(Kernel::HLERequestContext& ctx) {
// Create a new event for this bind node. // Create a new event for this bind node.
auto event = system.Kernel().CreateEvent(Kernel::ResetType::OneShot, auto event = system.Kernel().CreateEvent(Kernel::ResetType::OneShot,
"NWM::BindNodeEvent" + std::to_string(bind_node_id)); "NWM::BindNodeEvent" + std::to_string(bind_node_id));
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
ASSERT(channel_data.find(data_channel) == channel_data.end()); ASSERT(channel_data.find(data_channel) == channel_data.end());
// TODO(B3N30): Support more than one bind node per channel. // TODO(B3N30): Support more than one bind node per channel.
@ -792,7 +792,7 @@ void NWM_UDS::Unbind(Kernel::HLERequestContext& ctx) {
return; return;
} }
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
auto itr = auto itr =
std::find_if(channel_data.begin(), channel_data.end(), [bind_node_id](const auto& data) { std::find_if(channel_data.begin(), channel_data.end(), [bind_node_id](const auto& data) {
@ -819,7 +819,7 @@ ResultCode NWM_UDS::BeginHostingNetwork(const u8* network_info_buffer,
// TODO(Subv): Store the passphrase and verify it when attempting a connection. // TODO(Subv): Store the passphrase and verify it when attempting a connection.
{ {
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
network_info = {}; network_info = {};
std::memcpy(&network_info, network_info_buffer, network_info_size); std::memcpy(&network_info, network_info_buffer, network_info_size);
@ -933,7 +933,7 @@ void NWM_UDS::DestroyNetwork(Kernel::HLERequestContext& ctx) {
system.CoreTiming().UnscheduleEvent(beacon_broadcast_event, 0); system.CoreTiming().UnscheduleEvent(beacon_broadcast_event, 0);
// Only a host can destroy // Only a host can destroy
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
if (connection_status.status != static_cast<u8>(NetworkStatus::ConnectedAsHost)) { if (connection_status.status != static_cast<u8>(NetworkStatus::ConnectedAsHost)) {
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ResultCode(ErrCodes::WrongStatus, ErrorModule::UDS, ErrorSummary::InvalidState, rb.Push(ResultCode(ErrCodes::WrongStatus, ErrorModule::UDS, ErrorSummary::InvalidState,
@ -970,7 +970,7 @@ void NWM_UDS::DisconnectNetwork(Kernel::HLERequestContext& ctx) {
using Network::WifiPacket; using Network::WifiPacket;
WifiPacket deauth; WifiPacket deauth;
{ {
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
if (connection_status.status == static_cast<u32>(NetworkStatus::ConnectedAsHost)) { if (connection_status.status == static_cast<u32>(NetworkStatus::ConnectedAsHost)) {
// A real 3ds makes strange things here. We do the same // A real 3ds makes strange things here. We do the same
u16_le tmp_node_id = connection_status.network_node_id; u16_le tmp_node_id = connection_status.network_node_id;
@ -1027,7 +1027,7 @@ void NWM_UDS::SendTo(Kernel::HLERequestContext& ctx) {
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsClient) && if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsClient) &&
connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost)) { connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost)) {
rb.Push(ResultCode(ErrorDescription::NotAuthorized, ErrorModule::UDS, rb.Push(ResultCode(ErrorDescription::NotAuthorized, ErrorModule::UDS,
@ -1091,7 +1091,7 @@ void NWM_UDS::PullPacket(Kernel::HLERequestContext& ctx) {
// This size is hard coded into the uds module. We don't know the meaning yet. // This size is hard coded into the uds module. We don't know the meaning yet.
u32 buff_size = std::min<u32>(max_out_buff_size_aligned, 0x172) << 2; u32 buff_size = std::min<u32>(max_out_buff_size_aligned, 0x172) << 2;
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost) && if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost) &&
connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsClient) && connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsClient) &&
connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsSpectator)) { connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsSpectator)) {
@ -1154,7 +1154,7 @@ void NWM_UDS::GetChannel(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x1A, 0, 0); IPC::RequestParser rp(ctx, 0x1A, 0, 0);
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
std::lock_guard<std::mutex> lock(connection_status_mutex); std::lock_guard lock(connection_status_mutex);
bool is_connected = connection_status.status != static_cast<u32>(NetworkStatus::NotConnected); bool is_connected = connection_status.status != static_cast<u32>(NetworkStatus::NotConnected);
u8 channel = is_connected ? network_channel : 0; u8 channel = is_connected ? network_channel : 0;

View file

@ -18,13 +18,13 @@ using std::chrono::microseconds;
namespace Core { namespace Core {
void PerfStats::BeginSystemFrame() { void PerfStats::BeginSystemFrame() {
std::lock_guard<std::mutex> lock(object_mutex); std::lock_guard lock{object_mutex};
frame_begin = Clock::now(); frame_begin = Clock::now();
} }
void PerfStats::EndSystemFrame() { void PerfStats::EndSystemFrame() {
std::lock_guard<std::mutex> lock(object_mutex); std::lock_guard lock{object_mutex};
auto frame_end = Clock::now(); auto frame_end = Clock::now();
accumulated_frametime += frame_end - frame_begin; accumulated_frametime += frame_end - frame_begin;
@ -35,13 +35,13 @@ void PerfStats::EndSystemFrame() {
} }
void PerfStats::EndGameFrame() { void PerfStats::EndGameFrame() {
std::lock_guard<std::mutex> lock(object_mutex); std::lock_guard lock{object_mutex};
game_frames += 1; game_frames += 1;
} }
PerfStats::Results PerfStats::GetAndResetStats(microseconds current_system_time_us) { PerfStats::Results PerfStats::GetAndResetStats(microseconds current_system_time_us) {
std::lock_guard<std::mutex> lock(object_mutex); std::lock_guard lock(object_mutex);
const auto now = Clock::now(); const auto now = Clock::now();
// Walltime elapsed since stats were reset // Walltime elapsed since stats were reset
@ -67,7 +67,7 @@ PerfStats::Results PerfStats::GetAndResetStats(microseconds current_system_time_
} }
double PerfStats::GetLastFrameTimeScale() { double PerfStats::GetLastFrameTimeScale() {
std::lock_guard<std::mutex> lock(object_mutex); std::lock_guard lock{object_mutex};
constexpr double FRAME_LENGTH = 1.0 / GPU::SCREEN_REFRESH_RATE; constexpr double FRAME_LENGTH = 1.0 / GPU::SCREEN_REFRESH_RATE;
return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH; return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH;

View file

@ -36,18 +36,18 @@ struct KeyButtonPair {
class KeyButtonList { class KeyButtonList {
public: public:
void AddKeyButton(int key_code, KeyButton* key_button) { void AddKeyButton(int key_code, KeyButton* key_button) {
std::lock_guard<std::mutex> guard(mutex); std::lock_guard guard{mutex};
list.push_back(KeyButtonPair{key_code, key_button}); list.push_back(KeyButtonPair{key_code, key_button});
} }
void RemoveKeyButton(const KeyButton* key_button) { void RemoveKeyButton(const KeyButton* key_button) {
std::lock_guard<std::mutex> guard(mutex); std::lock_guard guard{mutex};
list.remove_if( list.remove_if(
[key_button](const KeyButtonPair& pair) { return pair.key_button == key_button; }); [key_button](const KeyButtonPair& pair) { return pair.key_button == key_button; });
} }
void ChangeKeyStatus(int key_code, bool pressed) { void ChangeKeyStatus(int key_code, bool pressed) {
std::lock_guard<std::mutex> guard(mutex); std::lock_guard guard{mutex};
for (const KeyButtonPair& pair : list) { for (const KeyButtonPair& pair : list) {
if (pair.key_code == key_code) if (pair.key_code == key_code)
pair.key_button->status.store(pressed); pair.key_button->status.store(pressed);
@ -55,7 +55,7 @@ public:
} }
void ChangeAllKeyStatus(bool pressed) { void ChangeAllKeyStatus(bool pressed) {
std::lock_guard<std::mutex> guard(mutex); std::lock_guard guard{mutex};
for (const KeyButtonPair& pair : list) { for (const KeyButtonPair& pair : list) {
pair.key_button->status.store(pressed); pair.key_button->status.store(pressed);
} }

View file

@ -40,7 +40,7 @@ public:
void Tilt(int x, int y) { void Tilt(int x, int y) {
auto mouse_move = Common::MakeVec(x, y) - mouse_origin; auto mouse_move = Common::MakeVec(x, y) - mouse_origin;
if (is_tilting) { if (is_tilting) {
std::lock_guard<std::mutex> guard(tilt_mutex); std::lock_guard guard{tilt_mutex};
if (mouse_move.x == 0 && mouse_move.y == 0) { if (mouse_move.x == 0 && mouse_move.y == 0) {
tilt_angle = 0; tilt_angle = 0;
} else { } else {
@ -52,13 +52,13 @@ public:
} }
void EndTilt() { void EndTilt() {
std::lock_guard<std::mutex> guard(tilt_mutex); std::lock_guard guard{tilt_mutex};
tilt_angle = 0; tilt_angle = 0;
is_tilting = false; is_tilting = false;
} }
std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() { std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() {
std::lock_guard<std::mutex> guard(status_mutex); std::lock_guard guard{status_mutex};
return status; return status;
} }
@ -95,7 +95,7 @@ private:
old_q = q; old_q = q;
{ {
std::lock_guard<std::mutex> guard(tilt_mutex); std::lock_guard guard{tilt_mutex};
// Find the quaternion describing current 3DS tilting // Find the quaternion describing current 3DS tilting
q = Common::MakeQuaternion( q = Common::MakeQuaternion(
@ -117,7 +117,7 @@ private:
// Update the sensor state // Update the sensor state
{ {
std::lock_guard<std::mutex> guard(status_mutex); std::lock_guard guard{status_mutex};
status = std::make_tuple(gravity, angular_rate); status = std::make_tuple(gravity, angular_rate);
} }
} }

View file

@ -55,22 +55,22 @@ public:
: guid{std::move(guid_)}, port{port_}, sdl_joystick{joystick, deleter} {} : guid{std::move(guid_)}, port{port_}, sdl_joystick{joystick, deleter} {}
void SetButton(int button, bool value) { void SetButton(int button, bool value) {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard lock{mutex};
state.buttons[button] = value; state.buttons[button] = value;
} }
bool GetButton(int button) const { bool GetButton(int button) const {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard lock{mutex};
return state.buttons.at(button); return state.buttons.at(button);
} }
void SetAxis(int axis, Sint16 value) { void SetAxis(int axis, Sint16 value) {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard lock{mutex};
state.axes[axis] = value; state.axes[axis] = value;
} }
float GetAxis(int axis) const { float GetAxis(int axis) const {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard lock{mutex};
return state.axes.at(axis) / 32767.0f; return state.axes.at(axis) / 32767.0f;
} }
@ -92,12 +92,12 @@ public:
} }
void SetHat(int hat, Uint8 direction) { void SetHat(int hat, Uint8 direction) {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard lock{mutex};
state.hats[hat] = direction; state.hats[hat] = direction;
} }
bool GetHatDirection(int hat, Uint8 direction) const { bool GetHatDirection(int hat, Uint8 direction) const {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard lock{mutex};
return (state.hats.at(hat) & direction) != 0; return (state.hats.at(hat) & direction) != 0;
} }
/** /**
@ -140,7 +140,7 @@ private:
* Get the nth joystick with the corresponding GUID * Get the nth joystick with the corresponding GUID
*/ */
std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickByGUID(const std::string& guid, int port) { std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickByGUID(const std::string& guid, int port) {
std::lock_guard<std::mutex> lock(joystick_map_mutex); std::lock_guard lock{joystick_map_mutex};
const auto it = joystick_map.find(guid); const auto it = joystick_map.find(guid);
if (it != joystick_map.end()) { if (it != joystick_map.end()) {
while (it->second.size() <= port) { while (it->second.size() <= port) {
@ -161,7 +161,8 @@ std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickByGUID(const std::string& g
std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickBySDLID(SDL_JoystickID sdl_id) { std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickBySDLID(SDL_JoystickID sdl_id) {
auto sdl_joystick = SDL_JoystickFromInstanceID(sdl_id); auto sdl_joystick = SDL_JoystickFromInstanceID(sdl_id);
const std::string guid = GetGUID(sdl_joystick); const std::string guid = GetGUID(sdl_joystick);
std::lock_guard<std::mutex> lock(joystick_map_mutex);
std::lock_guard lock{joystick_map_mutex};
auto map_it = joystick_map.find(guid); auto map_it = joystick_map.find(guid);
if (map_it != joystick_map.end()) { if (map_it != joystick_map.end()) {
auto vec_it = std::find_if(map_it->second.begin(), map_it->second.end(), auto vec_it = std::find_if(map_it->second.begin(), map_it->second.end(),
@ -198,8 +199,9 @@ void SDLState::InitJoystick(int joystick_index) {
LOG_ERROR(Input, "failed to open joystick {}", joystick_index); LOG_ERROR(Input, "failed to open joystick {}", joystick_index);
return; return;
} }
std::string guid = GetGUID(sdl_joystick); const std::string guid = GetGUID(sdl_joystick);
std::lock_guard<std::mutex> lock(joystick_map_mutex);
std::lock_guard lock{joystick_map_mutex};
if (joystick_map.find(guid) == joystick_map.end()) { if (joystick_map.find(guid) == joystick_map.end()) {
auto joystick = std::make_shared<SDLJoystick>(guid, 0, sdl_joystick); auto joystick = std::make_shared<SDLJoystick>(guid, 0, sdl_joystick);
joystick_map[guid].emplace_back(std::move(joystick)); joystick_map[guid].emplace_back(std::move(joystick));
@ -221,7 +223,7 @@ void SDLState::CloseJoystick(SDL_Joystick* sdl_joystick) {
std::string guid = GetGUID(sdl_joystick); std::string guid = GetGUID(sdl_joystick);
std::shared_ptr<SDLJoystick> joystick; std::shared_ptr<SDLJoystick> joystick;
{ {
std::lock_guard<std::mutex> lock(joystick_map_mutex); std::lock_guard lock{joystick_map_mutex};
// This call to guid is safe since the joystick is guaranteed to be in the map // This call to guid is safe since the joystick is guaranteed to be in the map
auto& joystick_guid_list = joystick_map[guid]; auto& joystick_guid_list = joystick_map[guid];
const auto joystick_it = const auto joystick_it =
@ -274,7 +276,7 @@ void SDLState::HandleGameControllerEvent(const SDL_Event& event) {
} }
void SDLState::CloseJoysticks() { void SDLState::CloseJoysticks() {
std::lock_guard<std::mutex> lock(joystick_map_mutex); std::lock_guard lock{joystick_map_mutex};
joystick_map.clear(); joystick_map.clear();
} }

View file

@ -165,7 +165,7 @@ void Client::OnPadData(Response::PadData data) {
Common::Vec3f accel = Common::MakeVec<float>(-data.accel.x, data.accel.y, -data.accel.z); Common::Vec3f accel = Common::MakeVec<float>(-data.accel.x, data.accel.y, -data.accel.z);
Common::Vec3f gyro = Common::MakeVec<float>(-data.gyro.pitch, -data.gyro.yaw, data.gyro.roll); Common::Vec3f gyro = Common::MakeVec<float>(-data.gyro.pitch, -data.gyro.yaw, data.gyro.roll);
{ {
std::lock_guard<std::mutex> guard(status->update_mutex); std::lock_guard guard(status->update_mutex);
status->motion_status = {accel, gyro}; status->motion_status = {accel, gyro};

View file

@ -15,7 +15,7 @@ class UDPTouchDevice final : public Input::TouchDevice {
public: public:
explicit UDPTouchDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {} explicit UDPTouchDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
std::tuple<float, float, bool> GetStatus() const { std::tuple<float, float, bool> GetStatus() const {
std::lock_guard<std::mutex> guard(status->update_mutex); std::lock_guard guard(status->update_mutex);
return status->touch_status; return status->touch_status;
} }
@ -27,7 +27,7 @@ class UDPMotionDevice final : public Input::MotionDevice {
public: public:
explicit UDPMotionDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {} explicit UDPMotionDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() const { std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() const {
std::lock_guard<std::mutex> guard(status->update_mutex); std::lock_guard guard(status->update_mutex);
return status->motion_status; return status->motion_status;
} }
@ -41,7 +41,7 @@ public:
std::unique_ptr<Input::TouchDevice> Create(const Common::ParamPackage& params) override { std::unique_ptr<Input::TouchDevice> Create(const Common::ParamPackage& params) override {
{ {
std::lock_guard<std::mutex> guard(status->update_mutex); std::lock_guard guard(status->update_mutex);
status->touch_calibration.emplace(); status->touch_calibration.emplace();
// These default values work well for DS4 but probably not other touch inputs // These default values work well for DS4 but probably not other touch inputs
status->touch_calibration->min_x = params.Get("min_x", 100); status->touch_calibration->min_x = params.Get("min_x", 100);

View file

@ -302,7 +302,7 @@ void Room::RoomImpl::StartLoop() {
void Room::RoomImpl::HandleJoinRequest(const ENetEvent* event) { void Room::RoomImpl::HandleJoinRequest(const ENetEvent* event) {
{ {
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
if (members.size() >= room_information.member_slots) { if (members.size() >= room_information.member_slots) {
SendRoomIsFull(event->peer); SendRoomIsFull(event->peer);
return; return;
@ -369,13 +369,13 @@ void Room::RoomImpl::HandleJoinRequest(const ENetEvent* event) {
std::string uid; std::string uid;
{ {
std::lock_guard<std::mutex> lock(verify_UID_mutex); std::lock_guard lock(verify_UID_mutex);
uid = verify_UID; uid = verify_UID;
} }
member.user_data = verify_backend->LoadUserData(uid, token); member.user_data = verify_backend->LoadUserData(uid, token);
{ {
std::lock_guard<std::mutex> lock(ban_list_mutex); std::lock_guard lock(ban_list_mutex);
// Check username ban // Check username ban
if (!member.user_data.username.empty() && if (!member.user_data.username.empty() &&
@ -401,7 +401,7 @@ void Room::RoomImpl::HandleJoinRequest(const ENetEvent* event) {
SendStatusMessage(IdMemberJoin, member.nickname, member.user_data.username); SendStatusMessage(IdMemberJoin, member.nickname, member.user_data.username);
{ {
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
members.push_back(std::move(member)); members.push_back(std::move(member));
} }
@ -429,7 +429,7 @@ void Room::RoomImpl::HandleModKickPacket(const ENetEvent* event) {
std::string username; std::string username;
{ {
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
const auto target_member = const auto target_member =
std::find_if(members.begin(), members.end(), std::find_if(members.begin(), members.end(),
[&nickname](const auto& member) { return member.nickname == nickname; }); [&nickname](const auto& member) { return member.nickname == nickname; });
@ -469,7 +469,7 @@ void Room::RoomImpl::HandleModBanPacket(const ENetEvent* event) {
std::string ip; std::string ip;
{ {
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
const auto target_member = const auto target_member =
std::find_if(members.begin(), members.end(), std::find_if(members.begin(), members.end(),
[&nickname](const auto& member) { return member.nickname == nickname; }); [&nickname](const auto& member) { return member.nickname == nickname; });
@ -493,7 +493,7 @@ void Room::RoomImpl::HandleModBanPacket(const ENetEvent* event) {
} }
{ {
std::lock_guard<std::mutex> lock(ban_list_mutex); std::lock_guard lock(ban_list_mutex);
if (!username.empty()) { if (!username.empty()) {
// Ban the forum username // Ban the forum username
@ -530,7 +530,7 @@ void Room::RoomImpl::HandleModUnbanPacket(const ENetEvent* event) {
bool unbanned = false; bool unbanned = false;
{ {
std::lock_guard<std::mutex> lock(ban_list_mutex); std::lock_guard lock(ban_list_mutex);
auto it = std::find(username_ban_list.begin(), username_ban_list.end(), address); auto it = std::find(username_ban_list.begin(), username_ban_list.end(), address);
if (it != username_ban_list.end()) { if (it != username_ban_list.end()) {
@ -568,28 +568,28 @@ bool Room::RoomImpl::IsValidNickname(const std::string& nickname) const {
if (!std::regex_match(nickname, nickname_regex)) if (!std::regex_match(nickname, nickname_regex))
return false; return false;
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
return std::all_of(members.begin(), members.end(), return std::all_of(members.begin(), members.end(),
[&nickname](const auto& member) { return member.nickname != nickname; }); [&nickname](const auto& member) { return member.nickname != nickname; });
} }
bool Room::RoomImpl::IsValidMacAddress(const MacAddress& address) const { bool Room::RoomImpl::IsValidMacAddress(const MacAddress& address) const {
// A MAC address is valid if it is not already taken by anybody else in the room. // A MAC address is valid if it is not already taken by anybody else in the room.
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
return std::all_of(members.begin(), members.end(), return std::all_of(members.begin(), members.end(),
[&address](const auto& member) { return member.mac_address != address; }); [&address](const auto& member) { return member.mac_address != address; });
} }
bool Room::RoomImpl::IsValidConsoleId(const std::string& console_id_hash) const { bool Room::RoomImpl::IsValidConsoleId(const std::string& console_id_hash) const {
// A Console ID is valid if it is not already taken by anybody else in the room. // A Console ID is valid if it is not already taken by anybody else in the room.
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
return std::all_of(members.begin(), members.end(), [&console_id_hash](const auto& member) { return std::all_of(members.begin(), members.end(), [&console_id_hash](const auto& member) {
return member.console_id_hash != console_id_hash; return member.console_id_hash != console_id_hash;
}); });
} }
bool Room::RoomImpl::HasModPermission(const ENetPeer* client) const { bool Room::RoomImpl::HasModPermission(const ENetPeer* client) const {
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
const auto sending_member = const auto sending_member =
std::find_if(members.begin(), members.end(), std::find_if(members.begin(), members.end(),
[client](const auto& member) { return member.peer == client; }); [client](const auto& member) { return member.peer == client; });
@ -734,7 +734,7 @@ void Room::RoomImpl::SendModBanListResponse(ENetPeer* client) {
Packet packet; Packet packet;
packet << static_cast<u8>(IdModBanListResponse); packet << static_cast<u8>(IdModBanListResponse);
{ {
std::lock_guard<std::mutex> lock(ban_list_mutex); std::lock_guard lock(ban_list_mutex);
packet << username_ban_list; packet << username_ban_list;
packet << ip_ban_list; packet << ip_ban_list;
} }
@ -748,7 +748,7 @@ void Room::RoomImpl::SendModBanListResponse(ENetPeer* client) {
void Room::RoomImpl::SendCloseMessage() { void Room::RoomImpl::SendCloseMessage() {
Packet packet; Packet packet;
packet << static_cast<u8>(IdCloseRoom); packet << static_cast<u8>(IdCloseRoom);
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
if (!members.empty()) { if (!members.empty()) {
ENetPacket* enet_packet = ENetPacket* enet_packet =
enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE); enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE);
@ -769,7 +769,7 @@ void Room::RoomImpl::SendStatusMessage(StatusMessageTypes type, const std::strin
packet << static_cast<u8>(type); packet << static_cast<u8>(type);
packet << nickname; packet << nickname;
packet << username; packet << username;
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
if (!members.empty()) { if (!members.empty()) {
ENetPacket* enet_packet = ENetPacket* enet_packet =
enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE); enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE);
@ -792,7 +792,7 @@ void Room::RoomImpl::BroadcastRoomInformation() {
packet << static_cast<u32>(members.size()); packet << static_cast<u32>(members.size());
{ {
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
for (const auto& member : members) { for (const auto& member : members) {
packet << member.nickname; packet << member.nickname;
packet << member.mac_address; packet << member.mac_address;
@ -838,7 +838,7 @@ void Room::RoomImpl::HandleWifiPacket(const ENetEvent* event) {
ENET_PACKET_FLAG_RELIABLE); ENET_PACKET_FLAG_RELIABLE);
if (destination_address == BroadcastMac) { // Send the data to everyone except the sender if (destination_address == BroadcastMac) { // Send the data to everyone except the sender
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
bool sent_packet = false; bool sent_packet = false;
for (const auto& member : members) { for (const auto& member : members) {
if (member.peer != event->peer) { if (member.peer != event->peer) {
@ -851,7 +851,7 @@ void Room::RoomImpl::HandleWifiPacket(const ENetEvent* event) {
enet_packet_destroy(enet_packet); enet_packet_destroy(enet_packet);
} }
} else { // Send the data only to the destination client } else { // Send the data only to the destination client
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
auto member = std::find_if(members.begin(), members.end(), auto member = std::find_if(members.begin(), members.end(),
[destination_address](const Member& member) -> bool { [destination_address](const Member& member) -> bool {
return member.mac_address == destination_address; return member.mac_address == destination_address;
@ -881,7 +881,7 @@ void Room::RoomImpl::HandleChatPacket(const ENetEvent* event) {
return member.peer == event->peer; return member.peer == event->peer;
}; };
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
const auto sending_member = std::find_if(members.begin(), members.end(), CompareNetworkAddress); const auto sending_member = std::find_if(members.begin(), members.end(), CompareNetworkAddress);
if (sending_member == members.end()) { if (sending_member == members.end()) {
return; // Received a chat message from a unknown sender return; // Received a chat message from a unknown sender
@ -923,7 +923,7 @@ void Room::RoomImpl::HandleGameNamePacket(const ENetEvent* event) {
in_packet >> game_info.id; in_packet >> game_info.id;
{ {
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
auto member = auto member =
std::find_if(members.begin(), members.end(), [event](const Member& member) -> bool { std::find_if(members.begin(), members.end(), [event](const Member& member) -> bool {
return member.peer == event->peer; return member.peer == event->peer;
@ -939,7 +939,7 @@ void Room::RoomImpl::HandleClientDisconnection(ENetPeer* client) {
// Remove the client from the members list. // Remove the client from the members list.
std::string nickname, username; std::string nickname, username;
{ {
std::lock_guard<std::mutex> lock(member_mutex); std::lock_guard lock(member_mutex);
auto member = std::find_if(members.begin(), members.end(), [client](const Member& member) { auto member = std::find_if(members.begin(), members.end(), [client](const Member& member) {
return member.peer == client; return member.peer == client;
}); });
@ -1009,18 +1009,18 @@ const RoomInformation& Room::GetRoomInformation() const {
} }
std::string Room::GetVerifyUID() const { std::string Room::GetVerifyUID() const {
std::lock_guard<std::mutex> lock(room_impl->verify_UID_mutex); std::lock_guard lock(room_impl->verify_UID_mutex);
return room_impl->verify_UID; return room_impl->verify_UID;
} }
Room::BanList Room::GetBanList() const { Room::BanList Room::GetBanList() const {
std::lock_guard<std::mutex> lock(room_impl->ban_list_mutex); std::lock_guard lock(room_impl->ban_list_mutex);
return {room_impl->username_ban_list, room_impl->ip_ban_list}; return {room_impl->username_ban_list, room_impl->ip_ban_list};
} }
std::vector<Room::Member> Room::GetRoomMemberList() const { std::vector<Room::Member> Room::GetRoomMemberList() const {
std::vector<Room::Member> member_list; std::vector<Room::Member> member_list;
std::lock_guard<std::mutex> lock(room_impl->member_mutex); std::lock_guard lock(room_impl->member_mutex);
for (const auto& member_impl : room_impl->members) { for (const auto& member_impl : room_impl->members) {
Member member; Member member;
member.nickname = member_impl.nickname; member.nickname = member_impl.nickname;
@ -1039,7 +1039,7 @@ bool Room::HasPassword() const {
} }
void Room::SetVerifyUID(const std::string& uid) { void Room::SetVerifyUID(const std::string& uid) {
std::lock_guard<std::mutex> lock(room_impl->verify_UID_mutex); std::lock_guard lock(room_impl->verify_UID_mutex);
room_impl->verify_UID = uid; room_impl->verify_UID = uid;
} }
@ -1054,7 +1054,7 @@ void Room::Destroy() {
room_impl->room_information = {}; room_impl->room_information = {};
room_impl->server = nullptr; room_impl->server = nullptr;
{ {
std::lock_guard<std::mutex> lock(room_impl->member_mutex); std::lock_guard lock(room_impl->member_mutex);
room_impl->members.clear(); room_impl->members.clear();
} }
room_impl->room_information.member_slots = 0; room_impl->room_information.member_slots = 0;

View file

@ -157,7 +157,7 @@ bool RoomMember::RoomMemberImpl::IsConnected() const {
void RoomMember::RoomMemberImpl::MemberLoop() { void RoomMember::RoomMemberImpl::MemberLoop() {
// Receive packets while the connection is open // Receive packets while the connection is open
while (IsConnected()) { while (IsConnected()) {
std::lock_guard<std::mutex> lock(network_mutex); std::lock_guard lock(network_mutex);
ENetEvent event; ENetEvent event;
if (enet_host_service(client, &event, 100) > 0) { if (enet_host_service(client, &event, 100) > 0) {
switch (event.type) { switch (event.type) {
@ -245,7 +245,7 @@ void RoomMember::RoomMemberImpl::MemberLoop() {
} }
} }
{ {
std::lock_guard<std::mutex> lock(send_list_mutex); std::lock_guard lock(send_list_mutex);
for (const auto& packet : send_list) { for (const auto& packet : send_list) {
ENetPacket* enetPacket = enet_packet_create(packet.GetData(), packet.GetDataSize(), ENetPacket* enetPacket = enet_packet_create(packet.GetData(), packet.GetDataSize(),
ENET_PACKET_FLAG_RELIABLE); ENET_PACKET_FLAG_RELIABLE);
@ -263,7 +263,7 @@ void RoomMember::RoomMemberImpl::StartLoop() {
} }
void RoomMember::RoomMemberImpl::Send(Packet&& packet) { void RoomMember::RoomMemberImpl::Send(Packet&& packet) {
std::lock_guard<std::mutex> lock(send_list_mutex); std::lock_guard lock(send_list_mutex);
send_list.push_back(std::move(packet)); send_list.push_back(std::move(packet));
} }
@ -318,7 +318,7 @@ void RoomMember::RoomMemberImpl::HandleRoomInformationPacket(const ENetEvent* ev
packet >> member.avatar_url; packet >> member.avatar_url;
{ {
std::lock_guard<std::mutex> lock(username_mutex); std::lock_guard lock(username_mutex);
if (member.nickname == nickname) { if (member.nickname == nickname) {
username = member.username; username = member.username;
} }
@ -473,7 +473,7 @@ RoomMember::RoomMemberImpl::Callbacks::Get() {
template <typename T> template <typename T>
void RoomMember::RoomMemberImpl::Invoke(const T& data) { void RoomMember::RoomMemberImpl::Invoke(const T& data) {
std::lock_guard<std::mutex> lock(callback_mutex); std::lock_guard lock(callback_mutex);
CallbackSet<T> callback_set = callbacks.Get<T>(); CallbackSet<T> callback_set = callbacks.Get<T>();
for (auto const& callback : callback_set) for (auto const& callback : callback_set)
(*callback)(data); (*callback)(data);
@ -482,7 +482,7 @@ void RoomMember::RoomMemberImpl::Invoke(const T& data) {
template <typename T> template <typename T>
RoomMember::CallbackHandle<T> RoomMember::RoomMemberImpl::Bind( RoomMember::CallbackHandle<T> RoomMember::RoomMemberImpl::Bind(
std::function<void(const T&)> callback) { std::function<void(const T&)> callback) {
std::lock_guard<std::mutex> lock(callback_mutex); std::lock_guard lock(callback_mutex);
CallbackHandle<T> handle; CallbackHandle<T> handle;
handle = std::make_shared<std::function<void(const T&)>>(callback); handle = std::make_shared<std::function<void(const T&)>>(callback);
callbacks.Get<T>().insert(handle); callbacks.Get<T>().insert(handle);
@ -512,7 +512,7 @@ const std::string& RoomMember::GetNickname() const {
} }
const std::string& RoomMember::GetUsername() const { const std::string& RoomMember::GetUsername() const {
std::lock_guard<std::mutex> lock(room_member_impl->username_mutex); std::lock_guard lock(room_member_impl->username_mutex);
return room_member_impl->username; return room_member_impl->username;
} }
@ -663,7 +663,7 @@ RoomMember::CallbackHandle<Room::BanList> RoomMember::BindOnBanListReceived(
template <typename T> template <typename T>
void RoomMember::Unbind(CallbackHandle<T> handle) { void RoomMember::Unbind(CallbackHandle<T> handle) {
std::lock_guard<std::mutex> lock(room_member_impl->callback_mutex); std::lock_guard lock(room_member_impl->callback_mutex);
room_member_impl->callbacks.Get<T>().erase(handle); room_member_impl->callbacks.Get<T>().erase(handle);
} }

View file

@ -43,7 +43,7 @@ namespace Pica {
void DebugContext::DoOnEvent(Event event, void* data) { void DebugContext::DoOnEvent(Event event, void* data) {
{ {
std::unique_lock<std::mutex> lock(breakpoint_mutex); std::unique_lock lock{breakpoint_mutex};
// Commit the rasterizer's caches so framebuffers, render targets, etc. will show on debug // Commit the rasterizer's caches so framebuffers, render targets, etc. will show on debug
// widgets // widgets
@ -66,7 +66,7 @@ void DebugContext::DoOnEvent(Event event, void* data) {
void DebugContext::Resume() { void DebugContext::Resume() {
{ {
std::lock_guard<std::mutex> lock(breakpoint_mutex); std::lock_guard lock{breakpoint_mutex};
// Tell all observers that we are about to resume // Tell all observers that we are about to resume
for (auto& breakpoint_observer : breakpoint_observers) { for (auto& breakpoint_observer : breakpoint_observers) {
@ -282,14 +282,14 @@ void StartPicaTracing() {
return; return;
} }
std::lock_guard<std::mutex> lock(pica_trace_mutex); std::lock_guard lock(pica_trace_mutex);
pica_trace = std::make_unique<PicaTrace>(); pica_trace = std::make_unique<PicaTrace>();
g_is_pica_tracing = true; g_is_pica_tracing = true;
} }
void OnPicaRegWrite(PicaTrace::Write write) { void OnPicaRegWrite(PicaTrace::Write write) {
std::lock_guard<std::mutex> lock(pica_trace_mutex); std::lock_guard lock(pica_trace_mutex);
if (!g_is_pica_tracing) if (!g_is_pica_tracing)
return; return;
@ -307,7 +307,7 @@ std::unique_ptr<PicaTrace> FinishPicaTracing() {
g_is_pica_tracing = false; g_is_pica_tracing = false;
// Wait until running tracing is finished // Wait until running tracing is finished
std::lock_guard<std::mutex> lock(pica_trace_mutex); std::lock_guard lock(pica_trace_mutex);
std::unique_ptr<PicaTrace> ret(std::move(pica_trace)); std::unique_ptr<PicaTrace> ret(std::move(pica_trace));
return ret; return ret;

View file

@ -63,14 +63,14 @@ public:
/// Constructs the object such that it observes events of the given DebugContext. /// Constructs the object such that it observes events of the given DebugContext.
BreakPointObserver(std::shared_ptr<DebugContext> debug_context) BreakPointObserver(std::shared_ptr<DebugContext> debug_context)
: context_weak(debug_context) { : context_weak(debug_context) {
std::unique_lock<std::mutex> lock(debug_context->breakpoint_mutex); std::unique_lock lock{debug_context->breakpoint_mutex};
debug_context->breakpoint_observers.push_back(this); debug_context->breakpoint_observers.push_back(this);
} }
virtual ~BreakPointObserver() { virtual ~BreakPointObserver() {
auto context = context_weak.lock(); auto context = context_weak.lock();
if (context) { if (context) {
std::unique_lock<std::mutex> lock(context->breakpoint_mutex); std::unique_lock lock(context->breakpoint_mutex);
context->breakpoint_observers.remove(this); context->breakpoint_observers.remove(this);
// If we are the last observer to be destroyed, tell the debugger context that // If we are the last observer to be destroyed, tell the debugger context that

View file

@ -26,7 +26,7 @@ constexpr std::size_t TIMEOUT_SECONDS = 30;
struct Client::Impl { struct Client::Impl {
Impl(std::string host, std::string username, std::string token) Impl(std::string host, std::string username, std::string token)
: host{std::move(host)}, username{std::move(username)}, token{std::move(token)} { : host{std::move(host)}, username{std::move(username)}, token{std::move(token)} {
std::lock_guard<std::mutex> lock(jwt_cache.mutex); std::lock_guard lock{jwt_cache.mutex};
if (this->username == jwt_cache.username && this->token == jwt_cache.token) { if (this->username == jwt_cache.username && this->token == jwt_cache.token) {
jwt = jwt_cache.jwt; jwt = jwt_cache.jwt;
} }
@ -154,7 +154,7 @@ struct Client::Impl {
if (result.result_code != Common::WebResult::Code::Success) { if (result.result_code != Common::WebResult::Code::Success) {
LOG_ERROR(WebService, "UpdateJWT failed"); LOG_ERROR(WebService, "UpdateJWT failed");
} else { } else {
std::lock_guard<std::mutex> lock(jwt_cache.mutex); std::lock_guard lock{jwt_cache.mutex};
jwt_cache.username = username; jwt_cache.username = username;
jwt_cache.token = token; jwt_cache.token = token;
jwt_cache.jwt = jwt = result.returned_data; jwt_cache.jwt = jwt = result.returned_data;