trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wka...@apache.org
Subject [trafficserver] branch master updated: Change ROUNDUP from function-like macro to function template. (#7614)
Date Mon, 29 Mar 2021 21:56:29 GMT
This is an automated email from the ASF dual-hosted git repository.

wkaras pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new c08e78c  Change ROUNDUP from function-like macro to function template. (#7614)
c08e78c is described below

commit c08e78cca1f4ca53ebca022218f791ae8682fe0f
Author: Walt Karas <wkaras@verizonmedia.com>
AuthorDate: Mon Mar 29 16:56:16 2021 -0500

    Change ROUNDUP from function-like macro to function template. (#7614)
    
    Making it safe for argument expressions with side effects.
---
 include/tscore/ink_defs.h    | 19 +++++++++++++++----
 iocore/dns/DNSConnection.cc  |  3 +--
 iocore/net/Connection.cc     |  3 +--
 iocore/net/UnixConnection.cc |  3 +--
 iocore/net/UnixNetAccept.cc  |  6 +-----
 5 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/include/tscore/ink_defs.h b/include/tscore/ink_defs.h
index 1b81e79..3514136 100644
--- a/include/tscore/ink_defs.h
+++ b/include/tscore/ink_defs.h
@@ -104,10 +104,6 @@ countof(const T (&)[N])
 #include <hwloc.h>
 #endif
 
-#ifndef ROUNDUP
-#define ROUNDUP(x, y) ((((x) + ((y)-1)) / (y)) * (y))
-#endif
-
 #if defined(MAP_NORESERVE)
 #define MAP_SHARED_MAP_NORESERVE (MAP_SHARED | MAP_NORESERVE)
 #else
@@ -126,6 +122,21 @@ int ink_sys_name_release(char *name, int namelen, char *release, int
releaselen)
 int ink_number_of_processors();
 int ink_login_name_max();
 
+#ifdef __cplusplus
+// Round up a value to be a multiple of m if necessary.
+//
+template <typename ArithmeticV, typename ArithmeticM>
+constexpr ArithmeticV
+ROUNDUP(ArithmeticV value, ArithmeticM m)
+{
+  ArithmeticV remainder = value % m;
+  if (remainder) {
+    value += m - remainder;
+  }
+  return value;
+}
+#endif
+
 #if TS_USE_HWLOC
 // Get the hardware topology
 hwloc_topology_t ink_get_topology();
diff --git a/iocore/dns/DNSConnection.cc b/iocore/dns/DNSConnection.cc
index 35e49a2..b563855 100644
--- a/iocore/dns/DNSConnection.cc
+++ b/iocore/dns/DNSConnection.cc
@@ -27,6 +27,7 @@
   Commonality across all platforms -- move out as required.
 
 **************************************************************************/
+#include <tscore/ink_defs.h>
 #include "P_DNS.h"
 #include "P_DNSConnection.h"
 #include "P_DNSProcessor.h"
@@ -40,8 +41,6 @@
 #define FIRST_RANDOM_PORT (16000)
 #define LAST_RANDOM_PORT (60000)
 
-#define ROUNDUP(x, y) ((((x) + ((y)-1)) / (y)) * (y))
-
 DNSConnection::Options const DNSConnection::DEFAULT_OPTIONS;
 
 //
diff --git a/iocore/net/Connection.cc b/iocore/net/Connection.cc
index 4f5395c..df0729d 100644
--- a/iocore/net/Connection.cc
+++ b/iocore/net/Connection.cc
@@ -28,6 +28,7 @@
 
 **************************************************************************/
 #include "tscore/ink_platform.h"
+#include "tscore/ink_defs.h"
 
 #include "P_Net.h"
 
@@ -37,8 +38,6 @@
 #define FIRST_RANDOM_PORT 16000
 #define LAST_RANDOM_PORT 32000
 
-#define ROUNDUP(x, y) ((((x) + ((y)-1)) / (y)) * (y))
-
 int
 get_listen_backlog()
 {
diff --git a/iocore/net/UnixConnection.cc b/iocore/net/UnixConnection.cc
index eb13f79..5657dc5 100644
--- a/iocore/net/UnixConnection.cc
+++ b/iocore/net/UnixConnection.cc
@@ -26,6 +26,7 @@
 
 **************************************************************************/
 #include "P_Net.h"
+#include "tscore/ink_defs.h"
 
 #define SET_NO_LINGER
 // set in the OS
@@ -34,8 +35,6 @@
 #define FIRST_RANDOM_PORT 16000
 #define LAST_RANDOM_PORT 32000
 
-#define ROUNDUP(x, y) ((((x) + ((y)-1)) / (y)) * (y))
-
 #if TS_USE_TPROXY
 #if !defined(IP_TRANSPARENT)
 unsigned int const IP_TRANSPARENT = 19;
diff --git a/iocore/net/UnixNetAccept.cc b/iocore/net/UnixNetAccept.cc
index 89c1c96..fe204cd 100644
--- a/iocore/net/UnixNetAccept.cc
+++ b/iocore/net/UnixNetAccept.cc
@@ -22,14 +22,10 @@
  */
 
 #include <tscore/TSSystemState.h>
+#include <tscore/ink_defs.h>
 
 #include "P_Net.h"
 
-#ifdef ROUNDUP
-#undef ROUNDUP
-#endif
-#define ROUNDUP(x, y) ((((x) + ((y)-1)) / (y)) * (y))
-
 using NetAcceptHandler = int (NetAccept::*)(int, void *);
 int accept_till_done   = 1;
 

Mime
View raw message