Thread (1 message) 1 message, 1 author, 2025-11-21

Re: [PATCH v3] win32: pthread_cond_init should return a value

From: Junio C Hamano <hidden>
Date: 2025-11-21 01:46:59

"AZero13 via GitGitGadget" [off-list ref] writes:
From: Greg Funni <redacted>

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

Signed-off-by: Greg Funni <redacted>
---
    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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help