Skip to content

Commit f660f15

Browse files
committed
Misc: use std::lock_guard
1 parent 74db386 commit f660f15

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

pcsx2-qt/Debugger/DebuggerSettingsManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void DebuggerSettingsManager::saveGameSettings(QAbstractTableModel* abstractTabl
153153
if (path.empty())
154154
return;
155155

156-
const std::lock_guard<std::mutex> lock(writeLock);
156+
std::lock_guard<std::mutex> lock(writeLock);
157157
QJsonObject loadedSettings = loadGameSettingsJSON();
158158
QJsonArray rowsArray;
159159
QStringList keys;

pcsx2/Host.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ std::pair<const char*, u32> Host::LookupTranslationString(const std::string_view
7171

7272
add_string:
7373
s_translation_string_mutex.unlock_shared();
74-
s_translation_string_mutex.lock();
74+
std::lock_guard lock(s_translation_string_mutex);
7575

7676
if (s_translation_string_cache.empty()) [[unlikely]]
7777
{
@@ -110,7 +110,6 @@ std::pair<const char*, u32> Host::LookupTranslationString(const std::string_view
110110

111111
ret.first = &s_translation_string_cache[insert_pos];
112112
ret.second = static_cast<u32>(len);
113-
s_translation_string_mutex.unlock();
114113
return ret;
115114
}
116115

@@ -132,10 +131,9 @@ std::string Host::TranslateToString(const std::string_view context, const std::s
132131

133132
void Host::ClearTranslationCache()
134133
{
135-
s_translation_string_mutex.lock();
134+
std::lock_guard lock(s_translation_string_mutex);
136135
s_translation_string_map.clear();
137136
s_translation_string_cache_pos = 0;
138-
s_translation_string_mutex.unlock();
139137
}
140138

141139
void Host::ReportFormattedInfoAsync(const std::string_view title, const char* format, ...)

pcsx2/USB/usb-eyetoy/cam-linux.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@ namespace usb_eyetoy
5656

5757
static void store_mpeg_frame(const unsigned char* data, const unsigned int len)
5858
{
59-
mpeg_mutex.lock();
59+
std::lock_guard lock(mpeg_mutex);
6060
if (len > 0)
6161
memcpy(mpeg_buffer.start, data, len);
6262
mpeg_buffer.length = len;
63-
mpeg_mutex.unlock();
6463
}
6564

6665
static void process_image(const unsigned char* data, int size)
@@ -642,13 +641,12 @@ namespace usb_eyetoy
642641

643642
int V4L2::GetImage(uint8_t* buf, size_t len)
644643
{
645-
mpeg_mutex.lock();
644+
std::lock_guard lock(mpeg_mutex);
646645
int len2 = mpeg_buffer.length;
647646
if (len < mpeg_buffer.length)
648647
len2 = len;
649648
memcpy(buf, mpeg_buffer.start, len2);
650649
mpeg_buffer.length = 0;
651-
mpeg_mutex.unlock();
652650
return len2;
653651
};
654652

pcsx2/USB/usb-eyetoy/cam-windows.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,10 @@ namespace usb_eyetoy
374374

375375
void store_mpeg_frame(const unsigned char* data, const unsigned int len)
376376
{
377-
mpeg_mutex.lock();
377+
std::lock_guard lock(mpeg_mutex);
378378
if (len > 0)
379379
memcpy(mpeg_buffer.start, data, len);
380380
mpeg_buffer.length = len;
381-
mpeg_mutex.unlock();
382381
}
383382

384383
void dshow_callback(unsigned char* data, int len, int bitsperpixel)
@@ -593,13 +592,12 @@ namespace usb_eyetoy
593592

594593
int DirectShow::GetImage(uint8_t* buf, size_t len)
595594
{
596-
mpeg_mutex.lock();
595+
std::lock_guard lock(mpeg_mutex);
597596
int len2 = mpeg_buffer.length;
598597
if (static_cast<size_t>(len) < mpeg_buffer.length)
599598
len2 = len;
600599
memcpy(buf, mpeg_buffer.start, len2);
601600
mpeg_buffer.length = 0;
602-
mpeg_mutex.unlock();
603601
return len2;
604602
};
605603

0 commit comments

Comments
 (0)