diff --git a/include/tscore/ink_defs.h b/include/tscore/ink_defs.h index 1b81e799e09..35141368371 100644 --- a/include/tscore/ink_defs.h +++ b/include/tscore/ink_defs.h @@ -104,10 +104,6 @@ countof(const T (&)[N]) #include #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 +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 35e49a2e497..b5638558c0a 100644 --- a/iocore/dns/DNSConnection.cc +++ b/iocore/dns/DNSConnection.cc @@ -27,6 +27,7 @@ Commonality across all platforms -- move out as required. **************************************************************************/ +#include #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 4f5395ce6f8..df0729dcad6 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 eb13f7993ec..5657dc5bf5a 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 89c1c9646f5..fe204cd6181 100644 --- a/iocore/net/UnixNetAccept.cc +++ b/iocore/net/UnixNetAccept.cc @@ -22,14 +22,10 @@ */ #include +#include #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;