_Cnd_timedwait timeout

Stefan Dösinger stefan at codeweavers.com
Mon Dec 4 10:33:14 CST 2017


Hi Daniel and Piotr,

I am having a trouble with _Cnd_timedwait and I am trying to understand
a few things.

The problem I'm running into is that the application I am dealing with
passes a timestamp that is 30 days into the future. This overflows in
_Xtime_diff_to_millis(2) and the result we get is somewhere in the area
of -1708070296. Now _Cnd_timedwait casts this to an ULONGLONG, so I
would expect the multiplication to come up with the right result, but
no, the function passes a timeout of 170807029600000 to
NtWaitForKeyedEvent, which is interpreted as an absolute value in the
past and instantly times out.

To get the right result I have to assign the result of
_Xtime_diff_to_millis to an ULONG and cast this back to a 64 bit signed
value - otherwise the multiplication happens in unsigned 32 bit and
results in a positive number that will fit in a a signed 64 bit integer
with ease.

So my two questions are:

1) Why go through _Xtime_diff_to_millis at all? If I understand the
server code right NtWaitForKeyedEvent should do the right thing if we
pass timeout.QuadPart = sec * 1000 * 1000 * 100 + nsec / 10. And indeed
in my quick testing this works for the app and passes the tests. Are
there timezone issues?

2) What C integer legalese prevents the current code from working? All
the signed/unsigned conversion references I found talk about
assignments, not casts in calculations.

Cheers,
Stefan



More information about the wine-devel mailing list