root/unix/hp_timer_impl.hpp

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. to_usec
  2. get_start_time
  3. current_count
  4. current_time
  5. start_up_count

   1 /******************************************************************************
   2 ** $Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/unix/hp_timer_impl.hpp 2055 2017-05-13 19:35:47Z jmmcg $
   3 **
   4 ** Copyright © 2012 by J.M.McGuiness, coder@hussar.me.uk
   5 **
   6 ** This library is free software; you can redistribute it and/or
   7 ** modify it under the terms of the GNU Lesser General Public
   8 ** License as published by the Free Software Foundation; either
   9 ** version 2.1 of the License, or (at your option) any later version.
  10 **
  11 ** This library is distributed in the hope that it will be useful,
  12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14 ** Lesser General Public License for more details.
  15 **
  16 ** You should have received a copy of the GNU Lesser General Public
  17 ** License along with this library; if not, write to the Free Software
  18 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19 */
  20 
  21 namespace jmmcg {
  22 
  23 template<typename Mdl>
  24 inline typename hp_timer<ppd::generic_traits::api_type::posix_pthreads, Mdl>::value_type
  25 hp_timer<ppd::generic_traits::api_type::posix_pthreads, Mdl>::to_usec(const time_utc_t ticks) noexcept(true) {
  26         const value_type tmp=static_cast<value_type>(ticks.tv_sec)*1000000+ticks.tv_nsec/1000.0;
  27         return tmp;
  28 }
  29 
  30 template<typename Mdl>
  31 inline const typename hp_timer<ppd::generic_traits::api_type::posix_pthreads, Mdl>::time_utc_t
  32 hp_timer<ppd::generic_traits::api_type::posix_pthreads, Mdl>::get_start_time() noexcept(false) {
  33         time_utc_t tm;
  34         if (::clock_gettime(CLOCK_REALTIME, &tm)) {
  35                 throw exception_type(_T("High-performance counter not supported."), jmmcg::info::function(__LINE__,__PRETTY_FUNCTION__,typeid(&hp_timer<ppd::generic_traits::api_type::posix_pthreads, Mdl>::get_start_time)), JMMCG_REVISION_HDR(_T("$Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/unix/hp_timer_impl.hpp 2055 2017-05-13 19:35:47Z jmmcg $")));
  36         }
  37         return tm;
  38 }
  39 
  40 template<typename Mdl>
  41 inline typename hp_timer<ppd::generic_traits::api_type::posix_pthreads, Mdl>::value_type
  42 hp_timer<ppd::generic_traits::api_type::posix_pthreads, Mdl>::current_count() noexcept(false) {
  43         return to_usec(get_start_time());
  44 }
  45 
  46 template<typename Mdl>
  47 inline const typename hp_timer<ppd::generic_traits::api_type::posix_pthreads, Mdl>::time_utc_t
  48 hp_timer<ppd::generic_traits::api_type::posix_pthreads, Mdl>::current_time() const noexcept(false) {
  49         return get_start_time();
  50 }
  51 
  52 template<typename Mdl>
  53 inline
  54 hp_timer<ppd::generic_traits::api_type::posix_pthreads, Mdl>::hp_timer() noexcept(false)
  55 : start_up_time(get_start_time()),
  56         start_up_count(current_count()) {
  57 }
  58 
  59 template <typename T>
  60 inline
  61 hp_interval<T>::~hp_interval() noexcept(true) {
  62         const typename timer_t::time_utc_t end=timer.current_time();
  63         if (end.tv_nsec>=start.tv_nsec) {
  64                 interval.tv_nsec=end.tv_nsec-start.tv_nsec;
  65                 interval.tv_sec=end.tv_sec-start.tv_sec;
  66         } else {
  67                 interval.tv_nsec=1000000000+(end.tv_nsec-start.tv_nsec);
  68                 interval.tv_sec=end.tv_sec-start.tv_sec-1;
  69         }
  70 }
  71 
  72 }

/* [<][>][^][v][top][bottom][index][help] */