X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FScheduler%2FClockService.cci;h=bf2740186dc91b52ad302c22727718cfb69dc954;hb=728c6fbeb525a2b48b927ebf17cc06ca943583b2;hp=c3a766f318f421e5f7daa8acc7e104fc4cb493a4;hpb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;p=senf.git diff --git a/senf/Scheduler/ClockService.cci b/senf/Scheduler/ClockService.cci index c3a766f..bf27401 100644 --- a/senf/Scheduler/ClockService.cci +++ b/senf/Scheduler/ClockService.cci @@ -2,23 +2,28 @@ // // Copyright (C) 2007 // Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY -// Stefan Bund // -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. +// The contents of this file are subject to the Fraunhofer FOKUS Public License +// Version 1.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// http://senf.berlios.de/license.html // -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// The Fraunhofer FOKUS Public License Version 1.0 is based on, +// but modifies the Mozilla Public License Version 1.1. +// See the full license text for the amendments. // -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the -// Free Software Foundation, Inc., -// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// Software distributed under the License is distributed on an "AS IS" basis, +// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +// for the specific language governing rights and limitations under the License. +// +// The Original Code is Fraunhofer FOKUS code. +// +// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. +// (registered association), Hansastraße 27 c, 80686 Munich, Germany. +// All Rights Reserved. +// +// Contributor(s): +// Stefan Bund /** \file \brief ClockService inline non-template implementation */ @@ -26,12 +31,13 @@ // Custom includes #include #include -#include "../Utils/Exception.hh" +#include +#include #define prefix_ inline -///////////////////////////////cci.p/////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::ClockService prefix_ senf::ClockService::clock_type senf::ClockService::now() @@ -39,15 +45,17 @@ prefix_ senf::ClockService::clock_type senf::ClockService::now() struct timespec spec; if (clock_gettime(CLOCK_MONOTONIC, &spec) < 0) SENF_THROW_SYSTEM_EXCEPTION("clock_gettime()"); - return spec.tv_sec * 1000000000LL + spec.tv_nsec; + return SENF_INT2CLOCKTYPE(spec.tv_sec * 1000000000LL + spec.tv_nsec); } -//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // private members +namespace senf { namespace scheduler { ClockService::clock_type now(); } } + prefix_ senf::ClockService::clock_type senf::ClockService::clock_m(abstime_type time) { - if (now() - baseClock_ > 1000000000ll) + if (scheduler::now() - baseClock_ > clock_type(1000000000ll)) restart_m(); boost::posix_time::time_duration delta (time - baseAbstime_); return baseClock_ + clock_type( delta.ticks() ) @@ -58,12 +66,12 @@ prefix_ senf::ClockService::abstime_type senf::ClockService::abstime_m(clock_typ { if (clock == 0) return abstime_type(); - if (now() - baseClock_ > 1000000000ll) + if (scheduler::now() - baseClock_ > clock_type(1000000000ll)) restart_m(); #ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG return baseAbstime_ + boost::posix_time::nanoseconds(clock-baseClock_); #else - return baseAbstime_ + boost::posix_time::microseconds((clock-baseClock_+500)/1000); + return baseAbstime_ + boost::posix_time::microseconds((clock.value() - baseClock_.value() + 500 )/1000); #endif } @@ -90,7 +98,7 @@ prefix_ senf::ClockService::reltime_type senf::ClockService::reltime(clock_type #ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG return boost::posix_time::nanoseconds(clock); #else - return boost::posix_time::microseconds((clock+500)/1000); + return boost::posix_time::microseconds((clock.value() + 500)/1000); #endif } @@ -106,77 +114,77 @@ prefix_ senf::ClockService::clock_type senf::ClockService::from_time_t(time_t co prefix_ senf::ClockService::clock_type senf::ClockService::nanoseconds(int64_type v) { - return v; + return SENF_INT2CLOCKTYPE(v); } prefix_ senf::ClockService::clock_type senf::ClockService::microseconds(int64_type v) { - return v * nanoseconds(1000); + return SENF_INT2CLOCKTYPE(v * SENF_CLOCKTYPEVAL(nanoseconds(1000))); } prefix_ senf::ClockService::clock_type senf::ClockService::milliseconds(int64_type v) { - return v * microseconds(1000); + return SENF_INT2CLOCKTYPE(v * SENF_CLOCKTYPEVAL(microseconds(1000))); } prefix_ senf::ClockService::clock_type senf::ClockService::seconds(int64_type v) { - return v * milliseconds(1000); + return SENF_INT2CLOCKTYPE(v * SENF_CLOCKTYPEVAL(milliseconds(1000))); } prefix_ senf::ClockService::clock_type senf::ClockService::minutes(int64_type v) { - return v * seconds(60); + return SENF_INT2CLOCKTYPE(v * SENF_CLOCKTYPEVAL(seconds(60))); } prefix_ senf::ClockService::clock_type senf::ClockService::hours(int64_type v) { - return v * minutes(60); + return SENF_INT2CLOCKTYPE(v * SENF_CLOCKTYPEVAL(minutes(60))); } prefix_ senf::ClockService::clock_type senf::ClockService::days(int64_type v) { - return v * hours(24); + return SENF_INT2CLOCKTYPE(v * SENF_CLOCKTYPEVAL(hours(24))); } -prefix_ senf::ClockService::clock_type senf::ClockService::in_nanoseconds(int64_type v) +prefix_ senf::ClockService::int64_type senf::ClockService::in_nanoseconds(clock_type v) { - return v; + return SENF_CLOCKTYPEVAL(v); } -prefix_ senf::ClockService::clock_type senf::ClockService::in_microseconds(int64_type v) +prefix_ senf::ClockService::int64_type senf::ClockService::in_microseconds(clock_type v) { - return v / nanoseconds(1000); + return (SENF_CLOCKTYPEVAL(v) / SENF_CLOCKTYPEVAL(nanoseconds(1000))); } -prefix_ senf::ClockService::clock_type senf::ClockService::in_milliseconds(int64_type v) +prefix_ senf::ClockService::int64_type senf::ClockService::in_milliseconds(clock_type v) { - return v / microseconds(1000); + return (SENF_CLOCKTYPEVAL(v) / SENF_CLOCKTYPEVAL(microseconds(1000))); } -prefix_ senf::ClockService::clock_type senf::ClockService::in_seconds(int64_type v) +prefix_ senf::ClockService::int64_type senf::ClockService::in_seconds(clock_type v) { - return v / milliseconds(1000); + return (SENF_CLOCKTYPEVAL(v) / SENF_CLOCKTYPEVAL(milliseconds(1000))); } -prefix_ senf::ClockService::clock_type senf::ClockService::in_minutes(int64_type v) +prefix_ senf::ClockService::int64_type senf::ClockService::in_minutes(clock_type v) { - return v / seconds(60); + return (SENF_CLOCKTYPEVAL(v) / SENF_CLOCKTYPEVAL(seconds(60))); } -prefix_ senf::ClockService::clock_type senf::ClockService::in_hours(int64_type v) +prefix_ senf::ClockService::int64_type senf::ClockService::in_hours(clock_type v) { - return v / minutes(60); + return (SENF_CLOCKTYPEVAL(v) / SENF_CLOCKTYPEVAL(minutes(60))) ; } -prefix_ senf::ClockService::clock_type senf::ClockService::in_days(int64_type v) +prefix_ senf::ClockService::int64_type senf::ClockService::in_days(clock_type v) { - return v / hours(24); + return (SENF_CLOCKTYPEVAL(v) / SENF_CLOCKTYPEVAL(hours(24))) ; } prefix_ senf::ClockService::clock_type senf::ClockService::from_timeval(timeval const & time) { - return from_time_t(time.tv_sec) + ClockService::microseconds(time.tv_usec); + return from_time_t(time.tv_sec) + microseconds(time.tv_usec); } prefix_ void senf::ClockService::restart() @@ -184,7 +192,7 @@ prefix_ void senf::ClockService::restart() instance().restart_m(); } -///////////////////////////////cci.e/////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// #undef prefix_