senf::ClockService::clock_type start (senf::ClockService::now());
run( senf::ClockService::seconds(1));
std::cerr << "\nActiveFeeder: "
- << (sink.size()*1e9)/(senf::ClockService::now()-start)
+ << (sink.size()*1e9)/ (SENF_CLOCKTYPEVAL(senf::ClockService::now()) - SENF_CLOCKTYPEVAL(start))
<< " packets/s" << std::endl;
BOOST_CHECK( sink.size() > 0);
}
// Custom includes
#include "EventManager.hh"
+#include <senf/Utils/ClockTypeMacros.hh>
//#include "IntervalTimer.mpp"
#define prefix_
prefix_ void senf::ppi::IntervalTimer::schedule()
{
- info_.expected = info_.intervalStart + ( interval_ * (info_.number+1) ) / eventsPerInterval_;
+ info_.expected = SENF_INT2CLOCKTYPE(SENF_CLOCKTYPEVAL(info_.intervalStart) + ( SENF_CLOCKTYPEVAL(interval_) * (info_.number+1) ) / eventsPerInterval_);
timer_.timeout(info_.expected);
}
// Custom includes
#include <boost/regex.hpp>
#include <senf/Utils/Console/Traits.hh>
-
+#include <senf/Utils/ClockTypeMacros.hh>
//#include "ClockService.mpp"
#define prefix_
//-/////////////////////////////////////////////////////////////////////////////////////////////////
senf::parseClockServiceInterval(console::ParseCommandInfo::TokensRange const & tokens,
ClockService::clock_type & out)
{
- out = 0;
+ out = senf::ClockService::clock_type(0);
std::string value;
{
console::CheckedArgumentIteratorWrapper arg (tokens);
#include <time.h>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <senf/Utils/Exception.hh>
+#include <senf/Utils/ClockTypeMacros.hh>
#define prefix_ inline
//-/////////////////////////////////////////////////////////////////////////////////////////////////
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);
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
prefix_ senf::ClockService::clock_type senf::ClockService::clock_m(abstime_type time)
{
- if (scheduler::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() )
{
if (clock == 0)
return abstime_type();
- if (scheduler::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
}
#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
}
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)
#include <senf/config.hh>
#include <senf/Utils/singleton.hh>
#include <senf/Utils/Console/Parse.hh>
+#include <senf/Utils/RestrictedInt.hh>
//#include "ClockService.mpp"
//-/////////////////////////////////////////////////////////////////////////////////////////////////
Unsigned integer type representing scheduler time. Scheduler time is measured in
nanoseconds relative to some implementation defined reference time.
*/
+#ifdef SENF_DEBUG
+ struct ClockTypeTag {};
+ typedef senf::RestrictedInt<config::time_type, ClockTypeTag> clock_type;
+#else
typedef config::time_type clock_type;
-
+#endif
/** \brief Supplementary integer type
This type is used to represent varies supplementary values (e.g. number of microseconds)
*/
+
typedef boost::int_fast64_t int64_type;
/** \brief Absolute time data type
SENF_AUTO_UNIT_TEST(clockService)
{
- BOOST_CHECK( senf::ClockService::abstime(0).is_not_a_date_time());
+ BOOST_CHECK( senf::ClockService::abstime(senf::ClockService::clock_type(0)).is_not_a_date_time());
char const * enabled (getenv("SENF_TIMING_CRITICAL_TESTS"));
BOOST_WARN_MESSAGE(enabled, "Set SENF_TIMING_CRITICAL_TESTS to not skip timing critical tests");
prefix_ senf::log::time_type senf::scheduler::LogTimeSource::operator()()
const
{
- return scheduler::now();
+ return SENF_CLOCKTYPEVAL(scheduler::now());
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
}
prefix_ senf::scheduler::TimerEvent::TimerEvent(std::string const & name, Callback const & cb)
- : detail::FIFORunner::TaskInfo (name), cb_ (cb), timeout_ (0)
+ : detail::FIFORunner::TaskInfo (name), cb_ (cb), timeout_ (SENF_INT2CLOCKTYPE(0))
{}
prefix_ senf::scheduler::TimerEvent::~TimerEvent()
{
//std::cerr << "diff:" << senf::ClockService::in_microseconds( senf::scheduler::now() - tm.timeout()) << '\n';
count ++;
- delay += senf::ClockService::in_microseconds( senf::scheduler::now() - tm.timeout());
+ delay += SENF_INT2CLOCKTYPE(senf::ClockService::in_microseconds( senf::scheduler::now() - tm.timeout()));
haveCb = true;
tm.timeout(randomDelay());
}
void jitterTest()
{
count = 0;
- delay = 0;
+ delay = senf::ClockService::clock_type(0);
// senf::scheduler::EventHook pre ("jitterTest::preCb", &preCb,
// senf::scheduler::EventHook::PRE);
// senf::scheduler::EventHook post ("jitterTest::postCb", &postCb,
senf::scheduler::process();
- std::cerr << "Average scheduling delay: " << delay/count << " microseconds\n";
+ std::cerr << "Average scheduling delay: " << SENF_CLOCKTYPEVAL(delay)/count << " microseconds\n";
}
}
: entrySetById( entrySet.template get<Id>()),
entrySetByTimeout( entrySet.template get<Timeout> ()),
timer( "TimerEventProxy " + description,
- membind(&TimerEventProxy<IdType>::timerEvent, this), 0, false)
+ membind(&TimerEventProxy<IdType>::timerEvent, this), SENF_INT2CLOCKTYPE(0), false)
{ }
template<typename IdType>
const
{
typename EntrySetById_t::const_iterator i ( entrySetById.find( id));
- return i == entrySetById.end() ? 0 : i->timeout;
+ return i == entrySetById.end() ? SENF_INT2CLOCKTYPE(0) : i->timeout;
}
timers.add( now + ClockService::milliseconds(200), 1, &handler);
BOOST_CHECK( timers.remove( 4));
BOOST_CHECK(! timers.remove( 4));
- BOOST_CHECK_EQUAL( timers.timeout(4), 0);
+ BOOST_CHECK_EQUAL( timers.timeout(4), SENF_INT2CLOCKTYPE(0));
timers.add( now + ClockService::milliseconds(700), 2, &handler);
BOOST_CHECK_EQUAL( timers.timeout(1), now + ClockService::milliseconds(200));
#include TIMERFD_H_PATH
#endif
#include "senf/Utils/IgnoreValue.hh"
+#include <senf/Utils/ClockTypeMacros.hh>
//#include "TimerSource.mpp"
#define prefix_
{
if (! timeoutEnabled_ || timeout_ != timeout) {
timeout_ = timeout;
- if (timeout_ <= 0)
- timeout_ = 1;
+ if (SENF_CLOCKTYPEVAL(timeout_) <= 0)
+ timeout_ = SENF_INT2CLOCKTYPE(1);
timeoutEnabled_ = true;
reschedule();
}
{
if (!timeoutEnabled_ || timeout_ != timeout) {
timeout_ = timeout;
- if (timeout_ <= 0)
- timeout_ = 1;
+ if (SENF_CLOCKTYPEVAL(timeout_) <= 0)
+ timeout_ = SENF_INT2CLOCKTYPE(1);
timeoutEnabled_ = true;
reschedule();
}
const
{
return pollCheck(fd(), true,
- (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)) );
+ (timeout==senf::ClockService::clock_type(-1)?-1:senf::ClockService::in_milliseconds(timeout)) );
}
prefix_ bool senf::FileBody::writeable()
const
{
return pollCheck(fd(), false,
- (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)) );
+ (timeout==senf::ClockService::clock_type(-1)?-1:senf::ClockService::in_milliseconds(timeout)) );
}
prefix_ bool senf::FileBody::oobReadable()
const
{
return pollCheck(fd(), true,
- (timeout==-1?-1:senf::ClockService::in_milliseconds(timeout)), true);
+ (timeout==senf::ClockService::clock_type(-1)?-1:senf::ClockService::in_milliseconds(timeout)), true);
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
bool readable() const; ///< Check, whether a read on the handle would not block
///< (ignoring blocking state)
- bool waitReadable(senf::ClockService::clock_type timeout = -1) const;
+ bool waitReadable(senf::ClockService::clock_type timeout = senf::ClockService::clock_type(-1)) const;
///< Wait, until read on the handle would not block (ignoring
///< blocking state)
/**< \param[in] timeout max time to wait, default is to wait
timeout. */
bool writeable() const; ///< Check, whether a write on the handle would not block
///< (ignoring blocking state)
- bool waitWriteable(senf::ClockService::clock_type timeout = -1) const;
+ bool waitWriteable(senf::ClockService::clock_type timeout = senf::ClockService::clock_type(-1)) const;
///< Wait, until a write on the handle would not block
///< (ignoring blocking state)
/**< \param[in] timeout max time to wait, default is to wait
timeout. */
bool oobReadable() const; ///< Check, whether a read of prioritized data on the handle
///< would not block (ignoring blocking state)
- bool waitOOBReadable(senf::ClockService::clock_type timeout = -1) const;
+ bool waitOOBReadable(senf::ClockService::clock_type timeout = senf::ClockService::clock_type(-1)) const;
///< Wait, until read of prioritized data on the handle does
///< not block (ignoring blocking state)
/**< \param[in] timeout max time to wait, default is to wait
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+#include <senf/Utils/ClockTypeMacros.hh>
//#include "DatagramSocketProtocol.mpp"
#define prefix_
// this may reduce the precision, but we only care about +/- 1ms, for now
struct timeval tv;
::gettimeofday( &tv, NULL);
- return tv.tv_sec * 1000000000LL + tv.tv_usec * 1000LL;
+ return SENF_INT2CLOCKTYPE(tv.tv_sec * 1000000000LL + tv.tv_usec * 1000LL);
}
// senf::Beeper
prefix_ senf::Beeper::Beeper(std::string const & device)
- : timer_( "senf::Beeper::timer", boost::bind(&Beeper::timeout, this), 0, false)
+ : timer_( "senf::Beeper::timer", boost::bind(&Beeper::timeout, this), SENF_INT2CLOCKTYPE(0), false)
{
if ((fd_ = ::open(device.c_str(), O_WRONLY)) == -1) {
SENF_THROW_SYSTEM_EXCEPTION("Could not open device for Beeper.");
--- /dev/null
+// $Id: ClockService.hh 1795 2011-07-14 08:42:24Z pba $
+//
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+//
+// 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
+//
+// 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.
+//
+// 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):
+// Philipp Batroff <philipp.batroff@fokus.fraunhofer.de>
+
+
+#ifndef HH_SENF_Utils_CLOCKTYPEMACROS
+#define HH_SENF_Utils_CLOCKTYPEMACROS_1
+
+
+#ifdef SENF_DEBUG
+#define SENF_INT2CLOCKTYPE(clock) \
+ senf::ClockService::clock_type(clock)
+
+#define SENF_CLOCKTYPEVAL(clock) \
+ clock.value()
+#endif
+
+#ifndef SENF_DEBUG
+#define SENF_INT2CLOCKTYPE(clock) \
+ (clock)
+#define SENF_CLOCKTYPEVAL(clock) \
+ (clock)
+#endif
+
+#endif // CLOCKTYPEMACROS_HH
+
+
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// comment-column: 40
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// End:
timeFormat_ = format;
if (format.empty()) {
noformat_ = true;
- timeBase_ = ClockService::now();
+ timeBase_ = SENF_CLOCKTYPEVAL(ClockService::now());
} else {
noformat_ = false;
std::locale const & loc (datestream_.getloc());
<< std::setw(9) << (delta % 1000000000ll);
}
else
- datestream_ << senf::ClockService::abstime(timestamp);
+ datestream_ << senf::ClockService::abstime(SENF_INT2CLOCKTYPE(timestamp));
datestream_ << ' ';
}
if (!tag_.empty())
prefix_ senf::log::time_type senf::log::SystemTimeSource::operator()()
const
{
- return senf::ClockService::now();
+ return SENF_CLOCKTYPEVAL(senf::ClockService::now());
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Contributor(s):
// Stefan Bund <g0dil@berlios.de>
+// Philipp Batroff <philipp.batroff@fokus.fraunhofer.de>
/** \file
\brief RestrictedInt public header */
bool boolean_test() const
{ return value_; }
+ RestrictedInt<Base, Tag> operator*(int i) const
+ { return RestrictedInt<Base, Tag>(value_ * i); }
+
+ RestrictedInt<Base, Tag> operator/(int i) const
+ { return RestrictedInt<Base, Tag>(value_ / i); }
+
+ bool operator>(int i) const
+ { return value_ > i; }
+
+ bool operator>=(int i) const
+ { return value_ >= i; }
+
+ bool operator<(int i) const
+ { return value_ < i; }
+
+ bool operator<=(int i) const
+ { return value_ <= i; }
+
+ bool operator==(int i) const
+ { return value_ == i; }
+
+ bool operator!=(int i) const
+ { return value_ != i; }
+
private:
Base value_;
};