Merge pull request #6156 from lioncash/lock-discard

kernel: Mark lock helper classes as [[nodiscard]]
This commit is contained in:
bunnei 2021-04-09 21:42:26 -07:00 committed by GitHub
commit c6d2af16b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View File

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

View File

@ -20,19 +20,22 @@ concept KLockable = !std::is_reference_v<T> && requires(T & t) {
};
template <typename T>
requires KLockable<T> class KScopedLock {
requires KLockable<T> class [[nodiscard]] KScopedLock {
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;

View File

@ -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) {