Procházet zdrojové kódy

Merge pull request #6156 from lioncash/lock-discard

kernel: Mark lock helper classes as [[nodiscard]]
bunnei před 5 roky
rodič
revize
c6d2af16b5

+ 2 - 2
src/core/hle/kernel/k_scheduler.h

@@ -198,9 +198,9 @@ private:
     Common::SpinLock guard{};
     Common::SpinLock guard{};
 };
 };
 
 
-class KScopedSchedulerLock : KScopedLock<GlobalSchedulerContext::LockType> {
+class [[nodiscard]] KScopedSchedulerLock : KScopedLock<GlobalSchedulerContext::LockType> {
 public:
 public:
-    explicit KScopedSchedulerLock(KernelCore& kernel);
+    explicit KScopedSchedulerLock(KernelCore & kernel);
     ~KScopedSchedulerLock();
     ~KScopedSchedulerLock();
 };
 };
 
 

+ 8 - 5
src/core/hle/kernel/k_scoped_lock.h

@@ -20,19 +20,22 @@ concept KLockable = !std::is_reference_v<T> && requires(T & t) {
 };
 };
 
 
 template <typename T>
 template <typename T>
-requires KLockable<T> class KScopedLock {
+requires KLockable<T> class [[nodiscard]] KScopedLock {
 public:
 public:
-    explicit KScopedLock(T* l) : lock_ptr(l) {
+    explicit KScopedLock(T * l) : lock_ptr(l) {
         this->lock_ptr->Lock();
         this->lock_ptr->Lock();
     }
     }
-    explicit KScopedLock(T& l) : KScopedLock(std::addressof(l)) { /* ... */
-    }
+    explicit KScopedLock(T & l) : KScopedLock(std::addressof(l)) {}
+
     ~KScopedLock() {
     ~KScopedLock() {
         this->lock_ptr->Unlock();
         this->lock_ptr->Unlock();
     }
     }
 
 
     KScopedLock(const KScopedLock&) = delete;
     KScopedLock(const KScopedLock&) = delete;
-    KScopedLock(KScopedLock&&) = delete;
+    KScopedLock& operator=(const KScopedLock&) = delete;
+
+    KScopedLock(KScopedLock &&) = delete;
+    KScopedLock& operator=(KScopedLock&&) = delete;
 
 
 private:
 private:
     T* lock_ptr;
     T* lock_ptr;

+ 2 - 2
src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h

@@ -15,9 +15,9 @@
 
 
 namespace Kernel {
 namespace Kernel {
 
 
-class KScopedSchedulerLockAndSleep {
+class [[nodiscard]] KScopedSchedulerLockAndSleep {
 public:
 public:
-    explicit KScopedSchedulerLockAndSleep(KernelCore& kernel, KThread* t, s64 timeout)
+    explicit KScopedSchedulerLockAndSleep(KernelCore & kernel, KThread * t, s64 timeout)
         : kernel(kernel), thread(t), timeout_tick(timeout) {
         : kernel(kernel), thread(t), timeout_tick(timeout) {
         // Lock the scheduler.
         // Lock the scheduler.
         kernel.GlobalSchedulerContext().scheduler_lock.Lock();
         kernel.GlobalSchedulerContext().scheduler_lock.Lock();