瀏覽代碼

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.
Timothy 4 年之前
父節點
當前提交
9715311837
共有 3 個文件被更改,包括 9 次插入3 次删除
  1. 6 0
      AK/EnumBits.h
  2. 1 1
      Kernel/FileSystem/FileDescription.cpp
  3. 2 2
      Kernel/Syscalls/select.cpp

+ 6 - 0
AK/EnumBits.h

@@ -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;                       \
     }

+ 1 - 1
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())

+ 2 - 2
Kernel/Syscalls/select.cpp

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