git icon indicating copy to clipboard operation
git copied to clipboard

win32: pthread_cond_init should return a value

Open AZero13 opened this issue 1 month ago • 33 comments

This value is not checked, but it must return to match POSIX

AZero13 avatar Nov 18 '25 00:11 AZero13

There are issues in commit a311ebc2edcb90cd3e59c9d88e227b7609a29375: win32: pthread_cond_wait should return a value Commit not signed off

gitgitgadget-git[bot] avatar Nov 18 '25 00:11 gitgitgadget-git[bot]

/submit

AZero13 avatar Nov 18 '25 00:11 AZero13

Submitted as [email protected]

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2103/AZero13/pthread-v1

To fetch this version to local tag pr-git-2103/AZero13/pthread-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2103/AZero13/pthread-v1

gitgitgadget-git[bot] avatar Nov 18 '25 01:11 gitgitgadget-git[bot]

/submit

AZero13 avatar Nov 18 '25 15:11 AZero13

Submitted as [email protected]

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2103/AZero13/pthread-v2

To fetch this version to local tag pr-git-2103/AZero13/pthread-v2:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2103/AZero13/pthread-v2

gitgitgadget-git[bot] avatar Nov 18 '25 15:11 gitgitgadget-git[bot]

On the Git mailing list, Junio C Hamano wrote (reply to this):

"AZero13 via GitGitGadget" <[email protected]> writes:

> Subject: Re: [PATCH v2] win32: pthread_cond_wait should return a value

Is this mistitled?  The patch text talks about cond_init(), not cond_wait(),
which is the theme for the other patch around SleepConditionVariableCS().

> From: Greg Funni <[email protected]>
>
> This value is not checked, but it must return to match POSIX
>
> Signed-off-by: Greg Funni <[email protected]>
> ---
> ...
> diff --git a/compat/win32/pthread.h b/compat/win32/pthread.h
> index e2b5c4f64c..000604cdf6 100644
> --- a/compat/win32/pthread.h
> +++ b/compat/win32/pthread.h
> @@ -34,7 +34,7 @@ typedef int pthread_mutexattr_t;
>  
>  #define pthread_cond_t CONDITION_VARIABLE
>  
> -#define pthread_cond_init(a,b) InitializeConditionVariable((a))
> +#define pthread_cond_init(a,b) return_0((InitializeConditionVariable((a)), 0))
>  #define pthread_cond_destroy(a) do {} while (0)
>  #define pthread_cond_wait(a,b) return_0(SleepConditionVariableCS((a), (b), INFINITE))
>  #define pthread_cond_signal WakeConditionVariable
>
> base-commit: 9a2fb147f2c61d0cab52c883e7e26f5b7948e3ed

gitgitgadget-git[bot] avatar Nov 18 '25 18:11 gitgitgadget-git[bot]

Yes this was a typo. I apologize.

AZero13 avatar Nov 18 '25 21:11 AZero13

Yes this was a typo. I apologize.

@AZero13 you probably value the convenience of commenting on a PR. The Git project raises the bar, though, you have to follow the guidance in the "reply to this" link to get heard.

dscho avatar Nov 19 '25 07:11 dscho

/submit

AZero13 avatar Nov 20 '25 21:11 AZero13

Submitted as [email protected]

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2103/AZero13/pthread-v3

To fetch this version to local tag pr-git-2103/AZero13/pthread-v3:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2103/AZero13/pthread-v3

gitgitgadget-git[bot] avatar Nov 20 '25 21:11 gitgitgadget-git[bot]

This patch series was integrated into seen via https://github.com/git/git/commit/b871fe5c4e3e0e828d7ceb370c1cdcaa876bc131.

gitgitgadget-git[bot] avatar Nov 21 '25 02:11 gitgitgadget-git[bot]

On the Git mailing list, Junio C Hamano wrote (reply to this):

"AZero13 via GitGitGadget" <[email protected]> writes:

> From: Greg Funni <[email protected]>
>
> This value is not checked, but it must return to match POSIX
>
> Signed-off-by: Greg Funni <[email protected]>
> ---
>     win32: pthread_cond_init should return a value
>     
>     This value is not checked, but it must return to match POSIX
> ...
> -#define pthread_cond_init(a,b) InitializeConditionVariable((a))
> +#define pthread_cond_init(a,b) return_0((InitializeConditionVariable((a)), 0))

This is tricky and I like it.

Because InitializeConditionVariable() returns void, and return_0()
is defined as such:

    static inline int return_0(int i) { return 0; }

you cannot directly pass InitializeConditionVariable() to it, so you
use a comma operator and pass 0 to return_0().  Because the type of
the comma operator with mixed operands is the type of the rightmost
operand, the type of "InitializeConditionVariable((a)), 0" is type
of "0", so return_0() would happily take it as an int, and returns
0.

This should work correctly, but it still is tricky and yucky.

You may not have to use return_0(), but OK.

Will queue.  Thanks.

gitgitgadget-git[bot] avatar Nov 21 '25 02:11 gitgitgadget-git[bot]

This patch series was integrated into seen via https://github.com/git/git/commit/061c72af17dbb57b3a9cc75967ba3ec70c36812a.

gitgitgadget-git[bot] avatar Nov 21 '25 22:11 gitgitgadget-git[bot]

This branch is now known as gf/win32-pthread-cond-init.

gitgitgadget-git[bot] avatar Nov 21 '25 23:11 gitgitgadget-git[bot]

