table: simplify Measurements with C++11 features
This commit also changes TableMeasurements test suite to use UnitTestTimeFixture.
refs #2100
Change-Id: I6af9fbae435fb50d26f6ec54abc7219680c8ade8
diff --git a/daemon/fw/ncc-strategy.cpp b/daemon/fw/ncc-strategy.cpp
index 749e97c..e5aaab9 100644
--- a/daemon/fw/ncc-strategy.cpp
+++ b/daemon/fw/ncc-strategy.cpp
@@ -171,13 +171,13 @@
// going out of this strategy's namespace
return;
}
- this->getMeasurements().extendLifetime(measurementsEntry, MEASUREMENTS_LIFETIME);
+ this->getMeasurements().extendLifetime(*measurementsEntry, MEASUREMENTS_LIFETIME);
shared_ptr<MeasurementsEntryInfo> measurementsEntryInfo =
this->getMeasurementsEntryInfo(measurementsEntry);
measurementsEntryInfo->adjustPredictUp();
- measurementsEntry = this->getMeasurements().getParent(measurementsEntry);
+ measurementsEntry = this->getMeasurements().getParent(*measurementsEntry);
}
}
@@ -198,13 +198,13 @@
// going out of this strategy's namespace
return;
}
- this->getMeasurements().extendLifetime(measurementsEntry, MEASUREMENTS_LIFETIME);
+ this->getMeasurements().extendLifetime(*measurementsEntry, MEASUREMENTS_LIFETIME);
shared_ptr<MeasurementsEntryInfo> measurementsEntryInfo =
this->getMeasurementsEntryInfo(measurementsEntry);
measurementsEntryInfo->updateBestFace(inFace);
- measurementsEntry = this->getMeasurements().getParent(measurementsEntry);
+ measurementsEntry = this->getMeasurements().getParent(*measurementsEntry);
}
shared_ptr<PitEntryInfo> pitEntryInfo = pitEntry->getStrategyInfo<PitEntryInfo>();
@@ -231,7 +231,7 @@
info = make_shared<MeasurementsEntryInfo>();
entry->setStrategyInfo(info);
- shared_ptr<measurements::Entry> parentEntry = this->getMeasurements().getParent(entry);
+ shared_ptr<measurements::Entry> parentEntry = this->getMeasurements().getParent(*entry);
if (static_cast<bool>(parentEntry)) {
shared_ptr<MeasurementsEntryInfo> parentInfo = this->getMeasurementsEntryInfo(parentEntry);
BOOST_ASSERT(static_cast<bool>(parentInfo));
diff --git a/daemon/table/measurements-accessor.hpp b/daemon/table/measurements-accessor.hpp
index 2108435..872cff2 100644
--- a/daemon/table/measurements-accessor.hpp
+++ b/daemon/table/measurements-accessor.hpp
@@ -45,36 +45,37 @@
~MeasurementsAccessor();
- /// find or insert a Measurements entry for name
+ /** \brief find or insert a Measurements entry for name
+ */
shared_ptr<measurements::Entry>
get(const Name& name);
- /// find or insert a Measurements entry for fibEntry->getPrefix()
+ /** \brief find or insert a Measurements entry for fibEntry->getPrefix()
+ */
shared_ptr<measurements::Entry>
get(const fib::Entry& fibEntry);
- /// find or insert a Measurements entry for pitEntry->getName()
+ /** \brief find or insert a Measurements entry for pitEntry->getName()
+ */
shared_ptr<measurements::Entry>
get(const pit::Entry& pitEntry);
/** \brief find or insert a Measurements entry for child's parent
- *
- * If child is the root entry, returns null.
+ * \retval nullptr if child is the root entry
*/
shared_ptr<measurements::Entry>
- getParent(shared_ptr<measurements::Entry> child);
+ getParent(const measurements::Entry& child);
/** \brief extend lifetime of an entry
*
* The entry will be kept until at least now()+lifetime.
*/
void
- extendLifetime(shared_ptr<measurements::Entry> entry, const time::nanoseconds& lifetime);
+ extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime);
private:
/** \brief perform access control to Measurements entry
- *
- * \return entry if strategy has access to namespace, otherwise 0
+ * \return entry if strategy has access to namespace, otherwise nullptr
*/
shared_ptr<measurements::Entry>
filter(const shared_ptr<measurements::Entry>& entry);
@@ -104,13 +105,13 @@
}
inline shared_ptr<measurements::Entry>
-MeasurementsAccessor::getParent(shared_ptr<measurements::Entry> child)
+MeasurementsAccessor::getParent(const measurements::Entry& child)
{
return this->filter(m_measurements.getParent(child));
}
inline void
-MeasurementsAccessor::extendLifetime(shared_ptr<measurements::Entry> entry,
+MeasurementsAccessor::extendLifetime(measurements::Entry& entry,
const time::nanoseconds& lifetime)
{
m_measurements.extendLifetime(entry, lifetime);
diff --git a/daemon/table/measurements.cpp b/daemon/table/measurements.cpp
index 4943bf4..8a24306 100644
--- a/daemon/table/measurements.cpp
+++ b/daemon/table/measurements.cpp
@@ -36,30 +36,20 @@
{
}
-Measurements::~Measurements()
-{
-}
-
-static inline bool
-predicate_NameTreeEntry_hasMeasurementsEntry(const name_tree::Entry& entry)
-{
- return static_cast<bool>(entry.getMeasurementsEntry());
-}
-
shared_ptr<measurements::Entry>
-Measurements::get(shared_ptr<name_tree::Entry> nameTreeEntry)
+Measurements::get(name_tree::Entry& nte)
{
- shared_ptr<measurements::Entry> entry = nameTreeEntry->getMeasurementsEntry();
- if (static_cast<bool>(entry))
+ shared_ptr<measurements::Entry> entry = nte.getMeasurementsEntry();
+ if (entry != nullptr)
return entry;
- entry = make_shared<measurements::Entry>(nameTreeEntry->getPrefix());
- nameTreeEntry->setMeasurementsEntry(entry);
+ entry = make_shared<measurements::Entry>(nte.getPrefix());
+ nte.setMeasurementsEntry(entry);
++m_nItems;
entry->m_expiry = time::steady_clock::now() + getInitialLifetime();
entry->m_cleanup = scheduler::schedule(getInitialLifetime(),
- bind(&Measurements::cleanup, this, entry));
+ bind(&Measurements::cleanup, this, ref(*entry)));
return entry;
}
@@ -67,101 +57,86 @@
shared_ptr<measurements::Entry>
Measurements::get(const Name& name)
{
- shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.lookup(name);
- return get(nameTreeEntry);
+ shared_ptr<name_tree::Entry> nte = m_nameTree.lookup(name);
+ return this->get(*nte);
}
shared_ptr<measurements::Entry>
Measurements::get(const fib::Entry& fibEntry)
{
- shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.get(fibEntry);
-
- BOOST_ASSERT(static_cast<bool>(nameTreeEntry));
-
- return get(nameTreeEntry);
+ shared_ptr<name_tree::Entry> nte = m_nameTree.get(fibEntry);
+ return this->get(*nte);
}
shared_ptr<measurements::Entry>
Measurements::get(const pit::Entry& pitEntry)
{
- shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.get(pitEntry);
-
- BOOST_ASSERT(static_cast<bool>(nameTreeEntry));
-
- return get(nameTreeEntry);
+ shared_ptr<name_tree::Entry> nte = m_nameTree.get(pitEntry);
+ return this->get(*nte);
}
shared_ptr<measurements::Entry>
-Measurements::getParent(shared_ptr<measurements::Entry> child)
+Measurements::getParent(const measurements::Entry& child)
{
- BOOST_ASSERT(child);
-
- if (child->getName().size() == 0) {
- return shared_ptr<measurements::Entry>();
+ if (child.getName().size() == 0) { // the root entry
+ return nullptr;
}
- shared_ptr<name_tree::Entry> nameTreeChild = m_nameTree.get(*child);
- shared_ptr<name_tree::Entry> nameTreeEntry = nameTreeChild->getParent();
- if (static_cast<bool>(nameTreeEntry)) {
- return this->get(nameTreeEntry);
- }
- else {
- BOOST_ASSERT(nameTreeChild->getPrefix().size() == 0); // root entry has no parent
- return shared_ptr<measurements::Entry>();
- }
+ shared_ptr<name_tree::Entry> nteChild = m_nameTree.get(child);
+ shared_ptr<name_tree::Entry> nte = nteChild->getParent();
+ BOOST_ASSERT(nte != nullptr);
+ return this->get(*nte);
}
shared_ptr<measurements::Entry>
Measurements::findLongestPrefixMatch(const Name& name) const
{
- shared_ptr<name_tree::Entry> nameTreeEntry =
- m_nameTree.findLongestPrefixMatch(name, &predicate_NameTreeEntry_hasMeasurementsEntry);
- if (static_cast<bool>(nameTreeEntry)) {
- return nameTreeEntry->getMeasurementsEntry();
+ shared_ptr<name_tree::Entry> nte = m_nameTree.findLongestPrefixMatch(name,
+ [] (const name_tree::Entry& nte) { return nte.getMeasurementsEntry() != nullptr; });
+ if (nte != nullptr) {
+ return nte->getMeasurementsEntry();
}
- return shared_ptr<measurements::Entry>();
+ return nullptr;
}
shared_ptr<measurements::Entry>
Measurements::findExactMatch(const Name& name) const
{
- shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.lookup(name);
- if (static_cast<bool>(nameTreeEntry))
- return nameTreeEntry->getMeasurementsEntry();
- return shared_ptr<measurements::Entry>();
+ shared_ptr<name_tree::Entry> nte = m_nameTree.lookup(name);
+ if (nte != nullptr)
+ return nte->getMeasurementsEntry();
+ return nullptr;
}
void
-Measurements::extendLifetime(shared_ptr<measurements::Entry> entry,
+Measurements::extendLifetime(measurements::Entry& entry,
const time::nanoseconds& lifetime)
{
- shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.get(*entry);
- if (!static_cast<bool>(nameTreeEntry) ||
- nameTreeEntry->getMeasurementsEntry().get() != entry.get()) {
+ shared_ptr<name_tree::Entry> nte = m_nameTree.get(entry);
+ if (nte == nullptr ||
+ nte->getMeasurementsEntry().get() != &entry) {
// entry is already gone; it is a dangling reference
return;
}
time::steady_clock::TimePoint expiry = time::steady_clock::now() + lifetime;
- if (entry->m_expiry >= expiry) {
+ if (entry.m_expiry >= expiry) {
// has longer lifetime, not extending
return;
}
- scheduler::cancel(entry->m_cleanup);
- entry->m_expiry = expiry;
- entry->m_cleanup = scheduler::schedule(lifetime, bind(&Measurements::cleanup, this, entry));
+ scheduler::cancel(entry.m_cleanup);
+ entry.m_expiry = expiry;
+ entry.m_cleanup = scheduler::schedule(lifetime, bind(&Measurements::cleanup, this, ref(entry)));
}
void
-Measurements::cleanup(shared_ptr<measurements::Entry> entry)
+Measurements::cleanup(measurements::Entry& entry)
{
- BOOST_ASSERT(static_cast<bool>(entry));
-
- shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.get(*entry);
- if (static_cast<bool>(nameTreeEntry)) {
- nameTreeEntry->setMeasurementsEntry(shared_ptr<measurements::Entry>());
- m_nameTree.eraseEntryIfEmpty(nameTreeEntry);
+ shared_ptr<name_tree::Entry> nte = m_nameTree.get(entry);
+ if (nte != nullptr) {
+ nte->setMeasurementsEntry(nullptr);
+ m_nameTree.eraseEntryIfEmpty(nte);
m_nItems--;
}
}
diff --git a/daemon/table/measurements.hpp b/daemon/table/measurements.hpp
index 7478c58..71d8db5 100644
--- a/daemon/table/measurements.hpp
+++ b/daemon/table/measurements.hpp
@@ -49,54 +49,56 @@
explicit
Measurements(NameTree& nametree);
- ~Measurements();
-
- /// find or insert a Measurements entry for name
+ /** \brief find or insert a Measurements entry for name
+ */
shared_ptr<measurements::Entry>
get(const Name& name);
- /// find or insert a Measurements entry for fibEntry->getPrefix()
+ /** \brief find or insert a Measurements entry for fibEntry->getPrefix()
+ */
shared_ptr<measurements::Entry>
get(const fib::Entry& fibEntry);
- /// find or insert a Measurements entry for pitEntry->getName()
+ /** \brief find or insert a Measurements entry for pitEntry->getName()
+ */
shared_ptr<measurements::Entry>
get(const pit::Entry& pitEntry);
- /** find or insert a Measurements entry for child's parent
- *
- * If child is the root entry, returns null.
+ /** \brief find or insert a Measurements entry for child's parent
+ * \retval nullptr if child is the root entry
*/
shared_ptr<measurements::Entry>
- getParent(shared_ptr<measurements::Entry> child);
+ getParent(const measurements::Entry& child);
- /// perform a longest prefix match
+ /** \brief perform a longest prefix match
+ */
shared_ptr<measurements::Entry>
findLongestPrefixMatch(const Name& name) const;
- /// perform an exact match
+ /** \brief perform an exact match
+ */
shared_ptr<measurements::Entry>
findExactMatch(const Name& name) const;
static time::nanoseconds
getInitialLifetime();
- /** extend lifetime of an entry
+ /** \brief extend lifetime of an entry
*
* The entry will be kept until at least now()+lifetime.
*/
void
- extendLifetime(shared_ptr<measurements::Entry> entry, const time::nanoseconds& lifetime);
+ extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime);
size_t
size() const;
private:
void
- cleanup(shared_ptr<measurements::Entry> entry);
+ cleanup(measurements::Entry& entry);
shared_ptr<measurements::Entry>
- get(shared_ptr<name_tree::Entry> nameTreeEntry);
+ get(name_tree::Entry& nte);
private:
NameTree& m_nameTree;
diff --git a/tests/daemon/table/measurements-accessor.cpp b/tests/daemon/table/measurements-accessor.cpp
index cbcbe5a..8d09ca4 100644
--- a/tests/daemon/table/measurements-accessor.cpp
+++ b/tests/daemon/table/measurements-accessor.cpp
@@ -1,11 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014 Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology
+ * Copyright (c) 2014, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,7 +21,7 @@
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
#include "table/measurements-accessor.hpp"
#include "fw/strategy.hpp"
@@ -67,10 +68,8 @@
{
Forwarder forwarder;
- shared_ptr<MeasurementsAccessorTestStrategy> strategy1 =
- make_shared<MeasurementsAccessorTestStrategy>(ref(forwarder), "ndn:/strategy1");
- shared_ptr<MeasurementsAccessorTestStrategy> strategy2 =
- make_shared<MeasurementsAccessorTestStrategy>(ref(forwarder), "ndn:/strategy2");
+ auto strategy1 = make_shared<MeasurementsAccessorTestStrategy>(ref(forwarder), "ndn:/strategy1");
+ auto strategy2 = make_shared<MeasurementsAccessorTestStrategy>(ref(forwarder), "ndn:/strategy2");
Name nameRoot("ndn:/");
Name nameA ("ndn:/A");
@@ -95,7 +94,7 @@
BOOST_CHECK_EQUAL(static_cast<bool>(accessor1.get(nameAD )), false);
shared_ptr<measurements::Entry> entryRoot = forwarder.getMeasurements().get(nameRoot);
- BOOST_CHECK_NO_THROW(accessor1.getParent(entryRoot));
+ BOOST_CHECK_NO_THROW(accessor1.getParent(*entryRoot));
BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameRoot)), false);
BOOST_CHECK_EQUAL(static_cast<bool>(accessor2.get(nameA )), true);
diff --git a/tests/daemon/table/measurements.cpp b/tests/daemon/table/measurements.cpp
index 30b71c4..63254bd 100644
--- a/tests/daemon/table/measurements.cpp
+++ b/tests/daemon/table/measurements.cpp
@@ -43,23 +43,22 @@
Name nameAB("ndn:/A/B");
shared_ptr<measurements::Entry> entryAB = measurements.get(nameAB);
- BOOST_REQUIRE(static_cast<bool>(entryAB));
+ BOOST_REQUIRE(entryAB != nullptr);
BOOST_CHECK_EQUAL(entryAB->getName(), nameAB);
shared_ptr<measurements::Entry> entry0 = measurements.get(name0);
- BOOST_REQUIRE(static_cast<bool>(entry0));
+ BOOST_REQUIRE(entry0 != nullptr);
- shared_ptr<measurements::Entry> entryA = measurements.getParent(entryAB);
- BOOST_REQUIRE(static_cast<bool>(entryA));
+ shared_ptr<measurements::Entry> entryA = measurements.getParent(*entryAB);
+ BOOST_REQUIRE(entryA != nullptr);
BOOST_CHECK_EQUAL(entryA->getName(), nameA);
- shared_ptr<measurements::Entry> entry0c = measurements.getParent(entryA);
+ shared_ptr<measurements::Entry> entry0c = measurements.getParent(*entryA);
BOOST_CHECK_EQUAL(entry0, entry0c);
}
-BOOST_AUTO_TEST_CASE(Lifetime)
+BOOST_FIXTURE_TEST_CASE(Lifetime, UnitTestTimeFixture)
{
- LimitedIo limitedIo;
NameTree nameTree;
Measurements measurements(nameTree);
Name nameA("ndn:/A");
@@ -78,14 +77,14 @@
const time::nanoseconds CHECK2 = time::seconds(5);
const time::nanoseconds EXTEND_C = time::seconds(6);
const time::nanoseconds CHECK3 = time::seconds(7);
- BOOST_ASSERT(EXTEND_A < CHECK1 &&
- CHECK1 < Measurements::getInitialLifetime() &&
- Measurements::getInitialLifetime() < CHECK2 &&
- CHECK2 < EXTEND_C &&
- EXTEND_C < CHECK3);
+ BOOST_ASSERT(EXTEND_A < CHECK1);
+ BOOST_ASSERT(CHECK1 < Measurements::getInitialLifetime());
+ BOOST_ASSERT(Measurements::getInitialLifetime() < CHECK2);
+ BOOST_ASSERT(CHECK2 < EXTEND_C);
+ BOOST_ASSERT(EXTEND_C < CHECK3);
- measurements.extendLifetime(entryA, EXTEND_A);
- measurements.extendLifetime(entryC, EXTEND_C);
+ measurements.extendLifetime(*entryA, EXTEND_A);
+ measurements.extendLifetime(*entryC, EXTEND_C);
// remaining lifetime:
// A = initial lifetime, because it's extended by less duration
// B = initial lifetime
@@ -94,39 +93,33 @@
entryB.reset();
entryC.reset();
- BOOST_CHECK_EQUAL(limitedIo.run(LimitedIo::UNLIMITED_OPS, CHECK1), LimitedIo::EXCEED_TIME);
- BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameA)), true);
- BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameB)), true);
- BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameC)), true);
+ this->advanceClocks(time::milliseconds(100), CHECK1);
+ BOOST_CHECK(measurements.findExactMatch(nameA) != nullptr);
+ BOOST_CHECK(measurements.findExactMatch(nameB) != nullptr);
+ BOOST_CHECK(measurements.findExactMatch(nameC) != nullptr);
BOOST_CHECK_EQUAL(measurements.size(), 3);
- BOOST_CHECK_EQUAL(limitedIo.run(LimitedIo::UNLIMITED_OPS, CHECK2 - CHECK1),
- LimitedIo::EXCEED_TIME);
- BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameA)), false);
- BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameB)), false);
- BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameC)), true);
+ this->advanceClocks(time::milliseconds(100), CHECK2 - CHECK1);
+ BOOST_CHECK(measurements.findExactMatch(nameA) == nullptr);
+ BOOST_CHECK(measurements.findExactMatch(nameB) == nullptr);
+ BOOST_CHECK(measurements.findExactMatch(nameC) != nullptr);
BOOST_CHECK_EQUAL(measurements.size(), 1);
- BOOST_CHECK_EQUAL(limitedIo.run(LimitedIo::UNLIMITED_OPS, CHECK3 - CHECK2),
- LimitedIo::EXCEED_TIME);
- BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameA)), false);
- BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameB)), false);
- BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameC)), false);
+ this->advanceClocks(time::milliseconds(100), CHECK3 - CHECK2);
+ BOOST_CHECK(measurements.findExactMatch(nameA) == nullptr);
+ BOOST_CHECK(measurements.findExactMatch(nameB) == nullptr);
+ BOOST_CHECK(measurements.findExactMatch(nameC) == nullptr);
BOOST_CHECK_EQUAL(measurements.size(), 0);
}
-BOOST_AUTO_TEST_CASE(EraseNameTreeEntry)
+BOOST_FIXTURE_TEST_CASE(EraseNameTreeEntry, UnitTestTimeFixture)
{
- LimitedIo limitedIo;
NameTree nameTree;
Measurements measurements(nameTree);
size_t nNameTreeEntriesBefore = nameTree.size();
shared_ptr<measurements::Entry> entry = measurements.get("/A");
- BOOST_CHECK_EQUAL(
- limitedIo.run(LimitedIo::UNLIMITED_OPS,
- Measurements::getInitialLifetime() + time::milliseconds(10)),
- LimitedIo::EXCEED_TIME);
+ this->advanceClocks(Measurements::getInitialLifetime() + time::milliseconds(10));
BOOST_CHECK_EQUAL(measurements.size(), 0);
BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
}
diff --git a/tests/test-common.hpp b/tests/test-common.hpp
index d122189..e3bc0b5 100644
--- a/tests/test-common.hpp
+++ b/tests/test-common.hpp
@@ -64,7 +64,7 @@
*/
class UnitTestTimeFixture : public BaseFixture
{
-public:
+protected:
UnitTestTimeFixture()
: steadyClock(make_shared<time::UnitTestSteadyClock>())
, systemClock(make_shared<time::UnitTestSystemClock>())
@@ -88,9 +88,38 @@
void
advanceClocks(const time::nanoseconds& tick, size_t nTicks = 1)
{
- for (size_t i = 0; i < nTicks; ++i) {
- steadyClock->advance(tick);
- systemClock->advance(tick);
+ BOOST_ASSERT(nTicks >= 0);
+
+ this->advanceClocks(tick, tick * nTicks);
+ }
+
+ /** \brief advance steady and system clocks
+ *
+ * Clocks are advanced in increments of \p tick for \p total time.
+ * The last increment might be shorter than \p tick.
+ * After each tick, global io_service is polled to process pending I/O events.
+ *
+ * Exceptions thrown during I/O events are propagated to the caller.
+ * Clock advancing would stop in case of an exception.
+ */
+ void
+ advanceClocks(const time::nanoseconds& tick, const time::nanoseconds& total)
+ {
+ BOOST_ASSERT(tick > time::nanoseconds::zero());
+ BOOST_ASSERT(total >= time::nanoseconds::zero());
+
+ time::nanoseconds remaining = total;
+ while (remaining > time::nanoseconds::zero()) {
+ if (remaining >= tick) {
+ steadyClock->advance(tick);
+ systemClock->advance(tick);
+ remaining -= tick;
+ }
+ else {
+ steadyClock->advance(remaining);
+ systemClock->advance(remaining);
+ remaining = time::nanoseconds::zero();
+ }
if (g_io.stopped())
g_io.reset();