Re: [Mingw-w64-public] [PATCH 1/2] Round up when converting nanoseconds to milliseconds

2019-03-01 Thread Liu Hao
在 2019/3/1 19:08, LRN 写道:
> 
> New version is attached.
> 
> 
> 
OK, pushed this one.

-- 
Best regards,
LH_Mouse



___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH 1/2] Round up when converting nanoseconds to milliseconds

2019-03-01 Thread LRN
On 01.03.2019 5:48, Liu Hao wrote:
> 在 2019/3/1 上午2:09, LRN 写道:
>> If the caller provides ts_nsec in struct timespec,
>> we lose precision when converting that time to milliseconds
>> for our WaitFor*() calls. Make sure we round *up* when doing that
>> conversion, as otherwise the wait time will be *less* than the caller
>> expects. Users of pthreads on non-realtime systems are generally
>> OK with functions returning a bit later than requested. But timing out
>> *earlier* than the requested time is completely unexpected.
>> ---
>>  mingw-w64-libraries/winpthreads/src/misc.c | 13 -
>>  1 file changed, 12 insertions(+), 1 deletion(-)
>>
>>
>>
> 
> This seems an overkill. There is a much simpler solution:
> 
> ```
> t += (unsigned long long) (ts->tv_nsec + 99) / 100;
> ```
> 
> 

New version is attached.
From 59fb104b98567fd4a56444daa4382e9e43279856 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?=
 =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= 
Date: Thu, 28 Feb 2019 17:49:49 +
Subject: [PATCH 1/2] Round up when converting nanoseconds to milliseconds

If the caller provides ts_nsec in struct timespec,
we lose precision when converting that time to milliseconds
for our WaitFor*() calls. Make sure we round *up* when doing that
conversion, as otherwise the wait time will be *less* than the caller
expects. Users of pthreads on non-realtime systems are generally
OK with functions returning a bit later than requested. But timing out
*earlier* than the requested time is completely unexpected.
---
 mingw-w64-libraries/winpthreads/src/misc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mingw-w64-libraries/winpthreads/src/misc.c 
b/mingw-w64-libraries/winpthreads/src/misc.c
index ab0488c..d8753f2 100644
--- a/mingw-w64-libraries/winpthreads/src/misc.c
+++ b/mingw-w64-libraries/winpthreads/src/misc.c
@@ -36,7 +36,8 @@ unsigned long long _pthread_time_in_ms(void)
 unsigned long long _pthread_time_in_ms_from_timespec(const struct timespec *ts)
 {
 unsigned long long t = (unsigned long long) ts->tv_sec * 1000LL;
-t += (unsigned long long) (ts->tv_nsec / 100);
+/* The +99 is here to ensure that the division always rounds up */
+t += (unsigned long long) (ts->tv_nsec + 99) / 100;
 
 return t;
 }
-- 
2.4.0



signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH 1/2] Round up when converting nanoseconds to milliseconds

2019-02-28 Thread LRN
On 01.03.2019 5:48, Liu Hao wrote:
> 在 2019/3/1 上午2:09, LRN 写道:
>> If the caller provides ts_nsec in struct timespec,
>> we lose precision when converting that time to milliseconds
>> for our WaitFor*() calls. Make sure we round *up* when doing that
>> conversion, as otherwise the wait time will be *less* than the caller
>> expects. Users of pthreads on non-realtime systems are generally
>> OK with functions returning a bit later than requested. But timing out
>> *earlier* than the requested time is completely unexpected.
>> ---
>>  mingw-w64-libraries/winpthreads/src/misc.c | 13 -
>>  1 file changed, 12 insertions(+), 1 deletion(-)
>>
>>
>>
> 
> This seems an overkill. There is a much simpler solution:
> 
> ```
> t += (unsigned long long) (ts->tv_nsec + 99) / 100;
> ```
> 
> 

I don't care how it works, as long as it works :)



signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH 1/2] Round up when converting nanoseconds to milliseconds

2019-02-28 Thread Liu Hao
在 2019/3/1 上午2:09, LRN 写道:
> If the caller provides ts_nsec in struct timespec,
> we lose precision when converting that time to milliseconds
> for our WaitFor*() calls. Make sure we round *up* when doing that
> conversion, as otherwise the wait time will be *less* than the caller
> expects. Users of pthreads on non-realtime systems are generally
> OK with functions returning a bit later than requested. But timing out
> *earlier* than the requested time is completely unexpected.
> ---
>  mingw-w64-libraries/winpthreads/src/misc.c | 13 -
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> 
> 

This seems an overkill. There is a much simpler solution:

```
t += (unsigned long long) (ts->tv_nsec + 99) / 100;
```


-- 
Best regards,
LH_Mouse



signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public