]> git.tdb.fi Git - libs/core.git/blobdiff - source/time/timer.cpp
Use nullptr instead of 0 for pointers
[libs/core.git] / source / time / timer.cpp
index e0af57cc78fcc41363632e169e33a8219653e9f1..04c3074494e921d39f3edb54e53e378c8623e826 100644 (file)
@@ -1,4 +1,4 @@
-#include <algorithm>
+#include <msp/core/algorithm.h>
 #include <msp/core/raii.h>
 #include "timer.h"
 #include "utils.h"
@@ -9,14 +9,13 @@ namespace Msp {
 namespace Time {
 
 Timer::Timer():
-       sem(1),
-       blocking(false)
+       sem(1)
 { }
 
 Timer::~Timer()
 {
-       for(vector<SlotProxy>::iterator i=slots.begin(); i!=slots.end(); ++i)
-               delete i->slot;
+       for(const SlotProxy &s: slots)
+               delete s.slot;
 }
 
 Timer::Slot &Timer::add(const TimeDelta &td)
@@ -44,22 +43,13 @@ Timer::Slot &Timer::add(const TimeStamp &ts)
 void Timer::cancel(Slot &slot)
 {
        MutexLock l(mutex);
-       for(vector<SlotProxy>::iterator i=slots.begin(); i!=slots.end(); ++i)
-               if(i->slot==&slot)
-               {
-                       delete i->slot;
-                       slots.erase(i);
-                       make_heap(slots.begin(), slots.end());
-                       return;
-               }
-}
-
-void Timer::tick(bool block)
-{
-       if(block)
-               tick();
-       else
-               tick(zero);
+       auto i = find_member(slots, &slot, &SlotProxy::slot);
+       if(i!=slots.end())
+       {
+               delete i->slot;
+               slots.erase(i);
+               make_heap(slots.begin(), slots.end());
+       }
 }
 
 void Timer::tick()
@@ -81,7 +71,7 @@ void Timer::do_tick(const TimeDelta &timeout)
        if(timeout>=zero)
                deadline = now()+timeout;
 
-       Slot *next = 0;
+       Slot *next = nullptr;
        {
                MutexLock l(mutex);
                while(1)