Boost logo

Boost :

Subject: Re: [boost] [chrono] Thread clock compatibility problems on Android
From: Libor Bus (libor.bus_at_[hidden])
Date: 2011-05-14 12:16:53


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.

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.

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.

BR,
Libor

--
View this message in context: http://boost.2283326.n4.nabble.com/chrono-Thread-clock-compatibility-problems-on-Android-tp3520310p3522620.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