mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-08 23:42:53 +03:00
Kernel: Only lock process file descriptor table once in sys$poll()
Grab the OpenFileDescriptions mutex once and hold on to it while populating the SelectBlocker::FDVector.
This commit is contained in:
parent
b56646e293
commit
d748a3c173
Notes:
sideshowbarker
2024-07-17 20:03:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d748a3c1735
@ -47,20 +47,23 @@ ErrorOr<FlatPtr> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> use
|
||||
Thread::SelectBlocker::FDVector fds_info;
|
||||
TRY(fds_info.try_ensure_capacity(params.nfds));
|
||||
|
||||
for (size_t i = 0; i < params.nfds; i++) {
|
||||
auto& pfd = fds_copy[i];
|
||||
auto description = TRY(m_fds.with_shared([&](auto& fds) { return fds.open_file_description(pfd.fd); }));
|
||||
BlockFlags block_flags = BlockFlags::Exception; // always want POLLERR, POLLHUP, POLLNVAL
|
||||
if (pfd.events & POLLIN)
|
||||
block_flags |= BlockFlags::Read;
|
||||
if (pfd.events & POLLOUT)
|
||||
block_flags |= BlockFlags::Write;
|
||||
if (pfd.events & POLLPRI)
|
||||
block_flags |= BlockFlags::ReadPriority;
|
||||
if (pfd.events & POLLWRBAND)
|
||||
block_flags |= BlockFlags::WritePriority;
|
||||
fds_info.unchecked_append({ move(description), block_flags });
|
||||
}
|
||||
TRY(m_fds.with_shared([&](auto& fds) -> ErrorOr<void> {
|
||||
for (size_t i = 0; i < params.nfds; i++) {
|
||||
auto& pfd = fds_copy[i];
|
||||
auto description = TRY(fds.open_file_description(pfd.fd));
|
||||
BlockFlags block_flags = BlockFlags::Exception; // always want POLLERR, POLLHUP, POLLNVAL
|
||||
if (pfd.events & POLLIN)
|
||||
block_flags |= BlockFlags::Read;
|
||||
if (pfd.events & POLLOUT)
|
||||
block_flags |= BlockFlags::Write;
|
||||
if (pfd.events & POLLPRI)
|
||||
block_flags |= BlockFlags::ReadPriority;
|
||||
if (pfd.events & POLLWRBAND)
|
||||
block_flags |= BlockFlags::WritePriority;
|
||||
fds_info.unchecked_append({ move(description), block_flags });
|
||||
}
|
||||
return {};
|
||||
}));
|
||||
|
||||
auto* current_thread = Thread::current();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user