1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:47:34 +00:00

Kernel: Move block condition evaluation out of the Scheduler

This makes the Scheduler a lot leaner by not having to evaluate
block conditions every time it is invoked. Instead evaluate them as
the states change, and unblock threads at that point.

This also implements some more waitid/waitpid/wait features and
behavior. For example, WUNTRACED and WNOWAIT are now supported. And
wait will now not return EINTR when SIGCHLD is delivered at the
same time.
This commit is contained in:
Tom 2020-11-29 16:05:27 -07:00 committed by Andreas Kling
parent 6a620562cc
commit 046d6855f5
53 changed files with 2027 additions and 930 deletions

View file

@ -39,6 +39,36 @@
namespace Kernel {
class File;
class FileBlockCondition : public Thread::BlockCondition {
public:
FileBlockCondition(File& file)
: m_file(file)
{
}
virtual bool should_add_blocker(Thread::Blocker& b, void* data) override
{
ASSERT(b.blocker_type() == Thread::Blocker::Type::File);
auto& blocker = static_cast<Thread::FileBlocker&>(b);
return !blocker.unblock(true, data);
}
void unblock()
{
ScopedSpinLock lock(m_lock);
do_unblock([&](auto& b, void* data) {
ASSERT(b.blocker_type() == Thread::Blocker::Type::File);
auto& blocker = static_cast<Thread::FileBlocker&>(b);
return blocker.unblock(false, data);
});
}
private:
File& m_file;
};
// File is the base class for anything that can be referenced by a FileDescription.
//
// The most important functions in File are:
@ -103,8 +133,27 @@ public:
virtual bool is_character_device() const { return false; }
virtual bool is_socket() const { return false; }
virtual FileBlockCondition& block_condition() { return m_block_condition; }
protected:
File();
void evaluate_block_conditions()
{
if (Processor::current().in_irq()) {
// If called from an IRQ handler we need to delay evaluation
// and unblocking of waiting threads
Processor::deferred_call_queue([this]() {
ASSERT(!Processor::current().in_irq());
evaluate_block_conditions();
});
} else {
block_condition().unblock();
}
}
private:
FileBlockCondition m_block_condition;
};
}