diff options
author | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-03-07 03:01:11 -0800 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-08 18:47:40 +0100 |
commit | 5f6ab773520c71bd32cad4ca77d86a6bb280c8c7 (patch) | |
tree | e33d778b9b5bebc4d56589e76c21592901fd583a /Kernel/FileSystem | |
parent | eaef57443cfcc23c8f5b1090f25fb15f413a5c5a (diff) | |
download | serenity-5f6ab773520c71bd32cad4ca77d86a6bb280c8c7.zip |
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`.
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r-- | Kernel/FileSystem/FileDescription.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/FileDescription.cpp index b7df9bc659..f66811d450 100644 --- a/Kernel/FileSystem/FileDescription.cpp +++ b/Kernel/FileSystem/FileDescription.cpp @@ -98,22 +98,23 @@ KResult FileDescription::attach() Thread::FileBlocker::BlockFlags FileDescription::should_unblock(Thread::FileBlocker::BlockFlags block_flags) const { - u32 unblock_flags = (u32)Thread::FileBlocker::BlockFlags::None; - if (((u32)block_flags & (u32)Thread::FileBlocker::BlockFlags::Read) && can_read()) - unblock_flags |= (u32)Thread::FileBlocker::BlockFlags::Read; - if (((u32)block_flags & (u32)Thread::FileBlocker::BlockFlags::Write) && can_write()) - unblock_flags |= (u32)Thread::FileBlocker::BlockFlags::Write; + using BlockFlags = Thread::FileBlocker::BlockFlags; + BlockFlags unblock_flags = BlockFlags::None; + if (has_flag(block_flags, BlockFlags::Read) && can_read()) + unblock_flags |= BlockFlags::Read; + if (has_flag(block_flags, BlockFlags::Write) && can_write()) + unblock_flags |= BlockFlags::Write; // TODO: Implement Thread::FileBlocker::BlockFlags::Exception - if ((u32)block_flags & (u32)Thread::FileBlocker::BlockFlags::SocketFlags) { + if (has_flag(block_flags, BlockFlags::SocketFlags)) { auto* sock = socket(); VERIFY(sock); - if (((u32)block_flags & (u32)Thread::FileBlocker::BlockFlags::Accept) && sock->can_accept()) - unblock_flags |= (u32)Thread::FileBlocker::BlockFlags::Accept; - if (((u32)block_flags & (u32)Thread::FileBlocker::BlockFlags::Connect) && sock->setup_state() == Socket::SetupState::Completed) - unblock_flags |= (u32)Thread::FileBlocker::BlockFlags::Connect; + if (has_flag(block_flags, BlockFlags::Accept) && sock->can_accept()) + unblock_flags |= BlockFlags::Accept; + if (has_flag(block_flags, BlockFlags::Connect) && sock->setup_state() == Socket::SetupState::Completed) + unblock_flags |= BlockFlags::Connect; } - return (Thread::FileBlocker::BlockFlags)unblock_flags; + return unblock_flags; } KResult FileDescription::stat(::stat& buffer) |