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.
This commit is contained in:
Timothy 2021-07-14 21:59:22 +10:00 committed by Andreas Kling
parent 371911b1b5
commit 9715311837
3 changed files with 9 additions and 3 deletions

View file

@ -78,4 +78,10 @@
{ \
using Type = UnderlyingType<Enum>; \
return static_cast<Type>(value & mask) == static_cast<Type>(mask); \
} \
\
Prefix constexpr bool has_any_flag(Enum value, Enum mask) \
{ \
using Type = UnderlyingType<Enum>; \
return static_cast<Type>(value & mask) != 0; \
}

View file

@ -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())

View file

@ -112,7 +112,7 @@ KResultOr<FlatPtr> Process::sys$select(Userspace<const Syscall::SC_select_params
FD_SET(selected_fds[i], &fds_write);
marked_fd_count++;
}
if (params.exceptfds && has_flag(fd_entry.unblocked_flags, BlockFlags::Exception)) {
if (params.exceptfds && has_any_flag(fd_entry.unblocked_flags, BlockFlags::Exception)) {
FD_SET(selected_fds[i], &fds_except);
marked_fd_count++;
}
@ -207,7 +207,7 @@ KResultOr<FlatPtr> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> 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))