mirror of
https://github.com/stenzek/duckstation.git
synced 2025-06-28 22:30:11 +00:00
Always use CTAD with std::unique_lock
This commit is contained in:
parent
2c7d07b245
commit
70225f8345
@ -34,7 +34,7 @@ void CDROMAsyncReader::StopThread()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
std::unique_lock lock(m_mutex);
|
||||||
m_shutdown_flag.store(true);
|
m_shutdown_flag.store(true);
|
||||||
m_do_read_cv.notify_one();
|
m_do_read_cv.notify_one();
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ void CDROMAsyncReader::QueueReadSector(CDImage::LBA lba)
|
|||||||
|
|
||||||
// we need to toss away our readahead and start fresh
|
// we need to toss away our readahead and start fresh
|
||||||
DEBUG_LOG("Readahead buffer miss, queueing seek to {}", lba);
|
DEBUG_LOG("Readahead buffer miss, queueing seek to {}", lba);
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
std::unique_lock lock(m_mutex);
|
||||||
m_next_position_set.store(true);
|
m_next_position_set.store(true);
|
||||||
m_next_position = lba;
|
m_next_position = lba;
|
||||||
m_do_read_cv.notify_one();
|
m_do_read_cv.notify_one();
|
||||||
@ -190,7 +190,7 @@ bool CDROMAsyncReader::WaitForReadToComplete()
|
|||||||
Timer wait_timer;
|
Timer wait_timer;
|
||||||
DEBUG_LOG("Sector read pending, waiting");
|
DEBUG_LOG("Sector read pending, waiting");
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
std::unique_lock lock(m_mutex);
|
||||||
m_notify_read_complete_cv.wait(
|
m_notify_read_complete_cv.wait(
|
||||||
lock, [this]() { return (m_buffer_count.load() > 0 || m_seek_error.load()) && !m_next_position_set.load(); });
|
lock, [this]() { return (m_buffer_count.load() > 0 || m_seek_error.load()) && !m_next_position_set.load(); });
|
||||||
if (m_seek_error.load()) [[unlikely]]
|
if (m_seek_error.load()) [[unlikely]]
|
||||||
@ -213,7 +213,7 @@ void CDROMAsyncReader::WaitForIdle()
|
|||||||
if (!IsUsingThread())
|
if (!IsUsingThread())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
std::unique_lock lock(m_mutex);
|
||||||
m_notify_read_complete_cv.wait(lock, [this]() { return (!m_is_reading.load() && !m_next_position_set.load()); });
|
m_notify_read_complete_cv.wait(lock, [this]() { return (!m_is_reading.load() && !m_next_position_set.load()); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,7 +761,7 @@ void GameList::PopulateEntryAchievements(Entry* entry, const Achievements::Progr
|
|||||||
void GameList::UpdateAchievementData(const std::span<u8, 16> hash, u32 game_id, u32 num_achievements, u32 num_unlocked,
|
void GameList::UpdateAchievementData(const std::span<u8, 16> hash, u32 game_id, u32 num_achievements, u32 num_unlocked,
|
||||||
u32 num_unlocked_hardcore)
|
u32 num_unlocked_hardcore)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::recursive_mutex> lock(s_mutex);
|
std::unique_lock lock(s_mutex);
|
||||||
llvm::SmallVector<u32, 32> changed_indices;
|
llvm::SmallVector<u32, 32> changed_indices;
|
||||||
|
|
||||||
for (size_t i = 0; i < s_entries.size(); i++)
|
for (size_t i = 0; i < s_entries.size(); i++)
|
||||||
@ -801,7 +801,7 @@ void GameList::UpdateAllAchievementData()
|
|||||||
WARNING_LOG("Failed to load achievements progress: {}", error.GetDescription());
|
WARNING_LOG("Failed to load achievements progress: {}", error.GetDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_lock<std::recursive_mutex> lock(s_mutex);
|
std::unique_lock lock(s_mutex);
|
||||||
|
|
||||||
// this is pretty jank, but the frontend should collapse it into a single update
|
// this is pretty jank, but the frontend should collapse it into a single update
|
||||||
std::vector<u32> changed_indices;
|
std::vector<u32> changed_indices;
|
||||||
@ -856,7 +856,7 @@ void GameList::UpdateAllAchievementData()
|
|||||||
|
|
||||||
std::unique_lock<std::recursive_mutex> GameList::GetLock()
|
std::unique_lock<std::recursive_mutex> GameList::GetLock()
|
||||||
{
|
{
|
||||||
return std::unique_lock<std::recursive_mutex>(s_mutex);
|
return std::unique_lock(s_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
const GameList::Entry* GameList::GetEntryByIndex(u32 index)
|
const GameList::Entry* GameList::GetEntryByIndex(u32 index)
|
||||||
@ -1437,7 +1437,7 @@ void GameList::AddPlayedTimeForSerial(const std::string& serial, std::time_t las
|
|||||||
VERBOSE_LOG("Add {} seconds play time to {} -> now {}", static_cast<unsigned>(add_time), serial.c_str(),
|
VERBOSE_LOG("Add {} seconds play time to {} -> now {}", static_cast<unsigned>(add_time), serial.c_str(),
|
||||||
static_cast<unsigned>(pt.total_played_time));
|
static_cast<unsigned>(pt.total_played_time));
|
||||||
|
|
||||||
std::unique_lock<std::recursive_mutex> lock(s_mutex);
|
std::unique_lock lock(s_mutex);
|
||||||
const GameDatabase::Entry* dbentry = GameDatabase::GetEntryForSerial(serial);
|
const GameDatabase::Entry* dbentry = GameDatabase::GetEntryForSerial(serial);
|
||||||
llvm::SmallVector<u32, 32> changed_indices;
|
llvm::SmallVector<u32, 32> changed_indices;
|
||||||
|
|
||||||
@ -1476,7 +1476,7 @@ void GameList::ClearPlayedTimeForSerial(const std::string& serial)
|
|||||||
|
|
||||||
UpdatePlayedTimeFile(GetPlayedTimeFile(), serial, 0, 0);
|
UpdatePlayedTimeFile(GetPlayedTimeFile(), serial, 0, 0);
|
||||||
|
|
||||||
std::unique_lock<std::recursive_mutex> lock(s_mutex);
|
std::unique_lock lock(s_mutex);
|
||||||
for (GameList::Entry& entry : s_entries)
|
for (GameList::Entry& entry : s_entries)
|
||||||
{
|
{
|
||||||
if (entry.serial != serial)
|
if (entry.serial != serial)
|
||||||
@ -1528,7 +1528,7 @@ std::time_t GameList::GetCachedPlayedTimeForSerial(const std::string& serial)
|
|||||||
if (serial.empty())
|
if (serial.empty())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
std::unique_lock<std::recursive_mutex> lock(s_mutex);
|
std::unique_lock lock(s_mutex);
|
||||||
for (GameList::Entry& entry : s_entries)
|
for (GameList::Entry& entry : s_entries)
|
||||||
{
|
{
|
||||||
if (entry.serial == serial)
|
if (entry.serial == serial)
|
||||||
|
@ -101,7 +101,7 @@ std::string Host::Internal::ComputeDataDirectory()
|
|||||||
|
|
||||||
std::unique_lock<std::mutex> Host::GetSettingsLock()
|
std::unique_lock<std::mutex> Host::GetSettingsLock()
|
||||||
{
|
{
|
||||||
return std::unique_lock<std::mutex>(s_settings_mutex);
|
return std::unique_lock(s_settings_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingsInterface* Host::GetSettingsInterface()
|
SettingsInterface* Host::GetSettingsInterface()
|
||||||
|
@ -1207,7 +1207,7 @@ void System::RecreateGPU(GPURenderer renderer)
|
|||||||
|
|
||||||
void System::LoadSettings(bool display_osd_messages)
|
void System::LoadSettings(bool display_osd_messages)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock = Host::GetSettingsLock();
|
auto lock = Host::GetSettingsLock();
|
||||||
const SettingsInterface& si = *Host::GetSettingsInterface();
|
const SettingsInterface& si = *Host::GetSettingsInterface();
|
||||||
const SettingsInterface& controller_si = GetControllerSettingsLayer(lock);
|
const SettingsInterface& controller_si = GetControllerSettingsLayer(lock);
|
||||||
const SettingsInterface& hotkey_si = GetHotkeySettingsLayer(lock);
|
const SettingsInterface& hotkey_si = GetHotkeySettingsLayer(lock);
|
||||||
@ -1244,7 +1244,7 @@ void System::LoadSettings(bool display_osd_messages)
|
|||||||
|
|
||||||
void System::ReloadInputSources()
|
void System::ReloadInputSources()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock = Host::GetSettingsLock();
|
auto lock = Host::GetSettingsLock();
|
||||||
const SettingsInterface& controller_si = GetControllerSettingsLayer(lock);
|
const SettingsInterface& controller_si = GetControllerSettingsLayer(lock);
|
||||||
InputManager::ReloadSources(controller_si, lock);
|
InputManager::ReloadSources(controller_si, lock);
|
||||||
|
|
||||||
@ -1262,7 +1262,7 @@ void System::ReloadInputBindings()
|
|||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock = Host::GetSettingsLock();
|
auto lock = Host::GetSettingsLock();
|
||||||
const SettingsInterface& controller_si = GetControllerSettingsLayer(lock);
|
const SettingsInterface& controller_si = GetControllerSettingsLayer(lock);
|
||||||
const SettingsInterface& hotkey_si = GetHotkeySettingsLayer(lock);
|
const SettingsInterface& hotkey_si = GetHotkeySettingsLayer(lock);
|
||||||
InputManager::ReloadBindings(controller_si, hotkey_si);
|
InputManager::ReloadBindings(controller_si, hotkey_si);
|
||||||
|
@ -45,7 +45,7 @@ void HTTPDownloader::CreateRequest(std::string url, Request::Callback callback,
|
|||||||
req->progress = progress;
|
req->progress = progress;
|
||||||
req->start_time = Timer::GetCurrentValue();
|
req->start_time = Timer::GetCurrentValue();
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(m_pending_http_request_lock);
|
std::unique_lock lock(m_pending_http_request_lock);
|
||||||
if (LockedGetActiveRequestCount() < m_max_active_requests)
|
if (LockedGetActiveRequestCount() < m_max_active_requests)
|
||||||
{
|
{
|
||||||
if (!StartRequest(req))
|
if (!StartRequest(req))
|
||||||
@ -67,7 +67,7 @@ void HTTPDownloader::CreatePostRequest(std::string url, std::string post_data, R
|
|||||||
req->progress = progress;
|
req->progress = progress;
|
||||||
req->start_time = Timer::GetCurrentValue();
|
req->start_time = Timer::GetCurrentValue();
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(m_pending_http_request_lock);
|
std::unique_lock lock(m_pending_http_request_lock);
|
||||||
if (LockedGetActiveRequestCount() < m_max_active_requests)
|
if (LockedGetActiveRequestCount() < m_max_active_requests)
|
||||||
{
|
{
|
||||||
if (!StartRequest(req))
|
if (!StartRequest(req))
|
||||||
@ -199,13 +199,13 @@ void HTTPDownloader::LockedPollRequests(std::unique_lock<std::mutex>& lock)
|
|||||||
|
|
||||||
void HTTPDownloader::PollRequests()
|
void HTTPDownloader::PollRequests()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(m_pending_http_request_lock);
|
std::unique_lock lock(m_pending_http_request_lock);
|
||||||
LockedPollRequests(lock);
|
LockedPollRequests(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPDownloader::WaitForAllRequests()
|
void HTTPDownloader::WaitForAllRequests()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(m_pending_http_request_lock);
|
std::unique_lock lock(m_pending_http_request_lock);
|
||||||
while (!m_pending_http_requests.empty())
|
while (!m_pending_http_requests.empty())
|
||||||
{
|
{
|
||||||
// Don't burn too much CPU.
|
// Don't burn too much CPU.
|
||||||
@ -232,7 +232,7 @@ u32 HTTPDownloader::LockedGetActiveRequestCount()
|
|||||||
|
|
||||||
bool HTTPDownloader::HasAnyRequests()
|
bool HTTPDownloader::HasAnyRequests()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(m_pending_http_request_lock);
|
std::unique_lock lock(m_pending_http_request_lock);
|
||||||
return !m_pending_http_requests.empty();
|
return !m_pending_http_requests.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ void CALLBACK HTTPDownloaderWinHttp::HTTPStatusCallback(HINTERNET hRequest, DWOR
|
|||||||
DebugAssert(hRequest == req->hRequest);
|
DebugAssert(hRequest == req->hRequest);
|
||||||
|
|
||||||
HTTPDownloaderWinHttp* parent = static_cast<HTTPDownloaderWinHttp*>(req->parent);
|
HTTPDownloaderWinHttp* parent = static_cast<HTTPDownloaderWinHttp*>(req->parent);
|
||||||
std::unique_lock<std::mutex> lock(parent->m_pending_http_request_lock);
|
std::unique_lock lock(parent->m_pending_http_request_lock);
|
||||||
Assert(std::none_of(parent->m_pending_http_requests.begin(), parent->m_pending_http_requests.end(),
|
Assert(std::none_of(parent->m_pending_http_requests.begin(), parent->m_pending_http_requests.end(),
|
||||||
[req](HTTPDownloader::Request* it) { return it == req; }));
|
[req](HTTPDownloader::Request* it) { return it == req; }));
|
||||||
|
|
||||||
|
@ -967,7 +967,7 @@ void ImGuiManager::AddOSDMessage(std::string key, std::string message, float dur
|
|||||||
msg.last_y = -1.0f;
|
msg.last_y = -1.0f;
|
||||||
msg.is_warning = is_warning;
|
msg.is_warning = is_warning;
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(s_state.osd_messages_lock);
|
std::unique_lock lock(s_state.osd_messages_lock);
|
||||||
s_state.osd_posted_messages.push_back(std::move(msg));
|
s_state.osd_posted_messages.push_back(std::move(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -978,14 +978,14 @@ void ImGuiManager::RemoveKeyedOSDMessage(std::string key, bool is_warning)
|
|||||||
msg.duration = 0.0f;
|
msg.duration = 0.0f;
|
||||||
msg.is_warning = is_warning;
|
msg.is_warning = is_warning;
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(s_state.osd_messages_lock);
|
std::unique_lock lock(s_state.osd_messages_lock);
|
||||||
s_state.osd_posted_messages.push_back(std::move(msg));
|
s_state.osd_posted_messages.push_back(std::move(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiManager::ClearOSDMessages(bool clear_warnings)
|
void ImGuiManager::ClearOSDMessages(bool clear_warnings)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(s_state.osd_messages_lock);
|
std::unique_lock lock(s_state.osd_messages_lock);
|
||||||
if (clear_warnings)
|
if (clear_warnings)
|
||||||
{
|
{
|
||||||
s_state.osd_posted_messages.clear();
|
s_state.osd_posted_messages.clear();
|
||||||
|
@ -255,7 +255,7 @@ GPUTexture* MediaCaptureBase::GetRenderTexture()
|
|||||||
|
|
||||||
bool MediaCaptureBase::DeliverVideoFrame(GPUTexture* stex)
|
bool MediaCaptureBase::DeliverVideoFrame(GPUTexture* stex)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(m_lock);
|
std::unique_lock lock(m_lock);
|
||||||
|
|
||||||
// If the encoder thread reported an error, stop the capture.
|
// If the encoder thread reported an error, stop the capture.
|
||||||
if (m_encoding_error.load(std::memory_order_acquire))
|
if (m_encoding_error.load(std::memory_order_acquire))
|
||||||
@ -330,7 +330,7 @@ void MediaCaptureBase::EncoderThreadEntryPoint()
|
|||||||
Threading::SetNameOfCurrentThread("Media Capture Encoding");
|
Threading::SetNameOfCurrentThread("Media Capture Encoding");
|
||||||
|
|
||||||
Error error;
|
Error error;
|
||||||
std::unique_lock<std::mutex> lock(m_lock);
|
std::unique_lock lock(m_lock);
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
@ -417,7 +417,7 @@ bool MediaCaptureBase::DeliverAudioFrames(const s16* frames, u32 num_frames)
|
|||||||
if ((audio_buffer_size - m_audio_buffer_size.load(std::memory_order_acquire)) < num_frames)
|
if ((audio_buffer_size - m_audio_buffer_size.load(std::memory_order_acquire)) < num_frames)
|
||||||
{
|
{
|
||||||
// Need to wait for it to drain a bit.
|
// Need to wait for it to drain a bit.
|
||||||
std::unique_lock<std::mutex> lock(m_lock);
|
std::unique_lock lock(m_lock);
|
||||||
m_frame_encoded_cv.wait(lock, [this, &num_frames, &audio_buffer_size]() {
|
m_frame_encoded_cv.wait(lock, [this, &num_frames, &audio_buffer_size]() {
|
||||||
return (!m_capturing.load(std::memory_order_acquire) ||
|
return (!m_capturing.load(std::memory_order_acquire) ||
|
||||||
((audio_buffer_size - m_audio_buffer_size.load(std::memory_order_acquire)) >= num_frames));
|
((audio_buffer_size - m_audio_buffer_size.load(std::memory_order_acquire)) >= num_frames));
|
||||||
@ -441,7 +441,7 @@ bool MediaCaptureBase::DeliverAudioFrames(const s16* frames, u32 num_frames)
|
|||||||
if (!IsCapturingVideo() && buffer_size >= m_audio_frame_size)
|
if (!IsCapturingVideo() && buffer_size >= m_audio_frame_size)
|
||||||
{
|
{
|
||||||
// If we're not capturing video, push "frames" when we hit the audio packet size.
|
// If we're not capturing video, push "frames" when we hit the audio packet size.
|
||||||
std::unique_lock<std::mutex> lock(m_lock);
|
std::unique_lock lock(m_lock);
|
||||||
if (!m_capturing.load(std::memory_order_acquire))
|
if (!m_capturing.load(std::memory_order_acquire))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -493,7 +493,7 @@ void MediaCaptureBase::ClearState()
|
|||||||
|
|
||||||
bool MediaCaptureBase::EndCapture(Error* error)
|
bool MediaCaptureBase::EndCapture(Error* error)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(m_lock);
|
std::unique_lock lock(m_lock);
|
||||||
if (!InternalEndCapture(lock, error))
|
if (!InternalEndCapture(lock, error))
|
||||||
{
|
{
|
||||||
DeleteOutputFile();
|
DeleteOutputFile();
|
||||||
@ -574,7 +574,7 @@ void MediaCaptureBase::UpdateCaptureThreadUsage(double pct_divider, double time_
|
|||||||
|
|
||||||
void MediaCaptureBase::Flush()
|
void MediaCaptureBase::Flush()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(m_lock);
|
std::unique_lock lock(m_lock);
|
||||||
|
|
||||||
if (m_encoding_error)
|
if (m_encoding_error)
|
||||||
return;
|
return;
|
||||||
@ -2063,7 +2063,7 @@ bool MediaCaptureFFmpeg::IsCapturingVideo() const
|
|||||||
|
|
||||||
time_t MediaCaptureFFmpeg::GetElapsedTime() const
|
time_t MediaCaptureFFmpeg::GetElapsedTime() const
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(m_lock);
|
std::unique_lock lock(m_lock);
|
||||||
s64 seconds;
|
s64 seconds;
|
||||||
if (m_video_stream)
|
if (m_video_stream)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user