From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Rose via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Seija Kijin <doremylover123@gmail.com>
Subject: Re: [PATCH] win32: close handles of threads that have been joined
Date: Mon, 19 Dec 2022 19:40:37 +0100 [thread overview]
Message-ID: <221219.86ili7xmd5.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <pull.1406.git.git.1671474876207.gitgitgadget@gmail.com>
On Mon, Dec 19 2022, Rose via GitGitGadget wrote:
> From: Seija Kijin <doremylover123@gmail.com>
>
> After joining threads, the handle to the original thread
> should be closed as it no longer needs to be open.
>
> Signed-off-by: Seija Kijin <doremylover123@gmail.com>
> ---
> win32: close handles of threads that have been joined
>
> After joining threads, the handle to the original thread should be
> closed as it no longer needs to be open.
>
> Signed-off-by: Seija Kijin doremylover123@gmail.com
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1406%2FAtariDreams%2Fjoin-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1406/AtariDreams/join-v1
> Pull-Request: https://github.com/git/git/pull/1406
>
> compat/win32/pthread.c | 22 ++++++++++++++--------
> 1 file changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/compat/win32/pthread.c b/compat/win32/pthread.c
> index 2e7eead42cb..de89667ef70 100644
> --- a/compat/win32/pthread.c
> +++ b/compat/win32/pthread.c
> @@ -39,14 +39,20 @@ int win32_pthread_join(pthread_t *thread, void **value_ptr)
> {
> DWORD result = WaitForSingleObject(thread->handle, INFINITE);
> switch (result) {
> - case WAIT_OBJECT_0:
> - if (value_ptr)
> - *value_ptr = thread->arg;
> - return 0;
> - case WAIT_ABANDONED:
> - return EINVAL;
> - default:
> - return err_win_to_posix(GetLastError());
> + case WAIT_OBJECT_0:
> + if (value_ptr)
> + *value_ptr = thread->arg;
> + /* detach the thread once the join succeeds */
> + CloseHandle(thread->handle);
> + return 0;
> + case WAIT_ABANDONED:
> + /* either thread is not joinable or another thread is waiting on
> + * this, so we do not detatch */
See CodingGuidelines for how multi-line comments should look like.
/*
* Like this
* Another line etc.
*/
> + return EINVAL;
> + default:
> + case WAIT_FAILED:
> + /* the function failed so we do not detach */
> + return err_win_to_posix(GetLastError());
The post-image adhares to our CodingGuidelines better than the
pre-image, but please split up such re-indentation into a "prep" change.
Manually looking at this with "git show -w" shows the actual (and
smaller) functional change.
You add a "case" for WAIT_FAILED", but keep "default".
I have no idea about this API, but a search turned up:
https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitforsingleobject
That seems to suggest that it only returns 4 possible values.
Rather than having the "default" case shouldn't we (and this is just a
suggestion, and should be its own prep change in any case) do:
switch (result) {
case WAIT_OBJECT_0:
return ...;
case WAIT_ABANDONED:
return ...;
case WAIT_TIMEOUT:
case WAIT_FAILED:
return ...;
default:
BUG("unhandled result %d", result);
}
I.e. instead of keeping "default" you can just list "WAIT_TIMEOUT".
I don't know if that's OK with this API, it does say "If the function
succeeds, the return value indicates, so maybe that "default" handles a
lot more still?
next prev parent reply other threads:[~2022-12-19 18:46 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-19 18:34 [PATCH] win32: close handles of threads that have been joined Rose via GitGitGadget
2022-12-19 18:40 ` Ævar Arnfjörð Bjarmason [this message]
2022-12-20 7:53 ` Johannes Sixt
2022-12-20 18:57 ` [PATCH v2] " Rose via GitGitGadget
2022-12-20 19:00 ` [PATCH v3] " Rose via GitGitGadget
2022-12-20 20:03 ` [PATCH v4 0/2] " Rose via GitGitGadget
2022-12-20 20:04 ` [PATCH v4 1/2] " Seija Kijin via GitGitGadget
2022-12-20 20:04 ` [PATCH v4 2/2] prep Seija Kijin via GitGitGadget
2022-12-20 21:18 ` [PATCH v5] win32: close handles of threads that have been joined Rose via GitGitGadget
2022-12-20 22:06 ` Johannes Sixt
2022-12-21 4:35 ` [PATCH v6 0/2] " Rose via GitGitGadget
2022-12-21 4:35 ` [PATCH v6 1/2] " Seija Kijin via GitGitGadget
2022-12-21 4:35 ` [PATCH v6 2/2] prep Seija Kijin via GitGitGadget
2022-12-21 4:46 ` [PATCH v7 0/2] win32: close handles of threads that have been joined Rose via GitGitGadget
2022-12-21 4:46 ` [PATCH v7 1/2] " Seija Kijin via GitGitGadget
2022-12-22 7:52 ` Johannes Sixt
2022-12-21 4:46 ` [PATCH v7 2/2] prep Seija Kijin via GitGitGadget
2022-12-22 16:01 ` [PATCH v8] win32: close handles of threads that have been joined Rose via GitGitGadget
2022-12-22 17:17 ` [PATCH v9 0/2] " Rose via GitGitGadget
2022-12-22 17:17 ` [PATCH v9 1/2] " Seija Kijin via GitGitGadget
2022-12-22 17:17 ` [PATCH v9 2/2] prep: reformat pthread.c to fit coding guidelines Seija Kijin via GitGitGadget
2022-12-23 1:51 ` Junio C Hamano
2022-12-23 19:15 ` [PATCH v10 0/2] win32: close handles of threads that have been joined Rose via GitGitGadget
2022-12-23 19:15 ` [PATCH v10 1/2] win32-pthread: prepare pthread.c for change by formatting Seija Kijin via GitGitGadget
2022-12-23 19:15 ` [PATCH v10 2/2] win32: close handles of threads that have been joined Seija Kijin via GitGitGadget
2022-12-23 19:19 ` [PATCH v11 0/2] " Rose via GitGitGadget
2022-12-23 19:19 ` [PATCH v11 1/2] win32-pthread: prepare pthread.c for change by formatting Seija Kijin via GitGitGadget
2022-12-23 19:19 ` [PATCH v11 2/2] win32: close handles of threads that have been joined Seija Kijin via GitGitGadget
2022-12-24 7:50 ` René Scharfe
2022-12-25 1:40 ` [PATCH v12 0/2] " Rose via GitGitGadget
2022-12-25 1:40 ` [PATCH v12 1/2] win32-pthread: prepare pthread.c for change by formatting Seija Kijin via GitGitGadget
2022-12-26 1:32 ` Junio C Hamano
2022-12-25 1:40 ` [PATCH v12 2/2] win32: close handles of threads that have been joined Seija Kijin via GitGitGadget
2022-12-26 2:07 ` Junio C Hamano
2023-01-03 16:20 ` [PATCH v13 0/2] " Rose via GitGitGadget
2023-01-03 16:20 ` [PATCH v13 1/2] win32: prepare pthread.c for change by formatting Seija Kijin via GitGitGadget
2023-01-03 16:20 ` [PATCH v13 2/2] win32: close handles of threads that have been joined Seija Kijin via GitGitGadget
2023-01-05 15:44 ` [PATCH v14 0/2] " Rose via GitGitGadget
2023-01-05 15:44 ` [PATCH v14 1/2] win32: prepare pthread.c for change by formatting Seija Kijin via GitGitGadget
2023-01-05 15:44 ` [PATCH v14 2/2] win32: close handles of threads that have been joined Seija Kijin via GitGitGadget
2023-01-06 12:28 ` [PATCH v14 0/2] " Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=221219.86ili7xmd5.gmgdl@evledraar.gmail.com \
--to=avarab@gmail.com \
--cc=doremylover123@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).