This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Re: Re: Adding a new thread model to GCC
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: lh_mouse <lh_mouse at 126 dot com>
- Cc: gcc <gcc at gcc dot gnu dot org>, mingw-w64-public <mingw-w64-public at lists dot sourceforge dot net>
- Date: Mon, 18 Apr 2016 10:57:05 +0100
- Subject: Re: Re: Re: Adding a new thread model to GCC
- Authentication-results: sourceware.org; auth=none
- References: <2f3897eb dot bbc0e dot 1540ee9aa0b dot Coremail dot lh_mouse at 126 dot com> <CAH6eHdQ2b_NLLC6Hyq=tKgXhgAEhTdV1d2+sv6enHN7wG4JESQ at mail dot gmail dot com> <3eafd9c2 dot ce5a2 dot 154252730a4 dot Coremail dot lh_mouse at 126 dot com> <CAH6eHdQhDSwSt91xSi_yGSrsownGCErTP5H=3w1NrjXkr9T98Q at mail dot gmail dot com> <3d4feb73 dot d4007 dot 15428a9a070 dot Coremail dot lh_mouse at 126 dot com>
On 18 April 2016 at 10:18, lh_mouse wrote:
>> I don't see why it has to be a struct, it just has to be suitable as
>> an argument to the relevant __gthread functions.
>
> The type __gthread_time_t is referenced in gcc/libstdc++-v3/include/std/mutex:157
> __gthread_time_t __ts = {
> static_cast<std::time_t>(__s.time_since_epoch().count()),
> static_cast<long>(__ns.count())
> };
> This definition uses a braced-init-list that has two elements and is unsuitable for scalar types.
Yes I know.
What I meant is that there's no fundamental reason it needs to be a
struct. That code could be changed.
>> If the current code assumes a struct and the Windows API calls need an
>> integer then either the existing code needs to be made more flexible,
>> or you need to define it as a struct and then convert to an integer
>> inside your new gthread wrapper functions.
>
> The Windows APIs involved use LARGE_INTEGER - a union of a 64-bit integer and an array of two 32-bit integers - because some languages might have no native 64-bit integer types.
> Actually in C99 and C++11 we just assume there is long long and int64_t despite the fact that ISO C marks int64_t as optional, so it can be regarded as a union whose only element is an int64_t.
What are the units of the argument? Milliseconds?
You have two choices, either modify all the places in libstdc++ that
use __gthread_time_t, changing the code to use some new function
template that populates a __gthread_time_t from a
std::chrono::time_point<C,D> or std::chrono::duration<R,P>, or define
a similar struct in your gthreads header and convert it to int64_t
inside your functions. For functions taking a relative time the
conversion from a { seconds, nanoseconds } struct to milliseconds is
trivial, for functions taking an absolute time you need to know the
epoch of the clock that was used when populating the struct.