2020-01-18 11:38:21 +03:00
|
|
|
/*
|
2021-04-28 23:46:44 +03:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-12-01 13:57:20 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-01-12 20:46:41 +03:00
|
|
|
#include <AK/Atomic.h>
|
2021-08-22 02:37:17 +03:00
|
|
|
#include <Kernel/Locking/Spinlock.h>
|
2023-02-24 20:45:37 +03:00
|
|
|
#include <Kernel/Tasks/Thread.h>
|
2019-12-01 13:57:20 +03:00
|
|
|
|
2020-02-16 03:27:42 +03:00
|
|
|
namespace Kernel {
|
|
|
|
|
2021-08-22 16:59:47 +03:00
|
|
|
class WaitQueue final : public Thread::BlockerSet {
|
2019-12-01 13:57:20 +03:00
|
|
|
public:
|
2021-01-24 08:30:10 +03:00
|
|
|
u32 wake_one();
|
2020-12-22 09:21:58 +03:00
|
|
|
u32 wake_n(u32 wake_count);
|
|
|
|
u32 wake_all();
|
2020-12-08 07:29:41 +03:00
|
|
|
|
|
|
|
template<class... Args>
|
2022-04-01 20:58:27 +03:00
|
|
|
Thread::BlockResult wait_on(Thread::BlockTimeout const& timeout, Args&&... args)
|
2020-12-08 07:29:41 +03:00
|
|
|
{
|
2021-08-23 01:10:33 +03:00
|
|
|
return Thread::current()->block<Thread::WaitQueueBlocker>(timeout, *this, forward<Args>(args)...);
|
2020-12-08 07:29:41 +03:00
|
|
|
}
|
|
|
|
|
2021-02-15 02:02:14 +03:00
|
|
|
template<class... Args>
|
|
|
|
void wait_forever(Args&&... args)
|
|
|
|
{
|
2021-08-23 01:10:33 +03:00
|
|
|
(void)Thread::current()->block<Thread::WaitQueueBlocker>({}, *this, forward<Args>(args)...);
|
2021-02-15 02:02:14 +03:00
|
|
|
}
|
|
|
|
|
2020-12-08 07:29:41 +03:00
|
|
|
protected:
|
2021-08-24 02:07:16 +03:00
|
|
|
virtual bool should_add_blocker(Thread::Blocker& b, void*) override;
|
2019-12-01 13:57:20 +03:00
|
|
|
|
|
|
|
private:
|
2020-07-06 00:46:51 +03:00
|
|
|
bool m_wake_requested { false };
|
2019-12-01 13:57:20 +03:00
|
|
|
};
|
2020-02-16 03:27:42 +03:00
|
|
|
|
|
|
|
}
|