From 971531183746d4481f6f475ef80bea90c6f03df5 Mon Sep 17 00:00:00 2001 From: Timothy Date: Wed, 14 Jul 2021 21:59:22 +1000 Subject: [PATCH] AK+Kernel: Implement and use EnumBits has_any_flag() This duplicates the old functionality of has_flag and will return true when any flags present in the mask are also in the value. --- AK/EnumBits.h | 6 ++++++ Kernel/FileSystem/FileDescription.cpp | 2 +- Kernel/Syscalls/select.cpp | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/AK/EnumBits.h b/AK/EnumBits.h index a1216b8c26d..9ee954056aa 100644 --- a/AK/EnumBits.h +++ b/AK/EnumBits.h @@ -78,4 +78,10 @@ { \ using Type = UnderlyingType; \ return static_cast(value & mask) == static_cast(mask); \ + } \ + \ + Prefix constexpr bool has_any_flag(Enum value, Enum mask) \ + { \ + using Type = UnderlyingType; \ + return static_cast(value & mask) != 0; \ } diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/FileDescription.cpp index be2c806a32e..1625639a501 100644 --- a/Kernel/FileSystem/FileDescription.cpp +++ b/Kernel/FileSystem/FileDescription.cpp @@ -96,7 +96,7 @@ Thread::FileBlocker::BlockFlags FileDescription::should_unblock(Thread::FileBloc unblock_flags |= BlockFlags::Write; // TODO: Implement Thread::FileBlocker::BlockFlags::Exception - if (has_flag(block_flags, BlockFlags::SocketFlags)) { + if (has_any_flag(block_flags, BlockFlags::SocketFlags)) { auto* sock = socket(); VERIFY(sock); if (has_flag(block_flags, BlockFlags::Accept) && sock->can_accept()) diff --git a/Kernel/Syscalls/select.cpp b/Kernel/Syscalls/select.cpp index ebbb18dcffc..76d3fa3fc24 100644 --- a/Kernel/Syscalls/select.cpp +++ b/Kernel/Syscalls/select.cpp @@ -112,7 +112,7 @@ KResultOr Process::sys$select(Userspace Process::sys$poll(Userspace u if (fds_entry.unblocked_flags == BlockFlags::None) continue; - if (has_flag(fds_entry.unblocked_flags, BlockFlags::Exception)) { + if (has_any_flag(fds_entry.unblocked_flags, BlockFlags::Exception)) { if (has_flag(fds_entry.unblocked_flags, BlockFlags::ReadHangUp)) pfd.revents |= POLLRDHUP; if (has_flag(fds_entry.unblocked_flags, BlockFlags::WriteError))