Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions include/tscore/ink_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only provides it when it's included from a C++ file. It's a little odd to remove the C version when converting to C++. This version is unambiguously better, though, since it will refuse to compile with non-integer types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ink_defs.h is included by .c files, but they don't use ROUNDUP.

#endif

#if TS_USE_HWLOC
// Get the hardware topology
hwloc_topology_t ink_get_topology();
Expand Down
3 changes: 1 addition & 2 deletions iocore/dns/DNSConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;

//
Expand Down
3 changes: 1 addition & 2 deletions iocore/net/Connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

**************************************************************************/
#include "tscore/ink_platform.h"
#include "tscore/ink_defs.h"

#include "P_Net.h"

Expand All @@ -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()
{
Expand Down
3 changes: 1 addition & 2 deletions iocore/net/UnixConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

**************************************************************************/
#include "P_Net.h"
#include "tscore/ink_defs.h"

#define SET_NO_LINGER
// set in the OS
Expand All @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions iocore/net/UnixNetAccept.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down