mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:58:11 +00:00
Kernel: Only lock file descriptor table once in sys$pipe()
Instead of locking it twice, we now frontload all the work that doesn't touch the fd table, and then only lock it towards the end of the syscall. The benefit here is simplicity. The downside is that we do a bit of unnecessary work in the EMFILE error case, but we don't need to optimize that case anyway.
This commit is contained in:
parent
b6d0636656
commit
164c9617c3
1 changed files with 3 additions and 9 deletions
|
@ -21,15 +21,6 @@ ErrorOr<FlatPtr> Process::sys$pipe(Userspace<int*> pipefd, int flags)
|
|||
u32 fd_flags = (flags & O_CLOEXEC) ? FD_CLOEXEC : 0;
|
||||
auto fifo = TRY(FIFO::try_create(uid()));
|
||||
|
||||
ScopedDescriptionAllocation reader_fd_allocation;
|
||||
ScopedDescriptionAllocation writer_fd_allocation;
|
||||
|
||||
TRY(m_fds.with_exclusive([&](auto& fds) -> ErrorOr<void> {
|
||||
reader_fd_allocation = TRY(fds.allocate());
|
||||
writer_fd_allocation = TRY(fds.allocate());
|
||||
return {};
|
||||
}));
|
||||
|
||||
auto reader_description = TRY(fifo->open_direction(FIFO::Direction::Reader));
|
||||
auto writer_description = TRY(fifo->open_direction(FIFO::Direction::Writer));
|
||||
|
||||
|
@ -41,6 +32,9 @@ ErrorOr<FlatPtr> Process::sys$pipe(Userspace<int*> pipefd, int flags)
|
|||
}
|
||||
|
||||
TRY(m_fds.with_exclusive([&](auto& fds) -> ErrorOr<void> {
|
||||
auto reader_fd_allocation = TRY(fds.allocate());
|
||||
auto writer_fd_allocation = TRY(fds.allocate());
|
||||
|
||||
fds[reader_fd_allocation.fd].set(move(reader_description), fd_flags);
|
||||
fds[writer_fd_allocation.fd].set(move(writer_description), fd_flags);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue