Project

General

Profile

Actions

Task #1152

closed

time structs

Added by Junxiao Shi almost 11 years ago. Updated almost 11 years ago.

Status:
Closed
Priority:
High
Category:
-
Target version:
-
Start date:
Due date:
% Done:

100%

Estimated time:
6.00 h

Description

Define time::Duration and time::Point types; implement time::now.

time::Duration should be convertible to and from nanoseconds.

time::Point represents a time point in monotonic clock, and doesn't need to relate with UTC time.

These types should support addition, subtraction, and comparison operators.

  • Point + Duration => Point
  • Point - Point => Duration
  • Duration + Duration => Duration
  • Duration - Duration => Duration
  • Comparisons should take two operands of same type

time::now() uses monotonic clock on every platform that supports it, otherwise fallback to wall clock.


Related issues 3 (0 open3 closed)

Related to NFD - Task #1119: Implement simple event schedulerClosedAlex Afanasyev01/24/201401/24/2014

Actions
Blocks ndn-cxx - Task #1274: Optimize SchedulerAbandonedHang Zhang

Actions
Follows NFD - Task #1148: mock implementation of time structsClosedJunxiao Shi01/24/2014

Actions
Actions #1

Updated by Junxiao Shi almost 11 years ago

  • Due date deleted (01/25/2014)
  • Start date deleted (01/25/2014)
Actions #2

Updated by Junxiao Shi almost 11 years ago

  • Description updated (diff)
  • Category set to Core
Actions #3

Updated by Junxiao Shi almost 11 years ago

  • Assignee set to Jerald Paul Abraham
Actions #4

Updated by Junxiao Shi almost 11 years ago

  • Description updated (diff)
Actions #5

Updated by Junxiao Shi almost 11 years ago

This task should be moved to ndn-cpp-dev, because Task #1290 stage 1 imports time structs and Scheduler from the library.

Actions #6

Updated by Alex Afanasyev almost 11 years ago

  • Project changed from NFD to ndn-cxx
  • Category deleted (Core)
  • Target version deleted (v0.1)
Actions #7

Updated by Jerald Paul Abraham almost 11 years ago

  • % Done changed from 0 to 30

As there is specific mention of a nanosecond time granularity requirement for ndn::Point and ndn::Duration, I am using the considering two options which are not presently employed in the ndn-cpp-dev library:

  1. std::chrono::high_resolution_clock (C++ v11 Feature) This offers the smallest available tick in the implementation but is not necessarily platform invariant
  2. Boost.Chrono (Boost Third Party Library) The advantage is boost takes care of the platform invariant aspect and also has library implemented for most required arithmetic operations

An underlying hardware inability will cause the usage of the next available resolution of time (although it would be externalized as nanoseconds).

Also not sure if we really need nanosecond resolution. Even for the timing wheel implementation, if we are to offer millisecond unit timers, then microsecond granularity is good enough. In that case boost::posix_time would be enough as it has routines for upto microsecond resolution and this would be more aligned to what ndn-cpp-dev uses currently.

Actions #8

Updated by Jerald Paul Abraham almost 11 years ago

  • Status changed from New to In Progress
Actions #9

Updated by Junxiao Shi almost 11 years ago

ndn-cpp-dev is targeting C++03, which does not have std::chrono.

I’m not sure the targeting Boost version. If it’s above 1.47, this task is done in 0.2 hours:

#ifdef BOOST_HAS_CLOCK_STEADY
#define CLOCK boost::chrono::steady_clock
#else
#define CLOCK boost::chrono::system_clock
#endif
typedef CLOCK::duration Duration;
typedef CLOCK::time_point Point;
inline Point now() { return CLOCK::now(); }

If Boost.Chrono isn’t available, you have to deal with everything with platform-dependent APIs, and this would be a 6 hour task.

Actions #10

Updated by Jerald Paul Abraham almost 11 years ago

  • Status changed from In Progress to Code review
  • % Done changed from 30 to 100

The ndn-cpp-dev Library already has most of this implemented.

All requested requirements of the task have been ensured to be present.

I added the following:

1.New Typedefs:

Microseconds
MicrosecondsSince1970
Nanoseconds
NanosecondsSince1970

2.Add the following operator support for ndn::time::Point and ndn::time::Duration:

==
!=
>=
<=
>
<
<<

3.Added unit tests for all of the above.

Actions #11

Updated by Alex Afanasyev almost 11 years ago

  • Assignee changed from Jerald Paul Abraham to Alex Afanasyev
Actions #12

Updated by Junxiao Shi almost 11 years ago

  • Priority changed from Normal to High

Bump priority because two other tasks are blocked on this.

Actions #13

Updated by Alex Afanasyev almost 11 years ago

  • Status changed from Code review to Closed
Actions

Also available in: Atom PDF