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
Notes: sideshowbarker 2024-07-18 08:56:48 +09:00
3 changed files with 9 additions and 3 deletions

View File

@ -78,4 +78,10 @@
{ \ { \
using Type = UnderlyingType<Enum>; \ using Type = UnderlyingType<Enum>; \
return static_cast<Type>(value & mask) == static_cast<Type>(mask); \ 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; unblock_flags |= BlockFlags::Write;
// TODO: Implement Thread::FileBlocker::BlockFlags::Exception // TODO: Implement Thread::FileBlocker::BlockFlags::Exception
if (has_flag(block_flags, BlockFlags::SocketFlags)) { if (has_any_flag(block_flags, BlockFlags::SocketFlags)) {
auto* sock = socket(); auto* sock = socket();
VERIFY(sock); VERIFY(sock);
if (has_flag(block_flags, BlockFlags::Accept) && sock->can_accept()) 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); FD_SET(selected_fds[i], &fds_write);
marked_fd_count++; 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); FD_SET(selected_fds[i], &fds_except);
marked_fd_count++; 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) if (fds_entry.unblocked_flags == BlockFlags::None)
continue; 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)) if (has_flag(fds_entry.unblocked_flags, BlockFlags::ReadHangUp))
pfd.revents |= POLLRDHUP; pfd.revents |= POLLRDHUP;
if (has_flag(fds_entry.unblocked_flags, BlockFlags::WriteError)) if (has_flag(fds_entry.unblocked_flags, BlockFlags::WriteError))