general: Use deducation guides for std::lock_guard and std::unique_lock
Since C++17, the introduction of deduction guides for locking facilities means that we no longer need to hardcode the mutex type into the locks themselves, making it easier to switch mutex types, should it ever be necessary in the future.
This commit is contained in:
parent
d9b7bc4474
commit
781ab8407b
23 changed files with 77 additions and 75 deletions
|
@ -36,18 +36,18 @@ struct KeyButtonPair {
|
|||
class KeyButtonList {
|
||||
public:
|
||||
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});
|
||||
}
|
||||
|
||||
void RemoveKeyButton(const KeyButton* key_button) {
|
||||
std::lock_guard<std::mutex> guard(mutex);
|
||||
std::lock_guard guard{mutex};
|
||||
list.remove_if(
|
||||
[key_button](const KeyButtonPair& pair) { return pair.key_button == key_button; });
|
||||
}
|
||||
|
||||
void ChangeKeyStatus(int key_code, bool pressed) {
|
||||
std::lock_guard<std::mutex> guard(mutex);
|
||||
std::lock_guard guard{mutex};
|
||||
for (const KeyButtonPair& pair : list) {
|
||||
if (pair.key_code == key_code)
|
||||
pair.key_button->status.store(pressed);
|
||||
|
@ -55,7 +55,7 @@ public:
|
|||
}
|
||||
|
||||
void ChangeAllKeyStatus(bool pressed) {
|
||||
std::lock_guard<std::mutex> guard(mutex);
|
||||
std::lock_guard guard{mutex};
|
||||
for (const KeyButtonPair& pair : list) {
|
||||
pair.key_button->status.store(pressed);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue