From 97e2604575459da8787a20d511d3438ac95d9f1a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 7 Apr 2021 01:19:26 -0400 Subject: k_scheduler: Mark KScopedSchedulerLock as [[nodiscard]] Prevents logic bugs like: KScopedSchedulerLock{kernel}; instead of: KScopedSchedulerLock lk{kernel}; from slipping through. --- src/core/hle/kernel/k_scheduler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/hle') diff --git a/src/core/hle/kernel/k_scheduler.h b/src/core/hle/kernel/k_scheduler.h index f595b9a5c..01c8c4b73 100644 --- a/src/core/hle/kernel/k_scheduler.h +++ b/src/core/hle/kernel/k_scheduler.h @@ -198,7 +198,7 @@ private: Common::SpinLock guard{}; }; -class KScopedSchedulerLock : KScopedLock { +class [[nodiscard]] KScopedSchedulerLock : KScopedLock { public: explicit KScopedSchedulerLock(KernelCore& kernel); ~KScopedSchedulerLock(); -- cgit v1.2.3 From bc30aa82499baea00a4d985f922e489041660ee7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 7 Apr 2021 01:23:06 -0400 Subject: k_scoped_lock: Mark class as [[nodiscard]] Prevents logic bugs of the kind described in the previous commit from slipping through. --- src/core/hle/kernel/k_scoped_lock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/hle') diff --git a/src/core/hle/kernel/k_scoped_lock.h b/src/core/hle/kernel/k_scoped_lock.h index d7cc557b2..543555680 100644 --- a/src/core/hle/kernel/k_scoped_lock.h +++ b/src/core/hle/kernel/k_scoped_lock.h @@ -20,7 +20,7 @@ concept KLockable = !std::is_reference_v && requires(T & t) { }; template -requires KLockable class KScopedLock { +requires KLockable class [[nodiscard]] KScopedLock { public: explicit KScopedLock(T* l) : lock_ptr(l) { this->lock_ptr->Lock(); -- cgit v1.2.3 From c0187690167704fd72dadad9dff5a8fb7e4f96bb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 7 Apr 2021 01:25:55 -0400 Subject: k_scoped_lock: delete copy and move assignment operators If we delete the copy and move constructor, we should also be deleting the copy and move assignment operators (and even if this were intended, it would be pretty odd to not document why it's done this way). --- src/core/hle/kernel/k_scoped_lock.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/core/hle') diff --git a/src/core/hle/kernel/k_scoped_lock.h b/src/core/hle/kernel/k_scoped_lock.h index 543555680..7a1035b8c 100644 --- a/src/core/hle/kernel/k_scoped_lock.h +++ b/src/core/hle/kernel/k_scoped_lock.h @@ -25,14 +25,17 @@ public: explicit KScopedLock(T* l) : lock_ptr(l) { this->lock_ptr->Lock(); } - explicit KScopedLock(T& l) : KScopedLock(std::addressof(l)) { /* ... */ - } + explicit KScopedLock(T& l) : KScopedLock(std::addressof(l)) {} + ~KScopedLock() { this->lock_ptr->Unlock(); } KScopedLock(const KScopedLock&) = delete; + KScopedLock& operator=(const KScopedLock&) = delete; + KScopedLock(KScopedLock&&) = delete; + KScopedLock& operator=(KScopedLock&&) = delete; private: T* lock_ptr; -- cgit v1.2.3 From 1e964604bbad3657581ae5c50d71ed0decd29590 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 7 Apr 2021 01:44:30 -0400 Subject: k_scoped_scheduler_lock_and_sleep: Mark class as [[nodiscard]] Prevents logic bugs from slipping through. --- src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/hle') diff --git a/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h index f8189e107..4a35842c5 100644 --- a/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h +++ b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h @@ -15,7 +15,7 @@ namespace Kernel { -class KScopedSchedulerLockAndSleep { +class [[nodiscard]] KScopedSchedulerLockAndSleep { public: explicit KScopedSchedulerLockAndSleep(KernelCore& kernel, KThread* t, s64 timeout) : kernel(kernel), thread(t), timeout_tick(timeout) { -- cgit v1.2.3 From 530a5a1d099805c5fc2cfa1a31229c3f8e7dd019 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 7 Apr 2021 01:37:59 -0400 Subject: Amend bizarre clang-format suggestions --- src/core/hle/kernel/k_scheduler.h | 2 +- src/core/hle/kernel/k_scoped_lock.h | 6 +++--- src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/core/hle') diff --git a/src/core/hle/kernel/k_scheduler.h b/src/core/hle/kernel/k_scheduler.h index 01c8c4b73..70d6bfcee 100644 --- a/src/core/hle/kernel/k_scheduler.h +++ b/src/core/hle/kernel/k_scheduler.h @@ -200,7 +200,7 @@ private: class [[nodiscard]] KScopedSchedulerLock : KScopedLock { public: - explicit KScopedSchedulerLock(KernelCore& kernel); + explicit KScopedSchedulerLock(KernelCore & kernel); ~KScopedSchedulerLock(); }; diff --git a/src/core/hle/kernel/k_scoped_lock.h b/src/core/hle/kernel/k_scoped_lock.h index 7a1035b8c..72c3b0252 100644 --- a/src/core/hle/kernel/k_scoped_lock.h +++ b/src/core/hle/kernel/k_scoped_lock.h @@ -22,10 +22,10 @@ concept KLockable = !std::is_reference_v && requires(T & t) { template requires KLockable class [[nodiscard]] KScopedLock { public: - explicit KScopedLock(T* l) : lock_ptr(l) { + explicit KScopedLock(T * l) : lock_ptr(l) { this->lock_ptr->Lock(); } - explicit KScopedLock(T& l) : KScopedLock(std::addressof(l)) {} + explicit KScopedLock(T & l) : KScopedLock(std::addressof(l)) {} ~KScopedLock() { this->lock_ptr->Unlock(); @@ -34,7 +34,7 @@ public: KScopedLock(const KScopedLock&) = delete; KScopedLock& operator=(const KScopedLock&) = delete; - KScopedLock(KScopedLock&&) = delete; + KScopedLock(KScopedLock &&) = delete; KScopedLock& operator=(KScopedLock&&) = delete; private: diff --git a/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h index 4a35842c5..ebecf0c77 100644 --- a/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h +++ b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h @@ -17,7 +17,7 @@ namespace Kernel { class [[nodiscard]] KScopedSchedulerLockAndSleep { public: - explicit KScopedSchedulerLockAndSleep(KernelCore& kernel, KThread* t, s64 timeout) + explicit KScopedSchedulerLockAndSleep(KernelCore & kernel, KThread * t, s64 timeout) : kernel(kernel), thread(t), timeout_tick(timeout) { // Lock the scheduler. kernel.GlobalSchedulerContext().scheduler_lock.Lock(); -- cgit v1.2.3