Commit 298cdd1e authored by Davis King's avatar Davis King

Fixed a bug in the timer_kernel_2 object. In certain rare cases it would stop

calling the action function and essentially shut down without being told to do
so.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403670
parent c3932281
...@@ -25,12 +25,13 @@ namespace ...@@ -25,12 +25,13 @@ namespace
public: public:
mutex m; mutex m;
int count; int count;
dlib::uint64 timestamp;
dlib::timestamper ts;
timer_test_helper():count(0){} timer_test_helper():count(0), timestamp(0){}
void add() void add()
{ {
m.lock(); m.lock();
print_spinner();
++count; ++count;
m.unlock(); m.unlock();
} }
...@@ -40,8 +41,48 @@ namespace ...@@ -40,8 +41,48 @@ namespace
dlib::sleep(1000); dlib::sleep(1000);
add(); add();
} }
void set_timestamp()
{
m.lock();
timestamp = ts.get_timestamp();
m.unlock();
}
}; };
template <
typename timer_t
>
void timer_test2 (
)
/*!
requires
- timer_t is an implementation of timer/timer_kernel_aseqract.h is instantiated
timer_test_helper
ensures
- runs tests on timer_t for compliance with the specs
!*/
{
for (int j = 0; j < 4; ++j)
{
print_spinner();
timer_test_helper h;
timer_t t1(h,&timer_test_helper::set_timestamp);
t1.set_delay_time(0);
t1.start();
dlib::sleep(3000);
t1.stop();
dlib::uint64 cur_time = h.ts.get_timestamp();
// make sure the action function has been called recently
DLIB_TEST_MSG((cur_time-h.timestamp)/1000 < 10, (cur_time-h.timestamp)/1000);
}
}
template < template <
typename timer_t typename timer_t
> >
...@@ -272,8 +313,10 @@ namespace ...@@ -272,8 +313,10 @@ namespace
{ {
dlog << LINFO << "testing kernel_1a"; dlog << LINFO << "testing kernel_1a";
timer_test<timer<timer_test_helper>::kernel_1a> (); timer_test<timer<timer_test_helper>::kernel_1a> ();
timer_test2<timer<timer_test_helper>::kernel_1a> ();
dlog << LINFO << "testing kernel_2a"; dlog << LINFO << "testing kernel_2a";
timer_test<timer<timer_test_helper>::kernel_2a> (); timer_test<timer<timer_test_helper>::kernel_2a> ();
timer_test2<timer<timer_test_helper>::kernel_2a> ();
} }
} a; } a;
......
...@@ -163,7 +163,7 @@ namespace dlib ...@@ -163,7 +163,7 @@ namespace dlib
// if this timer is still "running" then start its action function // if this timer is still "running" then start its action function
if (r->running) if (r->running)
{ {
r->start(); r->restart();
} }
} }
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment