1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-02 23:42:13 +00:00

Kernel: Add bitwise operators for Thread::FileBlocker::BlockFlags enum

Switch to using type-safe bitwise operators for the BlockFlags class,
this cleans up a lot of boilerplate casts which are necessary when the
enum is declared as `enum class`.
This commit is contained in:
Brian Gianforcaro 2021-03-07 03:01:11 -08:00 committed by Andreas Kling
parent eaef57443c
commit 5f6ab77352
7 changed files with 57 additions and 47 deletions

View file

@ -30,6 +30,8 @@
namespace Kernel {
using BlockFlags = Thread::FileBlocker::BlockFlags;
KResultOr<ssize_t> Process::sys$readv(int fd, Userspace<const struct iovec*> iov, int iov_count)
{
REQUIRE_PROMISE(stdio);
@ -65,10 +67,10 @@ KResultOr<ssize_t> Process::sys$readv(int fd, Userspace<const struct iovec*> iov
for (auto& vec : vecs) {
if (description->is_blocking()) {
if (!description->can_read()) {
auto unblock_flags = Thread::FileBlocker::BlockFlags::None;
auto unblock_flags = BlockFlags::None;
if (Thread::current()->block<Thread::ReadBlocker>({}, *description, unblock_flags).was_interrupted())
return EINTR;
if (!((u32)unblock_flags & (u32)Thread::FileBlocker::BlockFlags::Read))
if (!has_flag(unblock_flags, BlockFlags::Read))
return EAGAIN;
// TODO: handle exceptions in unblock_flags
}
@ -102,10 +104,10 @@ KResultOr<ssize_t> Process::sys$read(int fd, Userspace<u8*> buffer, ssize_t size
return EISDIR;
if (description->is_blocking()) {
if (!description->can_read()) {
auto unblock_flags = Thread::FileBlocker::BlockFlags::None;
auto unblock_flags = BlockFlags::None;
if (Thread::current()->block<Thread::ReadBlocker>({}, *description, unblock_flags).was_interrupted())
return EINTR;
if (!((u32)unblock_flags & (u32)Thread::FileBlocker::BlockFlags::Read))
if (!has_flag(unblock_flags, BlockFlags::Read))
return EAGAIN;
// TODO: handle exceptions in unblock_flags
}