|
Boost : |
Subject: Re: [boost] [chrono] Thread clock compatibility problems on Android
From: Vicente Botet (vicente.botet_at_[hidden])
Date: 2011-05-14 13:12:21
Libor Bus wrote:
>
>
> Vicente Botet wrote:
>>
>> Is CLOCK_THREAD_CPUTIME_ID a macro on this platform? I would prefer to
>> check if CLOCK_THREAD_CPUTIME_ID is defined and use it. Would it be the
>> correct behavior?
>>
>
> Yes, is defined like:
> #define CLOCK_THREAD_CPUTIME_ID 3
> in time.h.
>
Great. I will use this macro then, which seems to be more general.
>
> Vicente Botet wrote:
>>
>> could you try this patch
>>
>> // chrono/config.hpp
>>
>> # if defined(_POSIX_THREAD_CPUTIME) && !defined(BOOST_DISABLE_THREADS)
>> # define BOOST_CHRONO_HAS_THREAD_CLOCK
>> # define BOOST_CHRONO_THREAD_CLOCK_IS_STEADY true
>> # endif
>> # if defined(CLOCK_THREAD_CPUTIME_ID) &&
>> !defined(BOOST_DISABLE_THREADS)
>> # define BOOST_CHRONO_HAS_THREAD_CLOCK
>> # define BOOST_CHRONO_THREAD_CLOCK_IS_STEADY true
>> # endif
>>
>
> This causes compilation error because
> BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC is undefined in
> chrono/thread_clock.hpp:
> BOOST_CHRONO_STATIC_CONSTEXPR bool is_monotonic =
> BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC;
>
> However following patch works for me:
> # if defined(_POSIX_THREAD_CPUTIME) && !defined(BOOST_DISABLE_THREADS)
> # define BOOST_CHRONO_HAS_THREAD_CLOCK
> # define BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC true
> # endif
> # if defined(CLOCK_THREAD_CPUTIME_ID) && !defined(BOOST_DISABLE_THREADS)
> # define BOOST_CHRONO_HAS_THREAD_CLOCK
> # define BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC true
> # endif
> I'm not sure about BOOST_DISABLE_THREADS.
>
Oh, I see. You are not using the lib in the trunk which has replaced
monotonic clocks by steady clocks.
>
> Vicente Botet wrote:
>>
>> // posix/thread_clock.hpp
>> ...
>> #if defined CLOCK_THREAD_CPUTIME_ID
>> if ( ::clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts ) )
>> #else
>> // get the current thread
>> pthread_t pth=pthread_self();
>> // get the clock_id associated to the current thread
>> clockid_t clock_id;
>> pthread_getcpuclockid(pth, &clock_id);
>> // get the timespec associated to the thread clock
>> if ( ::clock_gettime( clock_id, &ts ) )
>> #endif
>>
> On Android works fine for me.
>
I have committed it on trunk. I will see how this behaves on the regression
compilers before moving it to the release branch. I would appreciate if you
create a ticket on the Trac system.
Best,
Vicente
-- View this message in context: http://boost.2283326.n4.nabble.com/chrono-Thread-clock-compatibility-problems-on-Android-tp3520310p3522746.html Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk