]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Better const-ness when dealing with timestamps
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 22 Sep 2020 09:58:09 +0000 (11:58 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 22 Sep 2020 09:58:09 +0000 (11:58 +0200)
pdns/lwres.hh
pdns/misc.hh
pdns/mtasker.cc
pdns/mtasker.hh
pdns/pdns_recursor.cc

index 36a6d714fcd4d7c647c8467f5a9f0bac81897203..2e813bd8cb69b4d20fb11ad111a4214c10d485d2 100644 (file)
@@ -47,7 +47,7 @@
 int asendto(const char *data, size_t len, int flags, const ComboAddress& ip, uint16_t id,
             const DNSName& domain, uint16_t qtype,  int* fd);
 int arecvfrom(std::string& packet, int flags, const ComboAddress& ip, size_t *d_len, uint16_t id,
-              const DNSName& domain, uint16_t qtype, int fd, struct timeval* now);
+              const DNSName& domain, uint16_t qtype, int fd, const struct timeval* now);
 
 class LWResException : public PDNSException
 {
index 314764d0c3c5cb775cee30b6e7dab3230600ee30..488441912bac09c6c06dc52ee3d171d3a9ac11aa 100644 (file)
@@ -196,8 +196,12 @@ public:
   DTime & operator=(const DTime &dt) = default;
   time_t time();
   inline void set();  //!< Reset the timer
-  inline int udiff(); //!< Return the number of microseconds since the timer was last set.
-  inline int udiffNoReset(); //!< Return the number of microseconds since the timer was last set.
+  inline int udiff(bool reset = true); //!< Return the number of microseconds since the timer was last set.
+
+  int udiffNoReset() //!< Return the number of microseconds since the timer was last set.
+  {
+    return udiff(false);
+  }
   void setTimeval(const struct timeval& tv)
   {
     d_set=tv;
@@ -215,19 +219,17 @@ inline void DTime::set()
   gettimeofday(&d_set,0);
 }
 
-inline int DTime::udiff()
-{
-  int res=udiffNoReset();
-  gettimeofday(&d_set,0);
-  return res;
-}
-
-inline int DTime::udiffNoReset()
+inline int DTime::udiff(bool reset)
 {
   struct timeval now;
-
   gettimeofday(&now,0);
+
   int ret=1000000*(now.tv_sec-d_set.tv_sec)+(now.tv_usec-d_set.tv_usec);
+
+  if (reset) {
+    d_set = now;
+  }
+
   return ret;
 }
 
index 2d01f12f272d8088eecfdadfdbf484ab72cd943b..7afc7d4012b2d7f01aeda2dc432061766624bcf1 100644 (file)
@@ -170,7 +170,7 @@ int main()
     \return returns -1 in case of error, 0 in case of timeout, 1 in case of an answer 
 */
 
-template<class EventKey, class EventVal>int MTasker<EventKey,EventVal>::waitEvent(EventKey &key, EventVal *val, unsigned int timeoutMsec, struct timeval* now)
+template<class EventKey, class EventVal>int MTasker<EventKey,EventVal>::waitEvent(EventKey &key, EventVal *val, unsigned int timeoutMsec, const struct timeval* now)
 {
   if(d_waiters.count(key)) { // there was already an exact same waiter
     return -1;
@@ -301,7 +301,7 @@ template<class Key, class Val>void MTasker<Key,Val>::makeThread(tfunc_t *start,
     \return Returns if there is more work scheduled and recalling schedule now would be useful
       
 */
-template<class Key, class Val>bool MTasker<Key,Val>::schedule(struct timeval*  now)
+template<class Key, class Val>bool MTasker<Key,Val>::schedule(const struct timeval*  now)
 {
   if(!d_runQueue.empty()) {
     d_tid=d_runQueue.front();
index bff0eca0ff1c5f77e88b1e4a2a8f1a0cf1214c67..ed6b02d0c59ca23b3c763a58a97c8ed8bfabb48f 100644 (file)
@@ -119,12 +119,12 @@ public:
   }
 
   typedef void tfunc_t(void *); //!< type of the pointer that starts a thread 
-  int waitEvent(EventKey &key, EventVal *val=0, unsigned int timeoutMsec=0, struct timeval* now=0);
+  int waitEvent(EventKey &key, EventVal *val=nullptr, unsigned int timeoutMsec=0, const struct timeval* now=nullptr);
   void yield();
-  int sendEvent(const EventKey& key, const EventVal* val=0);
+  int sendEvent(const EventKey& key, const EventVal* val=nullptr);
   void getEvents(std::vector<EventKey>& events);
   void makeThread(tfunc_t *start, void* val);
-  bool schedule(struct timeval* now=0);
+  bool schedule(const struct timeval* now=nullptr);
   bool noProcesses() const;
   unsigned int numProcesses() const;
   int getTid() const;
index 2cd4a86dd68e40e5ffd392cb7c418e236a3cf61b..8f1c0017470175d4a09fa67f2b1583ff5e4ed4f8 100644 (file)
@@ -676,7 +676,7 @@ int asendto(const char *data, size_t len, int flags,
 
 // -1 is error, 0 is timeout, 1 is success
 int arecvfrom(std::string& packet, int flags, const ComboAddress& fromaddr, size_t *d_len,
-              uint16_t id, const DNSName& domain, uint16_t qtype, int fd, struct timeval* now)
+              uint16_t id, const DNSName& domain, uint16_t qtype, int fd, const struct timeval* now)
 {
   static optional<unsigned int> nearMissLimit;
   if(!nearMissLimit)