]> granicus.if.org Git - pdns/commitdiff
make the 'pimp' multithreading communicator typesafe
authorBert Hubert <bert.hubert@netherlabs.nl>
Mon, 4 Jan 2010 21:30:07 +0000 (21:30 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Mon, 4 Jan 2010 21:30:07 +0000 (21:30 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1489 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/pdns_recursor.cc
pdns/rec_channel_rec.cc
pdns/syncres.hh

index b106cca9ac3691e16f84507256f1779499677a59..6f2345ca557e9543c2dce827043c03e494437476 100644 (file)
@@ -1134,7 +1134,12 @@ void handlePipeRequest(int fd, FDMultiplexer::funcparam_t& var)
   delete func;
 }
 
-template<class T> T broadcastAccFunction(const pipefunc_t& func, bool skipSelf)
+template<class T> void *voider(const boost::function<T*()>& func)
+{
+  return func();
+}
+
+template<class T> T broadcastAccFunction(const boost::function<T*()>& func, bool skipSelf)
 {
   unsigned int n = 0;
   T ret=T();
@@ -1152,7 +1157,7 @@ template<class T> T broadcastAccFunction(const pipefunc_t& func, bool skipSelf)
       continue;
     }
       
-    pipefunc_t *funcptr = new pipefunc_t(func);
+    pipefunc_t *funcptr = new pipefunc_t(boost::bind(voider<T>, func));
     if(write(tps.writeToThread, &funcptr, sizeof(funcptr)) != sizeof(funcptr))
       unixDie("write to thread pipe returned wrong size or error");
     
@@ -1169,8 +1174,8 @@ template<class T> T broadcastAccFunction(const pipefunc_t& func, bool skipSelf)
   return ret;
 }
 
-template string broadcastAccFunction(const pipefunc_t& fun, bool skipSelf); // explicit instantiation
-template uint64_t broadcastAccFunction(const pipefunc_t& fun, bool skipSelf); // explicit instantiation
+template string broadcastAccFunction(const boost::function<string*()>& fun, bool skipSelf); // explicit instantiation
+template uint64_t broadcastAccFunction(const boost::function<uint64_t*()>& fun, bool skipSelf); // explicit instantiation
 
 void handleRCC(int fd, FDMultiplexer::funcparam_t& var)
 {
index 96b6a1cce1094587906501ec72fe8be39867d030..a391f275e6a9fa1e6b08818f3cd1a753680127ae 100644 (file)
@@ -128,13 +128,13 @@ string doDumpEDNSStatus(T begin, T end)
   return "done\n";
 }
 
-static void* pleaseWipeCache(const std::string& canon)
+static uint64_t* pleaseWipeCache(const std::string& canon)
 {
   return new uint64_t(t_RC->doWipeCache(canon));
 }
 
 
-static void* pleaseWipeAndCountNegCache(const std::string& canon)
+static uint64_t* pleaseWipeAndCountNegCache(const std::string& canon)
 {
   uint64_t res = SyncRes::t_sstorage->negcache.count(tie(canon));
   pair<SyncRes::negcache_t::iterator, SyncRes::negcache_t::iterator> range=SyncRes::t_sstorage->negcache.equal_range(tie(canon));
@@ -190,7 +190,7 @@ static uint64_t calculateUptime()
   return time(0) - g_stats.startupTime;
 }
 
-static void* pleaseGetCurrentQueries()
+static string* pleaseGetCurrentQueries()
 {
   ostringstream ostr;
 
@@ -217,7 +217,7 @@ static string doCurrentQueries()
   return broadcastAccFunction<string>(pleaseGetCurrentQueries);
 }
 
-void* pleaseGetThrottleSize()
+uint64_t* pleaseGetThrottleSize()
 {
   return new uint64_t(SyncRes::t_sstorage->throttle.size());
 }
@@ -227,7 +227,7 @@ static uint64_t getThrottleSize()
   return broadcastAccFunction<uint64_t>(pleaseGetThrottleSize);
 }
 
-void* pleaseGetNegCacheSize()
+uint64_t* pleaseGetNegCacheSize()
 {
   uint64_t tmp=SyncRes::t_sstorage->negcache.size();
   return new uint64_t(tmp);
@@ -238,7 +238,7 @@ uint64_t getNegCacheSize()
   return broadcastAccFunction<uint64_t>(pleaseGetNegCacheSize);
 }
 
-void* pleaseGetNsSpeedsSize()
+uint64_t* pleaseGetNsSpeedsSize()
 {
   return new uint64_t(SyncRes::t_sstorage->nsSpeeds.size());
 }
@@ -248,7 +248,7 @@ uint64_t getNsSpeedsSize()
   return broadcastAccFunction<uint64_t>(pleaseGetNsSpeedsSize);
 }
 
-void* pleaseGetConcurrentQueries()
+uint64_t* pleaseGetConcurrentQueries()
 {
   return new uint64_t(MT->numProcesses()); 
 }
@@ -258,7 +258,7 @@ static uint64_t getConcurrentQueries()
   return broadcastAccFunction<uint64_t>(pleaseGetConcurrentQueries);
 }
 
-void* pleaseGetCacheSize()
+uint64_t* pleaseGetCacheSize()
 {
   return new uint64_t(t_RC->size());
 }
@@ -268,7 +268,7 @@ uint64_t doGetCacheSize()
   return broadcastAccFunction<uint64_t>(pleaseGetCacheSize);
 }
 
-void* pleaseGetCacheHits()
+uint64_t* pleaseGetCacheHits()
 {
   return new uint64_t(t_RC->cacheHits);
 }
@@ -278,7 +278,7 @@ uint64_t doGetCacheHits()
   return broadcastAccFunction<uint64_t>(pleaseGetCacheHits);
 }
 
-void* pleaseGetCacheMisses()
+uint64_t* pleaseGetCacheMisses()
 {
   return new uint64_t(t_RC->cacheMisses);
 }
@@ -418,7 +418,7 @@ string doTopRemotes()
   return ret.str();
 }
 
-static void* nopFunction()
+static string* nopFunction()
 {
   return new string("pong\n");
 }
index d1fe7b0c5f8c6ef1b4fccfdbeb3cbc905efe4116..54aa1e30035ca8ad17cdf0df3e038f319714ae03 100644 (file)
@@ -516,15 +516,15 @@ typedef boost::function<void*(void)> pipefunc_t;
 void broadcastFunction(const pipefunc_t& func, bool skipSelf = false);
 
 
-template<class T> T broadcastAccFunction(const pipefunc_t& func, bool skipSelf=false);
+template<class T> T broadcastAccFunction(const boost::function<T*()>& func, bool skipSelf=false);
 
 SyncRes::domainmap_t* parseAuthAndForwards();
 
-void* pleaseGetNsSpeedsSize();
-void* pleaseGetCacheSize();
-void* pleaseGetNegCacheSize();
-void* pleaseGetCacheHits();
-void* pleaseGetCacheMisses();
-void* pleaseGetConcurrentQueries();
-void* pleaseGetThrottleSize();
+uint64_t* pleaseGetNsSpeedsSize();
+uint64_t* pleaseGetCacheSize();
+uint64_t* pleaseGetNegCacheSize();
+uint64_t* pleaseGetCacheHits();
+uint64_t* pleaseGetCacheMisses();
+uint64_t* pleaseGetConcurrentQueries();
+uint64_t* pleaseGetThrottleSize();
 #endif