1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-23 18:55:08 +00:00

Kernel: Support F_SETLKW in fcntl

This commit is contained in:
Idan Horowitz 2022-07-14 02:17:01 +03:00 committed by Andreas Kling
parent 9db10887a1
commit 3a80b25ed6
7 changed files with 133 additions and 29 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, the SerenityOS developers.
* Copyright (c) 2022, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -820,4 +821,37 @@ bool Thread::WaitBlocker::unblock(Process& process, UnblockFlags flags, u8 signa
return true;
}
Thread::FlockBlocker::FlockBlocker(NonnullRefPtr<Inode> inode, flock const& flock)
: m_inode(move(inode))
, m_flock(flock)
{
}
void Thread::FlockBlocker::will_unblock_immediately_without_blocking(UnblockImmediatelyReason reason)
{
VERIFY(reason == UnblockImmediatelyReason::UnblockConditionAlreadyMet);
}
bool Thread::FlockBlocker::setup_blocker()
{
return add_to_blocker_set(m_inode->flock_blocker_set());
}
bool Thread::FlockBlocker::try_unblock(bool from_add_blocker)
{
if (!m_inode->can_apply_flock(m_flock))
return false;
{
SpinlockLocker lock(m_lock);
if (m_did_unblock)
return false;
m_did_unblock = true;
}
if (!from_add_blocker)
unblock_from_blocker();
return true;
}
}