mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:38:10 +00:00
Kernel: Support F_SETLKW in fcntl
This commit is contained in:
parent
9db10887a1
commit
3a80b25ed6
7 changed files with 133 additions and 29 deletions
|
@ -283,7 +283,8 @@ public:
|
|||
Routing,
|
||||
Sleep,
|
||||
Signal,
|
||||
Wait
|
||||
Wait,
|
||||
Flock
|
||||
};
|
||||
virtual ~Blocker();
|
||||
virtual StringView state_string() const = 0;
|
||||
|
@ -788,6 +789,41 @@ public:
|
|||
bool m_finalized { false };
|
||||
};
|
||||
|
||||
class FlockBlocker final : public Blocker {
|
||||
public:
|
||||
FlockBlocker(NonnullRefPtr<Inode>, flock const&);
|
||||
virtual StringView state_string() const override { return "Locking File"sv; }
|
||||
virtual Type blocker_type() const override { return Type::Flock; }
|
||||
virtual void will_unblock_immediately_without_blocking(UnblockImmediatelyReason) override;
|
||||
virtual bool setup_blocker() override;
|
||||
bool try_unblock(bool from_add_blocker);
|
||||
|
||||
private:
|
||||
NonnullRefPtr<Inode> m_inode;
|
||||
flock const& m_flock;
|
||||
bool m_did_unblock { false };
|
||||
};
|
||||
|
||||
class FlockBlockerSet final : public BlockerSet {
|
||||
public:
|
||||
void unblock_all_blockers_whose_conditions_are_met()
|
||||
{
|
||||
BlockerSet::unblock_all_blockers_whose_conditions_are_met([&](auto& b, void*, bool&) {
|
||||
VERIFY(b.blocker_type() == Blocker::Type::Flock);
|
||||
auto& blocker = static_cast<Thread::FlockBlocker&>(b);
|
||||
return blocker.try_unblock(false);
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
bool should_add_blocker(Blocker& b, void*) override
|
||||
{
|
||||
VERIFY(b.blocker_type() == Blocker::Type::Flock);
|
||||
auto& blocker = static_cast<Thread::FlockBlocker&>(b);
|
||||
return !blocker.try_unblock(true);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename AddBlockerHandler>
|
||||
ErrorOr<void> try_join(AddBlockerHandler add_blocker)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue