Skip to content
Permalink
Browse files
Merge pull request #9389 from lioncash/deduction
Core: Make use of C++17 deduction guides with locks
  • Loading branch information
jordan-woyak committed Dec 29, 2020
2 parents 351fb71 + a8b0661 commit 92de043
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 98 deletions.
@@ -116,7 +116,7 @@ void ApplyCodes(const std::vector<ARCode>& codes)
if (!SConfig::GetInstance().bEnableCheats)
return;

std::lock_guard<std::mutex> guard(s_lock);
std::lock_guard guard(s_lock);
s_disable_logging = false;
s_active_codes.clear();
std::copy_if(codes.begin(), codes.end(), std::back_inserter(s_active_codes),
@@ -144,7 +144,7 @@ std::vector<ARCode> ApplyAndReturnCodes(const std::vector<ARCode>& codes)
{
if (SConfig::GetInstance().bEnableCheats)
{
std::lock_guard<std::mutex> guard(s_lock);
std::lock_guard guard(s_lock);
s_disable_logging = false;
s_active_codes.clear();
std::copy_if(codes.begin(), codes.end(), std::back_inserter(s_active_codes),
@@ -162,7 +162,7 @@ void AddCode(ARCode code)

if (code.enabled)
{
std::lock_guard<std::mutex> guard(s_lock);
std::lock_guard guard(s_lock);
s_disable_logging = false;
s_active_codes.emplace_back(std::move(code));
}
@@ -335,13 +335,13 @@ void EnableSelfLogging(bool enable)

std::vector<std::string> GetSelfLog()
{
std::lock_guard<std::mutex> guard(s_lock);
std::lock_guard guard(s_lock);
return s_internal_log;
}

void ClearSelfLog()
{
std::lock_guard<std::mutex> guard(s_lock);
std::lock_guard guard(s_lock);
s_internal_log.clear();
}

@@ -979,7 +979,7 @@ void RunAllActive()
// If the mutex is idle then acquiring it should be cheap, fast mutexes
// are only atomic ops unless contested. It should be rare for this to
// be contested.
std::lock_guard<std::mutex> guard(s_lock);
std::lock_guard guard(s_lock);
s_active_codes.erase(std::remove_if(s_active_codes.begin(), s_active_codes.end(),
[](const ARCode& code) {
bool success = RunCodeLocked(code);
@@ -1028,7 +1028,7 @@ void QueueHostJob(std::function<void()> job, bool run_during_stop)

bool send_message = false;
{
std::lock_guard<std::mutex> guard(s_host_jobs_lock);
std::lock_guard guard(s_host_jobs_lock);
send_message = s_host_jobs_queue.empty();
s_host_jobs_queue.emplace(HostJob{std::move(job), run_during_stop});
}
@@ -1042,7 +1042,7 @@ void HostDispatchJobs()
// WARNING: This should only run on the Host Thread.
// NOTE: This function is potentially re-entrant. If a job calls
// Core::Stop for instance then we'll enter this a second time.
std::unique_lock<std::mutex> guard(s_host_jobs_lock);
std::unique_lock guard(s_host_jobs_lock);
while (!s_host_jobs_queue.empty())
{
HostJob job = std::move(s_host_jobs_queue.front());
@@ -141,15 +141,15 @@ void Init()

void Shutdown()
{
std::lock_guard<std::mutex> lk(s_ts_write_lock);
std::lock_guard lk(s_ts_write_lock);
MoveEvents();
ClearPendingEvents();
UnregisterAllEvents();
}

void DoState(PointerWrap& p)
{
std::lock_guard<std::mutex> lk(s_ts_write_lock);
std::lock_guard lk(s_ts_write_lock);
p.Do(g.slice_length);
p.Do(g.global_timer);
p.Do(s_idled_cycles);
@@ -265,7 +265,7 @@ void ScheduleEvent(s64 cycles_into_future, EventType* event_type, u64 userdata,
*event_type->name);
}

std::lock_guard<std::mutex> lk(s_ts_write_lock);
std::lock_guard lk(s_ts_write_lock);
s_ts_queue.Push(Event{g.global_timer + cycles_into_future, 0, userdata, event_type});
}
}
@@ -66,7 +66,7 @@ static std::mutex s_active_codes_lock;

void SetActiveCodes(const std::vector<GeckoCode>& gcodes)
{
std::lock_guard<std::mutex> lk(s_active_codes_lock);
std::lock_guard lk(s_active_codes_lock);

s_active_codes.clear();
if (SConfig::GetInstance().bEnableCheats)
@@ -98,7 +98,7 @@ void UpdateSyncedCodes(const std::vector<GeckoCode>& gcodes)

std::vector<GeckoCode> SetAndReturnActiveCodes(const std::vector<GeckoCode>& gcodes)
{
std::lock_guard<std::mutex> lk(s_active_codes_lock);
std::lock_guard lk(s_active_codes_lock);

s_active_codes.clear();
if (SConfig::GetInstance().bEnableCheats)
@@ -218,14 +218,14 @@ static Installation InstallCodeHandlerLocked()
// modifications will be reset]
void DoState(PointerWrap& p)
{
std::lock_guard<std::mutex> codes_lock(s_active_codes_lock);
std::lock_guard codes_lock(s_active_codes_lock);
p.Do(s_code_handler_installed);
// FIXME: The active codes list will disagree with the embedded GCT
}

void Shutdown()
{
std::lock_guard<std::mutex> codes_lock(s_active_codes_lock);
std::lock_guard codes_lock(s_active_codes_lock);
s_active_codes.clear();
s_code_handler_installed = Installation::Uninstalled;
}
@@ -237,7 +237,7 @@ void RunCodeHandler()

// NOTE: Need to release the lock because of GUI deadlocks with PanicAlert in HostWrite_*
{
std::lock_guard<std::mutex> codes_lock(s_active_codes_lock);
std::lock_guard codes_lock(s_active_codes_lock);
if (s_code_handler_installed != Installation::Installed)
{
// Don't spam retry if the install failed. The corrupt / missing disk file is not likely to be
@@ -76,7 +76,7 @@ void GeckoSockServer::GeckoConnectionWaiter()
{
if (server.accept(*new_client) == sf::Socket::Done)
{
std::lock_guard<std::mutex> lk(connection_lock);
std::lock_guard lk(connection_lock);
waiting_socks.push(std::move(new_client));

new_client = std::make_unique<sf::TcpSocket>();
@@ -90,7 +90,7 @@ bool GeckoSockServer::GetAvailableSock()
{
bool sock_filled = false;

std::lock_guard<std::mutex> lk(connection_lock);
std::lock_guard lk(connection_lock);

if (!waiting_socks.empty())
{
@@ -125,7 +125,7 @@ void GeckoSockServer::ClientThread()
bool did_nothing = true;

{
std::lock_guard<std::mutex> lk(transfer_lock);
std::lock_guard lk(transfer_lock);

// what's an ideal buffer size?
std::array<char, 128> buffer;
@@ -186,7 +186,7 @@ void CEXIGecko::ImmReadWrite(u32& _uData, u32 _uSize)
// |= 0x08000000 if successful
case CMD_RECV:
{
std::lock_guard<std::mutex> lk(transfer_lock);
std::lock_guard lk(transfer_lock);
if (!recv_fifo.empty())
{
_uData = 0x08000000 | (recv_fifo.front() << 16);
@@ -199,7 +199,7 @@ void CEXIGecko::ImmReadWrite(u32& _uData, u32 _uSize)
// |= 0x04000000 if successful
case CMD_SEND:
{
std::lock_guard<std::mutex> lk(transfer_lock);
std::lock_guard lk(transfer_lock);
send_fifo.push_back(_uData >> 20);
_uData = 0x04000000;
break;
@@ -215,7 +215,7 @@ void CEXIGecko::ImmReadWrite(u32& _uData, u32 _uSize)
// |= 0x04000000 if data in recv FIFO
case CMD_CHK_RX:
{
std::lock_guard<std::mutex> lk(transfer_lock);
std::lock_guard lk(transfer_lock);
_uData = recv_fifo.empty() ? 0 : 0x04000000;
break;
}
@@ -45,7 +45,7 @@ long CEXIMic::DataCallback(cubeb_stream* stream, void* user_data, const void* in
{
CEXIMic* mic = static_cast<CEXIMic*>(user_data);

std::lock_guard<std::mutex> lk(mic->ring_lock);
std::lock_guard lk(mic->ring_lock);

const s16* buff_in = static_cast<const s16*>(input_buffer);
for (long i = 0; i < nframes; i++)
@@ -121,7 +121,7 @@ void CEXIMic::StreamStop()

void CEXIMic::StreamReadOne()
{
std::lock_guard<std::mutex> lk(ring_lock);
std::lock_guard lk(ring_lock);

if (samples_avail >= buff_size_samples)
{
@@ -328,7 +328,7 @@ s32 GCMemcardDirectory::Read(u32 src_address, s32 length, u8* dest_address)

s32 GCMemcardDirectory::Write(u32 dest_address, s32 length, const u8* src_address)
{
std::unique_lock<std::mutex> l(m_write_mutex);
std::unique_lock l(m_write_mutex);
if (length != 0x80)
INFO_LOG_FMT(EXPANSIONINTERFACE, "Writing to {:#x}. Length: {:#x}", dest_address, length);
s32 block = dest_address / Memcard::BLOCK_SIZE;
@@ -593,7 +593,7 @@ bool GCMemcardDirectory::SetUsedBlocks(int save_index)

void GCMemcardDirectory::FlushToFile()
{
std::unique_lock<std::mutex> l(m_write_mutex);
std::unique_lock l(m_write_mutex);
int errors = 0;
Memcard::DEntry invalid;
for (Memcard::GCIFile& save : m_saves)
@@ -686,7 +686,7 @@ void GCMemcardDirectory::FlushToFile()

void GCMemcardDirectory::DoState(PointerWrap& p)
{
std::unique_lock<std::mutex> l(m_write_mutex);
std::unique_lock l(m_write_mutex);
m_last_block = -1;
m_last_block_address = nullptr;
p.Do(m_save_directory);
@@ -191,7 +191,7 @@ void MemoryCard::FlushThread()
}

{
std::unique_lock<std::mutex> l(m_flush_mutex);
std::unique_lock l(m_flush_mutex);
memcpy(&m_flush_buffer[0], &m_memcard_data[0], m_memory_card_size);
}
file.WriteBytes(&m_flush_buffer[0], m_memory_card_size);
@@ -232,7 +232,7 @@ s32 MemoryCard::Write(u32 dest_address, s32 length, const u8* src_address)
}

{
std::unique_lock<std::mutex> l(m_flush_mutex);
std::unique_lock l(m_flush_mutex);
memcpy(&m_memcard_data[dest_address], src_address, length);
}
MakeDirty();
@@ -248,7 +248,7 @@ void MemoryCard::ClearBlock(u32 address)
}
else
{
std::unique_lock<std::mutex> l(m_flush_mutex);
std::unique_lock l(m_flush_mutex);
memset(&m_memcard_data[address], 0xFF, Memcard::BLOCK_SIZE);
}
MakeDirty();
@@ -257,7 +257,7 @@ void MemoryCard::ClearBlock(u32 address)
void MemoryCard::ClearAll()
{
{
std::unique_lock<std::mutex> l(m_flush_mutex);
std::unique_lock l(m_flush_mutex);
memset(&m_memcard_data[0], 0xFF, m_memory_card_size);
}
MakeDirty();
@@ -106,14 +106,14 @@ static void GBAConnectionWaiter()
{
if (server.accept(*new_client) == sf::Socket::Done)
{
std::lock_guard<std::mutex> lk(s_cs_gba);
std::lock_guard lk(s_cs_gba);
s_waiting_socks.push(std::move(new_client));

new_client = std::make_unique<sf::TcpSocket>();
}
if (clock_server.accept(*new_client) == sf::Socket::Done)
{
std::lock_guard<std::mutex> lk(s_cs_gba_clk);
std::lock_guard lk(s_cs_gba_clk);
s_waiting_clocks.push(std::move(new_client));

new_client = std::make_unique<sf::TcpSocket>();
@@ -142,13 +142,13 @@ static std::unique_ptr<T> MoveFromFront(std::queue<std::unique_ptr<T>>& ptrs)

static std::unique_ptr<sf::TcpSocket> GetNextSock()
{
std::lock_guard<std::mutex> lk(s_cs_gba);
std::lock_guard lk(s_cs_gba);
return MoveFromFront(s_waiting_socks);
}

static std::unique_ptr<sf::TcpSocket> GetNextClock()
{
std::lock_guard<std::mutex> lk(s_cs_gba_clk);
std::lock_guard lk(s_cs_gba_clk);
return MoveFromFront(s_waiting_clocks);
}

@@ -179,7 +179,7 @@ void ThrottleCallback(u64 last_time, s64 cyclesLate)
u32 next_event = GetTicksPerSecond() / 1000;

{
std::lock_guard<std::mutex> lk(s_emu_to_real_time_mutex);
std::lock_guard lk(s_emu_to_real_time_mutex);
s_emu_to_real_time_ring_buffer[s_emu_to_real_time_index] = time - s_time_spent_sleeping;
s_emu_to_real_time_index =
(s_emu_to_real_time_index + 1) % s_emu_to_real_time_ring_buffer.size();
@@ -252,7 +252,7 @@ double GetEstimatedEmulationPerformance()
{
u64 ts_now, ts_before; // In microseconds
{
std::lock_guard<std::mutex> lk(s_emu_to_real_time_mutex);
std::lock_guard lk(s_emu_to_real_time_mutex);
size_t index_now = s_emu_to_real_time_index == 0 ? s_emu_to_real_time_ring_buffer.size() - 1 :
s_emu_to_real_time_index - 1;
size_t index_before = s_emu_to_real_time_index;
@@ -140,7 +140,7 @@ Wiimote::Wiimote() = default;

void Wiimote::Shutdown()
{
std::lock_guard<std::mutex> lk(s_known_ids_mutex);
std::lock_guard lk(s_known_ids_mutex);
s_known_ids.erase(GetId());

StopThread();
@@ -550,7 +550,7 @@ void WiimoteScanner::SetScanMode(WiimoteScanMode scan_mode)

bool WiimoteScanner::IsReady() const
{
std::lock_guard<std::mutex> lg(m_backends_mutex);
std::lock_guard lg(m_backends_mutex);
return std::any_of(m_backends.begin(), m_backends.end(),
[](const auto& backend) { return backend->IsReady(); });
}
@@ -623,7 +623,7 @@ void WiimoteScanner::ThreadFunc()
// are called on different threads (and so reference different CFRunLoops) which can cause an
// EXC_BAD_ACCES crash.
{
std::lock_guard<std::mutex> lg(m_backends_mutex);
std::lock_guard lg(m_backends_mutex);

m_backends.emplace_back(std::make_unique<WiimoteScannerLinux>());
m_backends.emplace_back(std::make_unique<WiimoteScannerAndroid>());
@@ -670,7 +670,7 @@ void WiimoteScanner::ThreadFunc()
for (auto* wiimote : found_wiimotes)
{
{
std::lock_guard<std::mutex> lk(s_known_ids_mutex);
std::lock_guard lk(s_known_ids_mutex);
s_known_ids.insert(wiimote->GetId());
}

@@ -681,7 +681,7 @@ void WiimoteScanner::ThreadFunc()
if (found_board)
{
{
std::lock_guard<std::mutex> lk(s_known_ids_mutex);
std::lock_guard lk(s_known_ids_mutex);
s_known_ids.insert(found_board->GetId());
}

@@ -696,7 +696,7 @@ void WiimoteScanner::ThreadFunc()
}

{
std::lock_guard<std::mutex> lg(m_backends_mutex);
std::lock_guard lg(m_backends_mutex);
m_backends.clear();
}

@@ -942,7 +942,7 @@ bool IsBalanceBoardName(const std::string& name)
// This is called from the scanner backends (currently on the scanner thread).
bool IsNewWiimote(const std::string& identifier)
{
std::lock_guard<std::mutex> lk(s_known_ids_mutex);
std::lock_guard lk(s_known_ids_mutex);
return s_known_ids.count(identifier) == 0;
}

0 comments on commit 92de043

Please sign in to comment.