LIU Hao wrote:
> Is there a reason why `_POSIX_TIMERS` is no longer defined? In GCC source
> code there's a check for it:
> https://github.com/gnutools/gcc/blob/9c3dc461749a1257b9939625ef59b2b056035311/gcc/timevar.cc#L162,
> and
> also the comment about `_POSIX_CLOCK_SELECTION` says it 'implies the
> _POSIX_TIMERS option' so
> `_POSIX_TIMERS` should be defined.
My understanding is that constant `_POSIX_TIMERS`[1] indicates that function
`timer_create`[2] and friends are available, which is not the case for
winpthreads.
POSIX describes it as:
```
_POSIX_TIMERS
The implementation supports timers. This symbol shall always be set to the
value 202405L.
```
I was unable to find more details about `_POSIX_TIMERS` and what it implies.
> `GetSystemTimeAdjustmentPrecise()` is not exported from kernel32.dll; it's
> only exported from kernelbase.dll.
Good catch.
> `clock_nanosleep()` should return the error number directly; unlike
> `nanosleep()` it does not set `errno`.
With current implementation which is just a wrapper around `nanosleep`, it is a
bit tricky to do. I'll fix it in later changes.
> Also some more suggestions:
>
> -WINPTHREAD_API int __cdecl clock_nanosleep32(clockid_t, int , const struct
> _timespec32 *, struct
> _timespec32 *);
> -WINPTHREAD_API int __cdecl clock_nanosleep64(clockid_t, int , const struct
> _timespec64 *, struct
> _timespec64 *);
> +WINPTHREAD_API int __cdecl clock_nanosleep32(clockid_t, int, const struct
> _timespec32 *, struct
> _timespec32 *);
> +WINPTHREAD_API int __cdecl clock_nanosleep64(clockid_t, int, const struct
> _timespec64 *, struct
> _timespec64 *);
> WINPTHREAD_TIME_DECL int __cdecl clock_nanosleep(clockid_t _C, int _F, const
> struct timespec *_T1,
> struct timespec *_T2)
Nice catch; I missed that extra space after `int`.
> - if (likely (start.QuadPart < end.QuadPart)) {
> + if (likely (start.QuadPart <= end.QuadPart)) {
Right; if `start` and `end` are the same, `elapsedSleepTime` will be zero,
which means we still have to sleep for `totalSleepTime`.
> - struct _timespec64 remain64;
> + struct _timespec64 remain64 = {0};
I think it's not needed. If `clock_nanosleep64` fails with `EINTR`, it will
fill in both `remain64.tv_sec` and `remain64.tv_nsec` and they are accessed
only when `clock_nanosleep64` fails with `EINTR`.
I'll send updated version later today. I guess I can skip CI on my side?
- Kirill Makurin
[1]
https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/basedefs/unistd.h.html
[2]
https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/timer_create.html
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public