|
From: | Bruno Haible |
Subject: | posix_spawn-internal: improvements on native Windows |
Date: | Sat, 10 Sep 2022 02:56:24 +0200 |
Here are some improvements for the posix_spawn* implementation on native Windows. The first patch is a small fix (only visible if, among the file action, there is an _addopen of a file in O_APPEND mode, followed by a _adddup2 of that file descriptor). The next 4 patches optimize away most DuplicateHandle calls. In particular, the last among these patches applies some optimization rules: (1) dup2 (oldfd, newfd) ... close (newfd) -> nop ... nop (2) dup2 (oldfd, newfd) ... open (newfd, ...) -> nop ... open (newfd, ...) (3) dup2 (oldfd, newfd) ... dup2 (otherfd, newfd) -> nop ... dup2 (otherfd, newfd) (4) dup2 (oldfd, newfd) ... close (oldfd) -> dup2_close (oldfd, newfd) ... nop (5) dup2 (oldfd, newfd) ... open (oldfd, ...) -> dup2_close (oldfd, newfd) ... open (oldfd, ...) (6) dup2 (oldfd, newfd) ... dup2 (otherfd, oldfd) -> dup2_close (oldfd, newfd) ... dup2 (otherfd, oldfd) where dup2_close shuffles around file descriptors without doing any Windows API call. The rules (1), (2), (3), (5), (6) are rarely relevant in practice; however, rule (4) is widely applicable. 2022-09-09 Bruno Haible <bruno@clisp.org> posix_spawn-internal: Optimize DuplicateHandle calls on native Windows. * lib/windows-spawn.h (DELAYED_DUP2_OLDFD, DELAYED_DUP2_NEWFD): New macros. (struct IHANDLE): Add a linked_fd field. * lib/spawni.c (SPAWN_INTERNAL_OPTIMIZE_DUPLICATEHANDLE): New macro. (do_delayed_dup2, do_remaining_delayed_dup2): New functions. (close_inheritable_handles): Don't close handles in DELAYED_DUP2_NEWFD entries. (do_close): Add a third parameter. Optimize delayed dup2 calls. (do_open): Use do_close. (do_dup2): Likewise. Prepare for optimizing the DuplicateHandle call. (__spawni): Do the remaining delayed dup2 invocations after the loop over the actions. posix_spawn-internal: Refactor. * lib/windows-spawn.h (struct IHANDLE): New type. (struct inheritable_handles): Combine handles and flags into a single array. * lib/windows-spawn.c (init_inheritable_handles, compose_handles_block, spawnpvech): Update. * lib/spawni.c (grow_inheritable_handles, shrink_inheritable_handles, do_open, do_dup2, do_close): Update. posix_spawn-internal: Optimize DuplicateHandle calls on native Windows. * lib/spawni.c (open_handle): Return an inheritable HANDLE. (do_open): Don't call DuplicateHandle. Remove curr_process parameter. (__spawni): Update. posix_spawn-internal: Optimize DuplicateHandle calls on native Windows. * lib/windows-spawn.h (KEEP_OPEN_IN_PARENT): New macro. * lib/windows-spawn.c (init_inheritable_handles): When a handle is already inheritable, don't bother duplicating it; instead, just mark it as KEEP_OPEN_IN_PARENT. * lib/spawni.c (shrink_inheritable_handles, close_inheritable_handles, do_open, do_dup2, do_close): Don't close handles that are marked as KEEP_OPEN_IN_PARENT. 2022-09-09 Bruno Haible <bruno@clisp.org> posix_spawn-internal: Don't lose flags while duplicating an fd. * lib/spawni.c (do_dup2): Fix the flags of the new fd.
0001-posix_spawn-internal-Don-t-lose-flags-while-duplicat.patch
Description: Text Data
0002-posix_spawn-internal-Optimize-DuplicateHandle-calls-.patch
Description: Text Data
0003-posix_spawn-internal-Optimize-DuplicateHandle-calls-.patch
Description: Text Data
0004-posix_spawn-internal-Refactor.patch
Description: Text Data
0005-posix_spawn-internal-Optimize-DuplicateHandle-calls-.patch
Description: Text Data
[Prev in Thread] | Current Thread | [Next in Thread] |