This patch series was integrated into seen via https://github.com/git/git/commit/3c0725b0589fea975d71e553331a2b306d16f39c.

gitgitgadget-git[bot] avatar Nov 24 '25 00:11 gitgitgadget-git[bot]

There was a status update in the "New Topics" section about the branch gf/win32-pthread-cond-init on the Git mailing list:

Emulation code clean-up.

Will merge to 'next'?
source: <[email protected]>

gitgitgadget-git[bot] avatar Nov 24 '25 05:11 gitgitgadget-git[bot]

This patch series was integrated into seen via https://github.com/git/git/commit/796d489c93fa9966be508a6632dfc869e92987fe.

gitgitgadget-git[bot] avatar Nov 24 '25 20:11 gitgitgadget-git[bot]

This patch series was integrated into seen via https://github.com/git/git/commit/6d839ca3fc09708268030b4ca725fb9075c0de9a.

gitgitgadget-git[bot] avatar Nov 25 '25 01:11 gitgitgadget-git[bot]

This patch series was integrated into seen via https://github.com/git/git/commit/0003db9a18848d0e194474b226281506122beda3.

gitgitgadget-git[bot] avatar Nov 25 '25 21:11 gitgitgadget-git[bot]

There was a status update in the "Cooking" section about the branch gf/win32-pthread-cond-init on the Git mailing list:

Emulation code clean-up.

Will merge to 'next'?
source: <[email protected]>

gitgitgadget-git[bot] avatar Nov 26 '25 01:11 gitgitgadget-git[bot]

This patch series was integrated into seen via https://github.com/git/git/commit/af9aeec506662046a037678b3b8ea6e6a7ef14e4.

gitgitgadget-git[bot] avatar Nov 26 '25 19:11 gitgitgadget-git[bot]

There was a status update in the "Cooking" section about the branch gf/win32-pthread-cond-init on the Git mailing list:

Emulation code clean-up.

Will merge to 'next'?
source: <[email protected]>

gitgitgadget-git[bot] avatar Nov 29 '25 04:11 gitgitgadget-git[bot]

This patch series was integrated into seen via https://github.com/git/git/commit/923c79229f40a8fa1d04d173bd0b365180f1b8db.

gitgitgadget-git[bot] avatar Dec 01 '25 03:12 gitgitgadget-git[bot]

There was a status update in the "Cooking" section about the branch gf/win32-pthread-cond-init on the Git mailing list:

Emulation code clean-up.

Will merge to 'next'?
source: <[email protected]>

gitgitgadget-git[bot] avatar Dec 01 '25 05:12 gitgitgadget-git[bot]

This patch series was integrated into seen via https://github.com/git/git/commit/784ef72ce27f9406dc6bc05644b5a1d6e2198888.

gitgitgadget-git[bot] avatar Dec 05 '25 04:12 gitgitgadget-git[bot]

On the Git mailing list, Junio C Hamano wrote (reply to this):

Junio C Hamano <[email protected]> writes:

> "AZero13 via GitGitGadget" <[email protected]> writes:
>
>> From: Greg Funni <[email protected]>
>>
>> This value is not checked, but it must return to match POSIX
>>
>> Signed-off-by: Greg Funni <[email protected]>
>> ---
>>     win32: pthread_cond_init should return a value
>>     
>>     This value is not checked, but it must return to match POSIX
>> ...
>> -#define pthread_cond_init(a,b) InitializeConditionVariable((a))
>> +#define pthread_cond_init(a,b) return_0((InitializeConditionVariable((a)), 0))
>
> This is tricky and I like it.
>
> Because InitializeConditionVariable() returns void, and return_0()
> is defined as such:
>
>     static inline int return_0(int i) { return 0; }
>
> you cannot directly pass InitializeConditionVariable() to it, so you
> use a comma operator and pass 0 to return_0().  Because the type of
> the comma operator with mixed operands is the type of the rightmost
> operand, the type of "InitializeConditionVariable((a)), 0" is type
> of "0", so return_0() would happily take it as an int, and returns
> 0.
>
> This should work correctly, but it still is tricky and yucky.
>
> You may not have to use return_0(), but OK.
>
> Will queue.  Thanks.

As I do not do Windows, I was hoping somebody more clueful than
myself on the platform would give an Ack to this patch, but we saw
nothing.  I'll mark the topic for 'next'.  I do not anticipate
breakage but if there were something fishy, hopefully we will hear
quickly enough.

gitgitgadget-git[bot] avatar Dec 07 '25 01:12 gitgitgadget-git[bot]

This patch series was integrated into seen via https://github.com/git/git/commit/7516322387feb06b49633a57348fd08c522a6b68.

gitgitgadget-git[bot] avatar Dec 07 '25 03:12 gitgitgadget-git[bot]

There was a status update in the "Cooking" section about the branch gf/win32-pthread-cond-init on the Git mailing list:

Emulation code clean-up.

Will merge to 'next'.
source: <[email protected]>

gitgitgadget-git[bot] avatar Dec 07 '25 07:12 gitgitgadget-git[bot]

This patch series was integrated into seen via https://github.com/git/git/commit/1719ba42719396becfb0d472608fb9b66f3ae8f0.

gitgitgadget-git[bot] avatar Dec 09 '25 13:12 gitgitgadget-git[bot]

This patch series was integrated into next via https://github.com/git/git/commit/202516d20c11395565196e3fced1546f451f969b.

gitgitgadget-git[bot] avatar Dec 09 '25 13:12 gitgitgadget-git[bot]