Serenity Operating System
at master 40 lines 907 B view raw
1/* 2 * Copyright (c) 2020, the SerenityOS developers. 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include <AK/Atomic.h> 10#include <Kernel/Locking/Spinlock.h> 11#include <Kernel/Thread.h> 12 13namespace Kernel { 14 15class WaitQueue final : public Thread::BlockerSet { 16public: 17 u32 wake_one(); 18 u32 wake_n(u32 wake_count); 19 u32 wake_all(); 20 21 template<class... Args> 22 Thread::BlockResult wait_on(Thread::BlockTimeout const& timeout, Args&&... args) 23 { 24 return Thread::current()->block<Thread::WaitQueueBlocker>(timeout, *this, forward<Args>(args)...); 25 } 26 27 template<class... Args> 28 void wait_forever(Args&&... args) 29 { 30 (void)Thread::current()->block<Thread::WaitQueueBlocker>({}, *this, forward<Args>(args)...); 31 } 32 33protected: 34 virtual bool should_add_blocker(Thread::Blocker& b, void*) override; 35 36private: 37 bool m_wake_requested { false }; 38}; 39 40}