Revert "a useful change (#27381)" (#27411)

This reverts commit 11eb70bbed.
pull/27412/head
Craig Tiller 3 years ago committed by GitHub
parent 11eb70bbed
commit 5db17f7350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      BUILD
  2. 63
      CMakeLists.txt
  3. 19
      build_autogenerated.yaml
  4. 4
      src/core/ext/filters/client_channel/client_channel.cc
  5. 2
      src/core/ext/filters/client_channel/client_channel_factory.cc
  6. 2
      src/core/ext/filters/client_channel/config_selector.cc
  7. 6
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  8. 2
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc
  9. 6
      src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc
  10. 2
      src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc
  11. 1
      src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc
  12. 4
      src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc
  13. 2
      src/core/ext/filters/client_channel/server_address.h
  14. 2
      src/core/ext/filters/client_channel/subchannel_pool_interface.cc
  15. 2
      src/core/ext/filters/client_idle/client_idle_filter.cc
  16. 12
      src/core/ext/filters/fault_injection/fault_injection_filter.cc
  17. 10
      src/core/ext/filters/http/message_compress/message_compress_filter.cc
  18. 9
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  19. 35
      src/core/ext/transport/chttp2/transport/flow_control.cc
  20. 8
      src/core/ext/transport/chttp2/transport/flow_control.h
  21. 3
      src/core/ext/transport/chttp2/transport/frame_ping.cc
  22. 4
      src/core/ext/transport/chttp2/transport/frame_settings.cc
  23. 32
      src/core/ext/transport/chttp2/transport/writing.cc
  24. 4
      src/core/ext/transport/inproc/inproc_transport.cc
  25. 3
      src/core/ext/xds/xds_api.cc
  26. 6
      src/core/ext/xds/xds_certificate_provider.cc
  27. 5
      src/core/ext/xds/xds_client.cc
  28. 2
      src/core/ext/xds/xds_client_stats.h
  29. 10
      src/core/lib/avl/avl.cc
  30. 2
      src/core/lib/backoff/backoff.cc
  31. 13
      src/core/lib/channel/channel_args.cc
  32. 4
      src/core/lib/channel/channelz.cc
  33. 4
      src/core/lib/compression/compression.cc
  34. 10
      src/core/lib/compression/compression_args.cc
  35. 4
      src/core/lib/compression/compression_internal.cc
  36. 2
      src/core/lib/compression/compression_internal.h
  37. 2
      src/core/lib/debug/stats.cc
  38. 26
      src/core/lib/debug/stats_data.cc
  39. 2
      src/core/lib/gpr/atm.cc
  40. 2
      src/core/lib/gpr/cpu_posix.cc
  41. 4
      src/core/lib/gpr/string.cc
  42. 100
      src/core/lib/gpr/useful.h
  43. 4
      src/core/lib/http/parser.cc
  44. 8
      src/core/lib/iomgr/error.cc
  45. 5
      src/core/lib/iomgr/ev_epoll1_linux.cc
  46. 12
      src/core/lib/iomgr/ev_epollex_linux.cc
  47. 21
      src/core/lib/iomgr/ev_poll_posix.cc
  48. 6
      src/core/lib/iomgr/executor.cc
  49. 24
      src/core/lib/iomgr/resource_quota.cc
  50. 4
      src/core/lib/iomgr/socket_factory_posix.cc
  51. 4
      src/core/lib/iomgr/socket_mutator.cc
  52. 6
      src/core/lib/iomgr/tcp_posix.cc
  53. 26
      src/core/lib/iomgr/timer_generic.cc
  54. 2
      src/core/lib/iomgr/timer_heap.cc
  55. 2
      src/core/lib/security/authorization/authorization_policy_provider_vtable.cc
  56. 1
      src/core/lib/security/authorization/rbac_translator.cc
  57. 6
      src/core/lib/security/context/security_context.cc
  58. 6
      src/core/lib/security/credentials/credentials.cc
  59. 4
      src/core/lib/security/security_connector/fake/fake_security_connector.cc
  60. 11
      src/core/lib/security/security_connector/security_connector.cc
  61. 2
      src/core/lib/security/security_connector/ssl_utils.cc
  62. 2
      src/core/lib/security/transport/server_auth_filter.cc
  63. 10
      src/core/lib/slice/slice_buffer.cc
  64. 14
      src/core/lib/surface/call.cc
  65. 6
      src/core/lib/surface/channel.cc
  66. 7
      src/core/lib/surface/channel_init.cc
  67. 9
      src/core/lib/surface/completion_queue.cc
  68. 2
      src/core/lib/surface/lame_client.cc
  69. 2
      src/core/lib/surface/server.cc
  70. 2
      src/core/lib/transport/bdp_estimator.cc
  71. 3
      src/core/lib/transport/metadata.h
  72. 8
      src/core/lib/transport/pid_controller.cc
  73. 22
      src/core/tsi/alts/frame_protector/alts_frame_protector.cc
  74. 14
      src/core/tsi/alts/frame_protector/frame_handler.cc
  75. 2
      src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc
  76. 4
      src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc
  77. 4
      src/core/tsi/fake_transport_security.cc
  78. 3
      src/cpp/common/completion_queue_cc.cc
  79. 4
      src/cpp/server/server_builder.cc
  80. 2
      test/core/bad_client/tests/head_of_line_blocking.cc
  81. 2
      test/core/bad_client/tests/window_overflow.cc
  82. 4
      test/core/channel/channel_args_test.cc
  83. 38
      test/core/compression/compression_test.cc
  84. 3
      test/core/end2end/fixtures/proxy.cc
  85. 14
      test/core/end2end/tests/compressed_payload.cc
  86. 22
      test/core/end2end/tests/stream_compression_compressed_payload.cc
  87. 14
      test/core/end2end/tests/workaround_cronet_compression.cc
  88. 6
      test/core/gpr/BUILD
  89. 76
      test/core/gpr/useful_test.cc
  90. 2
      test/core/iomgr/endpoint_tests.cc
  91. 2
      test/core/iomgr/socket_utils_test.cc
  92. 2
      test/core/iomgr/tcp_posix_test.cc
  93. 2
      test/core/iomgr/timer_heap_test.cc
  94. 2
      test/core/iomgr/udp_server_test.cc
  95. 2
      test/core/transport/bdp_estimator_test.cc
  96. 2
      test/core/transport/chttp2/hpack_encoder_test.cc
  97. 7
      test/core/tsi/alts/frame_protector/frame_handler_test.cc
  98. 4
      test/core/util/fuzzer_util.cc
  99. 11
      test/core/util/histogram.cc
  100. 4
      test/core/util/slice_splitter.cc
  101. Some files were not shown because too many files have changed in this diff Show More

23
BUILD

@ -621,17 +621,9 @@ grpc_cc_library(
external_deps = [
"absl/synchronization",
],
deps = [
"gpr_codegen",
],
)
grpc_cc_library(
name = "useful",
hdrs = ["src/core/lib/gpr/useful.h"],
language = "c++",
deps = [
"gpr_platform",
"gpr_codegen",
],
)
@ -693,6 +685,7 @@ grpc_cc_library(
"src/core/lib/gpr/string_windows.h",
"src/core/lib/gpr/time_precise.h",
"src/core/lib/gpr/tmpfile.h",
"src/core/lib/gpr/useful.h",
"src/core/lib/gprpp/arena.h",
"src/core/lib/gprpp/examine_stack.h",
"src/core/lib/gprpp/fork.h",
@ -734,7 +727,6 @@ grpc_cc_library(
"gpr_codegen",
"gpr_tls",
"grpc_codegen",
"useful",
],
)
@ -1605,7 +1597,6 @@ grpc_cc_library(
"orphanable",
"ref_counted",
"ref_counted_ptr",
"useful",
],
)
@ -1745,7 +1736,6 @@ grpc_cc_library(
"ref_counted",
"ref_counted_ptr",
"udpa_orca_upb",
"useful",
],
)
@ -1922,7 +1912,6 @@ grpc_cc_library(
"gpr_base",
"grpc_base_c",
"grpc_client_channel",
"useful",
],
)
@ -2566,7 +2555,6 @@ grpc_cc_library(
"gpr_base",
"grpc_base_c",
"grpc_client_channel",
"useful",
],
)
@ -2740,7 +2728,6 @@ grpc_cc_library(
"ref_counted_ptr",
"tsi",
"tsi_interface",
"useful",
],
)
@ -3004,7 +2991,6 @@ grpc_cc_library(
"hpack_encoder_table",
"match",
"popularity_count",
"useful",
],
)
@ -3019,7 +3005,6 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"useful",
],
)
@ -3214,7 +3199,6 @@ grpc_cc_library(
"gpr_base",
"grpc_base_c",
"tsi_interface",
"useful",
],
)
@ -3292,7 +3276,6 @@ grpc_cc_library(
"grpc_base_c",
"grpc_transport_chttp2_client_insecure",
"tsi_interface",
"useful",
],
)
@ -3322,7 +3305,6 @@ grpc_cc_library(
"grpc_trace",
"grpc_transport_inproc",
"ref_counted",
"useful",
],
)
@ -3353,7 +3335,6 @@ grpc_cc_library(
"grpc_transport_inproc",
"grpc_unsecure",
"ref_counted",
"useful",
],
)

63
CMakeLists.txt generated

@ -720,6 +720,7 @@ if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_c udp_server_test)
endif()
add_dependencies(buildtests_c useful_test)
add_dependencies(buildtests_c varint_test)
add_custom_target(buildtests_cxx)
@ -1006,7 +1007,6 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx try_seq_test)
add_dependencies(buildtests_cxx unknown_frame_bad_client_test)
add_dependencies(buildtests_cxx uri_parser_test)
add_dependencies(buildtests_cxx useful_test)
add_dependencies(buildtests_cxx window_overflow_bad_client_test)
add_dependencies(buildtests_cxx wire_reader_test)
add_dependencies(buildtests_cxx wire_writer_test)
@ -7613,6 +7613,33 @@ endif()
endif()
if(gRPC_BUILD_TESTS)
add_executable(useful_test
test/core/gpr/useful_test.cc
)
target_include_directories(useful_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
)
target_link_libraries(useful_test
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(varint_test
test/core/transport/chttp2/varint_test.cc
)
@ -16335,40 +16362,6 @@ target_link_libraries(uri_parser_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(useful_test
test/core/gpr/useful_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(useful_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(useful_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
)
endif()
if(gRPC_BUILD_TESTS)

@ -4171,6 +4171,15 @@ targets:
- linux
- posix
- mac
- name: useful_test
build: test
language: c
headers: []
src:
- test/core/gpr/useful_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: varint_test
build: test
language: c
@ -7914,16 +7923,6 @@ targets:
- test/core/uri/uri_parser_test.cc
deps:
- grpc_test_util
- name: useful_test
gtest: true
build: test
language: c++
headers:
- src/core/lib/gpr/useful.h
src:
- test/core/gpr/useful_test.cc
deps: []
uses_polling: false
- name: window_overflow_bad_client_test
gtest: true
build: test

@ -254,7 +254,7 @@ namespace {
// Channel arg pointer vtable for GRPC_ARG_CLIENT_CHANNEL.
void* ClientChannelArgCopy(void* p) { return p; }
void ClientChannelArgDestroy(void* /*p*/) {}
int ClientChannelArgCmp(void* p, void* q) { return QsortCompare(p, q); }
int ClientChannelArgCmp(void* p, void* q) { return GPR_ICMP(p, q); }
const grpc_arg_pointer_vtable kClientChannelArgPointerVtable = {
ClientChannelArgCopy, ClientChannelArgDestroy, ClientChannelArgCmp};
@ -268,7 +268,7 @@ void ServiceConfigObjArgDestroy(void* p) {
auto* service_config = static_cast<ServiceConfig*>(p);
service_config->Unref();
}
int ServiceConfigObjArgCmp(void* p, void* q) { return QsortCompare(p, q); }
int ServiceConfigObjArgCmp(void* p, void* q) { return GPR_ICMP(p, q); }
const grpc_arg_pointer_vtable kServiceConfigObjArgPointerVtable = {
ServiceConfigObjArgCopy, ServiceConfigObjArgDestroy,
ServiceConfigObjArgCmp};

@ -32,7 +32,7 @@ namespace {
void* factory_arg_copy(void* f) { return f; }
void factory_arg_destroy(void* /*f*/) {}
int factory_arg_cmp(void* factory1, void* factory2) {
return QsortCompare(factory1, factory2);
return GPR_ICMP(factory1, factory2);
}
const grpc_arg_pointer_vtable factory_arg_vtable = {
factory_arg_copy, factory_arg_destroy, factory_arg_cmp};

@ -35,7 +35,7 @@ void ConfigSelectorArgDestroy(void* p) {
config_selector->Unref();
}
int ConfigSelectorArgCmp(void* p, void* q) { return QsortCompare(p, q); }
int ConfigSelectorArgCmp(void* p, void* q) { return GPR_ICMP(p, q); }
const grpc_arg_pointer_vtable kChannelArgVtable = {
ConfigSelectorArgCopy, ConfigSelectorArgDestroy, ConfigSelectorArgCmp};

@ -265,7 +265,7 @@ class GrpcLb : public LoadBalancingPolicy {
static_cast<const TokenAndClientStatsAttribute*>(other_base);
int r = lb_token_.compare(other->lb_token_);
if (r != 0) return r;
return QsortCompare(client_stats_.get(), other->client_stats_.get());
return GPR_ICMP(client_stats_.get(), other->client_stats_.get());
}
std::string ToString() const override {
@ -1054,8 +1054,8 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked() {
switch (response.type) {
case response.INITIAL: {
if (response.client_stats_report_interval != 0) {
client_stats_report_interval_ = std::max(
int64_t(GPR_MS_PER_SEC), response.client_stats_report_interval);
client_stats_report_interval_ =
GPR_MAX(GPR_MS_PER_SEC, response.client_stats_report_interval);
if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
gpr_log(GPR_INFO,
"[grpclb %p] lb_calld=%p: Received initial LB response "

@ -42,7 +42,7 @@ int BalancerAddressesArgCmp(void* p, void* q) {
ServerAddressList* address_list1 = static_cast<ServerAddressList*>(p);
ServerAddressList* address_list2 = static_cast<ServerAddressList*>(q);
if (address_list1 == nullptr || address_list2 == nullptr) {
return QsortCompare(address_list1, address_list2);
return GPR_ICMP(address_list1, address_list2);
}
if (address_list1->size() > address_list2->size()) return 1;
if (address_list1->size() < address_list2->size()) return -1;

@ -25,6 +25,8 @@
#include <grpc/support/alloc.h>
#include "src/core/lib/gpr/useful.h"
namespace grpc_core {
bool GrpcLbServer::operator==(const GrpcLbServer& other) const {
@ -54,8 +56,8 @@ grpc_slice GrpcLbRequestCreate(const char* lb_service_name, upb_arena* arena) {
grpc_lb_v1_LoadBalanceRequest* req = grpc_lb_v1_LoadBalanceRequest_new(arena);
grpc_lb_v1_InitialLoadBalanceRequest* initial_request =
grpc_lb_v1_LoadBalanceRequest_mutable_initial_request(req, arena);
size_t name_len = std::min(strlen(lb_service_name),
size_t(GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH));
size_t name_len =
GPR_MIN(strlen(lb_service_name), GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH);
grpc_lb_v1_InitialLoadBalanceRequest_set_name(
initial_request, upb_strview_make(lb_service_name, name_len));
return grpc_grpclb_request_encode(req, arena);

@ -267,7 +267,7 @@ void PickFirst::UpdateLocked(UpdateArgs args) {
const_cast<char*>(GRPC_ARG_INHIBIT_HEALTH_CHECKING), 1);
const grpc_channel_args* new_args =
grpc_channel_args_copy_and_add(args.args, &new_arg, 1);
std::swap(new_args, args.args);
GPR_SWAP(const grpc_channel_args*, new_args, args.args);
grpc_channel_args_destroy(new_args);
latest_update_args_ = std::move(args);
// If we are not in idle, start connection attempt immediately.

@ -33,6 +33,7 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/transport/connectivity_state.h"

@ -324,9 +324,7 @@ void ResponseGeneratorChannelArgDestroy(void* p) {
generator->Unref();
}
int ResponseGeneratorChannelArgCmp(void* a, void* b) {
return QsortCompare(a, b);
}
int ResponseGeneratorChannelArgCmp(void* a, void* b) { return GPR_ICMP(a, b); }
} // namespace

@ -128,7 +128,7 @@ class ServerAddressWeightAttribute : public ServerAddress::AttributeInterface {
int Cmp(const AttributeInterface* other) const override {
const auto* other_locality_attr =
static_cast<const ServerAddressWeightAttribute*>(other);
return QsortCompare(weight_, other_locality_attr->weight_);
return GPR_ICMP(weight_, other_locality_attr->weight_);
}
std::string ToString() const override {

@ -86,7 +86,7 @@ void arg_destroy(void* p) {
subchannel_pool->Unref();
}
int arg_cmp(void* a, void* b) { return QsortCompare(a, b); }
int arg_cmp(void* a, void* b) { return GPR_ICMP(a, b); }
const grpc_arg_pointer_vtable subchannel_pool_arg_vtable = {
arg_copy, arg_destroy, arg_cmp};

@ -118,7 +118,7 @@ enum ChannelState {
};
grpc_millis GetClientIdleTimeout(const grpc_channel_args* args) {
return std::max(
return GPR_MAX(
grpc_channel_arg_get_integer(
grpc_channel_args_find(args, GRPC_ARG_CLIENT_IDLE_TIMEOUT_MS),
{DEFAULT_IDLE_TIMEOUT_MS, 0, INT_MAX}),

@ -364,22 +364,22 @@ void CallData::DecideWhetherToInjectFaults(
key == fi_policy_->abort_percentage_header) {
maybe_copy_policy_func();
copied_policy->abort_percentage_numerator =
std::min(GetMetadatumValueUnsignedInt(md),
fi_policy_->abort_percentage_numerator);
GPR_MIN(GetMetadatumValueUnsignedInt(md),
fi_policy_->abort_percentage_numerator);
}
if (!fi_policy_->delay_header.empty() &&
(copied_policy == nullptr || copied_policy->delay == 0) &&
key == fi_policy_->delay_header) {
maybe_copy_policy_func();
copied_policy->delay = static_cast<grpc_millis>(
std::max(GetMetadatumValueInt64(md), int64_t(0)));
copied_policy->delay =
static_cast<grpc_millis>(GPR_MAX(GetMetadatumValueInt64(md), 0));
}
if (!fi_policy_->delay_percentage_header.empty() &&
key == fi_policy_->delay_percentage_header) {
maybe_copy_policy_func();
copied_policy->delay_percentage_numerator =
std::min(GetMetadatumValueUnsignedInt(md),
fi_policy_->delay_percentage_numerator);
GPR_MIN(GetMetadatumValueUnsignedInt(md),
fi_policy_->delay_percentage_numerator);
}
});
if (copied_policy != nullptr) fi_policy_ = copied_policy;

@ -55,8 +55,8 @@ class ChannelData {
grpc_channel_args_get_channel_default_compression_algorithm(
args->channel_args);
// Make sure the default is enabled.
if (!grpc_core::GetBit(enabled_compression_algorithms_bitset_,
default_compression_algorithm_)) {
if (!GPR_BITGET(enabled_compression_algorithms_bitset_,
default_compression_algorithm_)) {
const char* name;
GPR_ASSERT(grpc_compression_algorithm_name(default_compression_algorithm_,
&name) == 1);
@ -108,8 +108,7 @@ class CallData {
ChannelData* channeld = static_cast<ChannelData*>(elem->channel_data);
// The call's message compression algorithm is set to channel's default
// setting. It can be overridden later by initial metadata.
if (GPR_LIKELY(
grpc_core::GetBit(channeld->enabled_compression_algorithms_bitset(),
if (GPR_LIKELY(GPR_BITGET(channeld->enabled_compression_algorithms_bitset(),
channeld->default_compression_algorithm()))) {
message_compression_algorithm_ =
grpc_compression_algorithm_to_message_compression_algorithm(
@ -212,8 +211,7 @@ grpc_compression_algorithm FindCompressionAlgorithm(
// enabled.
// TODO(juanlishen): Maybe use channel default or abort() if the algorithm
// from the initial metadata is disabled.
if (GPR_LIKELY(
grpc_core::GetBit(channeld->enabled_compression_algorithms_bitset(),
if (GPR_LIKELY(GPR_BITGET(channeld->enabled_compression_algorithms_bitset(),
compression_algorithm))) {
return compression_algorithm;
}

@ -1064,7 +1064,7 @@ static void queue_setting_update(grpc_chttp2_transport* t,
grpc_chttp2_setting_id id, uint32_t value) {
const grpc_chttp2_setting_parameters* sp =
&grpc_chttp2_settings_parameters[id];
uint32_t use_value = grpc_core::Clamp(value, sp->min_value, sp->max_value);
uint32_t use_value = GPR_CLAMP(value, sp->min_value, sp->max_value);
if (use_value != value) {
gpr_log(GPR_INFO, "Requested parameter %s clamped from %d to %d", sp->name,
value, use_value);
@ -1433,7 +1433,7 @@ static void perform_stream_op_locked(void* stream_op,
op_payload->send_initial_metadata.send_initial_metadata;
if (t->is_client) {
s->deadline =
std::min(s->deadline, (*s->send_initial_metadata)->deadline());
GPR_MIN(s->deadline, (*s->send_initial_metadata)->deadline());
}
if (contains_non_ok_status(s->send_initial_metadata)) {
s->seen_error = true;
@ -1978,8 +1978,7 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t,
GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS) {
grpc_slice_buffer_move_first(
&s->frame_storage,
std::min(s->frame_storage.length,
size_t(GRPC_HEADER_SIZE_IN_BYTES)),
GPR_MIN(s->frame_storage.length, GRPC_HEADER_SIZE_IN_BYTES),
&s->unprocessed_incoming_frames_buffer);
if (s->unprocessed_incoming_frames_buffer.length > 0) {
s->unprocessed_incoming_frames_decompressed = true;
@ -2520,7 +2519,7 @@ static void read_action_locked(void* tp, grpc_error_handle error) {
GRPC_ERROR_INT_OCCURRED_DURING_WRITE,
t->write_state);
}
std::swap(err, error);
GPR_SWAP(grpc_error_handle, err, error);
GRPC_ERROR_UNREF(err);
if (t->closed_with_error == GRPC_ERROR_NONE) {
GPR_TIMER_SCOPE("reading_action.parse", 0);

@ -48,7 +48,7 @@ bool g_test_only_transport_flow_control_window_check;
namespace {
static constexpr const int kTracePadding = 30;
static constexpr const int64_t kMaxWindowUpdateSize = (1u << 31) - 1;
static constexpr const uint32_t kMaxWindowUpdateSize = (1u << 31) - 1;
static char* fmt_int64_diff_str(int64_t old_val, int64_t new_val) {
std::string str;
@ -181,7 +181,7 @@ TransportFlowControl::TransportFlowControl(const grpc_chttp2_transport* t,
: t_(t),
enable_bdp_probe_(enable_bdp_probe),
bdp_estimator_(t->peer_string.c_str()),
pid_controller_(PidController::Args()
pid_controller_(grpc_core::PidController::Args()
.set_gain_p(4)
.set_gain_i(8)
.set_gain_d(0)
@ -189,7 +189,7 @@ TransportFlowControl::TransportFlowControl(const grpc_chttp2_transport* t,
.set_min_control_value(-1)
.set_max_control_value(25)
.set_integral_range(10)),
last_pid_update_(ExecCtx::Get()->Now()) {}
last_pid_update_(grpc_core::ExecCtx::Get()->Now()) {}
uint32_t TransportFlowControl::MaybeSendUpdate(bool writing_anyway) {
FlowControlTrace trace("t updt sent", this, nullptr);
@ -197,9 +197,8 @@ uint32_t TransportFlowControl::MaybeSendUpdate(bool writing_anyway) {
static_cast<uint32_t>(target_window());
if ((writing_anyway || announced_window_ <= target_announced_window / 2) &&
announced_window_ != target_announced_window) {
const uint32_t announce =
static_cast<uint32_t>(Clamp(target_announced_window - announced_window_,
int64_t(0), kMaxWindowUpdateSize));
const uint32_t announce = static_cast<uint32_t> GPR_CLAMP(
target_announced_window - announced_window_, 0, kMaxWindowUpdateSize);
announced_window_ += announce;
return announce;
}
@ -281,9 +280,8 @@ uint32_t StreamFlowControl::MaybeSendUpdate() {
}
}
if (local_window_delta_ > announced_window_delta_) {
uint32_t announce = static_cast<uint32_t>(
Clamp(local_window_delta_ - announced_window_delta_, int64_t(0),
kMaxWindowUpdateSize));
uint32_t announce = static_cast<uint32_t> GPR_CLAMP(
local_window_delta_ - announced_window_delta_, 0, kMaxWindowUpdateSize);
UpdateAnnouncedWindowDelta(tfc_, announce);
return announce;
}
@ -336,8 +334,8 @@ static double AdjustForMemoryPressure(grpc_resource_quota* quota,
target = (target - kZeroTarget) * memory_pressure / kLowMemPressure +
kZeroTarget;
} else if (memory_pressure > kHighMemPressure) {
target *= 1 - std::min(1.0, (memory_pressure - kHighMemPressure) /
(kMaxMemPressure - kHighMemPressure));
target *= 1 - GPR_MIN(1, (memory_pressure - kHighMemPressure) /
(kMaxMemPressure - kHighMemPressure));
}
return target;
}
@ -348,7 +346,7 @@ double TransportFlowControl::TargetLogBdp() {
}
double TransportFlowControl::SmoothLogBdp(double value) {
grpc_millis now = ExecCtx::Get()->Now();
grpc_millis now = grpc_core::ExecCtx::Get()->Now();
double bdp_error = value - pid_controller_.last_control_value();
const double dt = static_cast<double>(now - last_pid_update_) * 1e-3;
last_pid_update_ = now;
@ -385,8 +383,8 @@ FlowControlAction TransportFlowControl::PeriodicUpdate() {
}
// Though initial window 'could' drop to 0, we keep the floor at
// kMinInitialWindowSize
target_initial_window_size_ = static_cast<int32_t>(Clamp(
target, double(kMinInitialWindowSize), double(kMaxInitialWindowSize)));
target_initial_window_size_ = static_cast<int32_t> GPR_CLAMP(
target, kMinInitialWindowSize, kMaxInitialWindowSize);
action.set_send_initial_window_update(
DeltaUrgency(target_initial_window_size_,
GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE),
@ -395,11 +393,10 @@ FlowControlAction TransportFlowControl::PeriodicUpdate() {
// get bandwidth estimate and update max_frame accordingly.
double bw_dbl = bdp_estimator_.EstimateBandwidth();
// we target the max of BDP or bandwidth in microseconds.
int32_t frame_size = static_cast<int32_t>(Clamp(
std::max(
static_cast<int32_t>(Clamp(bw_dbl, 0.0, double(INT_MAX))) / 1000,
static_cast<int32_t>(target_initial_window_size_)),
16384, 16777215));
int32_t frame_size = static_cast<int32_t> GPR_CLAMP(
GPR_MAX((int32_t)GPR_CLAMP(bw_dbl, 0, INT_MAX) / 1000,
target_initial_window_size_),
16384, 16777215);
action.set_send_max_frame_size_update(
DeltaUrgency(static_cast<int64_t>(frame_size),
GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE),

@ -274,10 +274,10 @@ class TransportFlowControl final : public TransportFlowControlBase {
// See comment above announced_stream_total_over_incoming_window_ for the
// logic behind this decision.
int64_t target_window() const override {
return static_cast<uint32_t>(
std::min(static_cast<int64_t>((1u << 31) - 1),
announced_stream_total_over_incoming_window_ +
target_initial_window_size_));
return static_cast<uint32_t> GPR_MIN(
(int64_t)((1u << 31) - 1),
announced_stream_total_over_incoming_window_ +
target_initial_window_size_);
}
const grpc_chttp2_transport* transport() const { return t_; }

@ -112,8 +112,7 @@ grpc_error_handle grpc_chttp2_ping_parser_parse(void* parser,
}
if (!g_disable_ping_ack) {
if (t->ping_ack_count == t->ping_ack_capacity) {
t->ping_ack_capacity =
std::max(t->ping_ack_capacity * 3 / 2, size_t(3));
t->ping_ack_capacity = GPR_MAX(t->ping_ack_capacity * 3 / 2, 3);
t->ping_acks = static_cast<uint64_t*>(gpr_realloc(
t->ping_acks, t->ping_ack_capacity * sizeof(*t->ping_acks)));
}

@ -217,8 +217,8 @@ grpc_error_handle grpc_chttp2_settings_parser_parse(void* p,
if (parser->value < sp->min_value || parser->value > sp->max_value) {
switch (sp->invalid_value_behavior) {
case GRPC_CHTTP2_CLAMP_INVALID_VALUE:
parser->value = grpc_core::Clamp(parser->value, sp->min_value,
sp->max_value);
parser->value =
GPR_CLAMP(parser->value, sp->min_value, sp->max_value);
break;
case GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE:
grpc_chttp2_goaway_append(

@ -177,12 +177,11 @@ static void report_stall(grpc_chttp2_transport* t, grpc_chttp2_stream* s,
t->settings[GRPC_ACKED_SETTINGS]
[GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE],
t->flow_control->remote_window(),
static_cast<uint32_t>(std::max(
int64_t(0),
static_cast<uint32_t> GPR_MAX(
0,
s->flow_control->remote_window_delta() +
static_cast<int64_t>(
t->settings[GRPC_PEER_SETTINGS]
[GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE]))),
(int64_t)t->settings[GRPC_PEER_SETTINGS]
[GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE]),
s->flow_control->remote_window_delta());
}
}
@ -327,26 +326,23 @@ class DataSendContext {
sending_bytes_before_(s_->sending_bytes) {}
uint32_t stream_remote_window() const {
return static_cast<uint32_t>(std::max(
int64_t(0),
s_->flow_control->remote_window_delta() +
static_cast<int64_t>(
t_->settings[GRPC_PEER_SETTINGS]
[GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE])));
return static_cast<uint32_t> GPR_MAX(
0, s_->flow_control->remote_window_delta() +
(int64_t)t_->settings[GRPC_PEER_SETTINGS]
[GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE]);
}
uint32_t max_outgoing() const {
return static_cast<uint32_t>(std::min(
return static_cast<uint32_t> GPR_MIN(
t_->settings[GRPC_PEER_SETTINGS][GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE],
static_cast<uint32_t>(std::min(int64_t(stream_remote_window()),
t_->flow_control->remote_window()))));
GPR_MIN(stream_remote_window(), t_->flow_control->remote_window()));
}
bool AnyOutgoing() const { return max_outgoing() > 0; }
void FlushUncompressedBytes() {
uint32_t send_bytes = static_cast<uint32_t>(
std::min(size_t(max_outgoing()), s_->flow_controlled_buffer.length));
uint32_t send_bytes = static_cast<uint32_t> GPR_MIN(
max_outgoing(), s_->flow_controlled_buffer.length);
is_last_frame_ = send_bytes == s_->flow_controlled_buffer.length &&
s_->fetching_send_message == nullptr &&
s_->send_trailing_metadata != nullptr &&
@ -361,8 +357,8 @@ class DataSendContext {
GPR_DEBUG_ASSERT(s_->stream_compression_method !=
GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS);
uint32_t send_bytes = static_cast<uint32_t>(
std::min(size_t(max_outgoing()), s_->compressed_data_buffer.length));
uint32_t send_bytes = static_cast<uint32_t> GPR_MIN(
max_outgoing(), s_->compressed_data_buffer.length);
bool is_last_data_frame =
(send_bytes == s_->compressed_data_buffer.length &&
s_->flow_controlled_buffer.length == 0 &&

@ -175,7 +175,7 @@ struct inproc_stream {
fill_in_metadata(this, &cs->write_buffer_initial_md,
cs->write_buffer_initial_md_flags, &to_read_initial_md,
&to_read_initial_md_flags, &to_read_initial_md_filled);
deadline = std::min(deadline, cs->write_buffer_deadline);
deadline = GPR_MIN(deadline, cs->write_buffer_deadline);
grpc_metadata_batch_clear(&cs->write_buffer_initial_md);
cs->write_buffer_initial_md_filled = false;
}
@ -1032,7 +1032,7 @@ void perform_stream_op(grpc_transport* gt, grpc_stream* gs,
if (s->t->is_client) {
grpc_millis* dl =
(other == nullptr) ? &s->write_buffer_deadline : &other->deadline;
*dl = std::min(
*dl = GPR_MIN(
*dl, (*op->payload->send_initial_metadata.send_initial_metadata)
->deadline());
s->initial_md_sent = true;

@ -94,6 +94,7 @@
#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/sockaddr.h"
@ -3272,7 +3273,7 @@ grpc_error_handle DropParseAndAppend(
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Unknown denominator type");
}
// Cap numerator to 1000000.
numerator = std::min(numerator, 1000000u);
numerator = GPR_MIN(numerator, 1000000);
drop_config->AddCategory(std::move(category), numerator);
return GRPC_ERROR_NONE;
}

@ -23,6 +23,8 @@
#include "absl/functional/bind_front.h"
#include "absl/strings/str_cat.h"
#include "src/core/lib/gpr/useful.h"
namespace grpc_core {
namespace {
@ -377,9 +379,7 @@ void XdsCertificateProviderArgDestroy(void* p) {
xds_certificate_provider->Unref();
}
int XdsCertificateProviderArgCmp(void* p, void* q) {
return QsortCompare(p, q);
}
int XdsCertificateProviderArgCmp(void* p, void* q) { return GPR_ICMP(p, q); }
const grpc_arg_pointer_vtable kChannelArgVtable = {
XdsCertificateProviderArgCopy, XdsCertificateProviderArgDestroy,

@ -646,8 +646,7 @@ void XdsClient::ChannelState::RetryableCall<T>::StartRetryTimerLocked() {
if (shutting_down_) return;
const grpc_millis next_attempt_time = backoff_.NextAttemptTime();
if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
grpc_millis timeout =
std::max(next_attempt_time - ExecCtx::Get()->Now(), grpc_millis(0));
grpc_millis timeout = GPR_MAX(next_attempt_time - ExecCtx::Get()->Now(), 0);
gpr_log(GPR_INFO,
"[xds_client %p] Failed to connect to xds server (chand: %p) "
"retry timer will fire in %" PRId64 "ms.",
@ -2541,7 +2540,7 @@ void XdsClientArgDestroy(void* p) {
xds_client->Unref(DEBUG_LOCATION, "channel arg");
}
int XdsClientArgCmp(void* p, void* q) { return QsortCompare(p, q); }
int XdsClientArgCmp(void* p, void* q) { return GPR_ICMP(p, q); }
const grpc_arg_pointer_vtable kXdsClientArgVtable = {
XdsClientArgCopy, XdsClientArgDestroy, XdsClientArgCmp};

@ -46,7 +46,7 @@ class XdsLocalityName : public RefCounted<XdsLocalityName> {
struct Less {
bool operator()(const XdsLocalityName* lhs,
const XdsLocalityName* rhs) const {
if (lhs == nullptr || rhs == nullptr) return QsortCompare(lhs, rhs);
if (lhs == nullptr || rhs == nullptr) return GPR_ICMP(lhs, rhs);
return lhs->Compare(*rhs) < 0;
}

@ -23,11 +23,11 @@
#include <assert.h>
#include <stdlib.h>
#include <algorithm>
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/useful.h"
grpc_avl grpc_avl_create(const grpc_avl_vtable* vtable) {
grpc_avl out;
out.vtable = vtable;
@ -63,8 +63,8 @@ static long node_height(grpc_avl_node* node) {
#ifndef NDEBUG
static long calculate_height(grpc_avl_node* node) {
return node == nullptr ? 0
: 1 + std::max(calculate_height(node->left),
calculate_height(node->right));
: 1 + GPR_MAX(calculate_height(node->left),
calculate_height(node->right));
}
static grpc_avl_node* assert_invariants(grpc_avl_node* n) {
@ -87,7 +87,7 @@ grpc_avl_node* new_node(void* key, void* value, grpc_avl_node* left,
node->value = value;
node->left = assert_invariants(left);
node->right = assert_invariants(right);
node->height = 1 + std::max(node_height(left), node_height(right));
node->height = 1 + GPR_MAX(node_height(left), node_height(right));
return node;
}

@ -39,7 +39,7 @@ double generate_uniform_random_number(uint32_t* rng_state) {
double generate_uniform_random_number_between(uint32_t* rng_state, double a,
double b) {
if (a == b) return a;
if (a > b) std::swap(a, b); // make sure a < b
if (a > b) GPR_SWAP(double, a, b); // make sure a < b
const double range = b - a;
return a + generate_uniform_random_number(rng_state) * range;
}

@ -146,7 +146,7 @@ grpc_channel_args* grpc_channel_args_union(const grpc_channel_args* a,
}
static int cmp_arg(const grpc_arg* a, const grpc_arg* b) {
int c = grpc_core::QsortCompare(a->type, b->type);
int c = GPR_ICMP(a->type, b->type);
if (c != 0) return c;
c = strcmp(a->key, b->key);
if (c != 0) return c;
@ -154,12 +154,11 @@ static int cmp_arg(const grpc_arg* a, const grpc_arg* b) {
case GRPC_ARG_STRING:
return strcmp(a->value.string, b->value.string);
case GRPC_ARG_INTEGER:
return grpc_core::QsortCompare(a->value.integer, b->value.integer);
return GPR_ICMP(a->value.integer, b->value.integer);
case GRPC_ARG_POINTER:
c = grpc_core::QsortCompare(a->value.pointer.p, b->value.pointer.p);
c = GPR_ICMP(a->value.pointer.p, b->value.pointer.p);
if (c != 0) {
c = grpc_core::QsortCompare(a->value.pointer.vtable,
b->value.pointer.vtable);
c = GPR_ICMP(a->value.pointer.vtable, b->value.pointer.vtable);
if (c == 0) {
c = a->value.pointer.vtable->cmp(a->value.pointer.p,
b->value.pointer.p);
@ -176,7 +175,7 @@ static int cmp_key_stable(const void* ap, const void* bp) {
const grpc_arg* const* a = static_cast<const grpc_arg* const*>(ap);
const grpc_arg* const* b = static_cast<const grpc_arg* const*>(bp);
int c = strcmp((*a)->key, (*b)->key);
if (c == 0) c = grpc_core::QsortCompare(*a, *b);
if (c == 0) c = GPR_ICMP(*a, *b);
return c;
}
@ -226,7 +225,7 @@ int grpc_channel_args_compare(const grpc_channel_args* a,
const grpc_channel_args* b) {
if (a == nullptr && b == nullptr) return 0;
if (a == nullptr || b == nullptr) return a == nullptr ? -1 : 1;
int c = grpc_core::QsortCompare(a->num_args, b->num_args);
int c = GPR_ICMP(a->num_args, b->num_args);
if (c != 0) return c;
for (size_t i = 0; i < a->num_args; i++) {
c = cmp_arg(&a->args[i], &b->args[i]);

@ -77,7 +77,7 @@ std::string BaseNode::RenderJsonString() {
//
CallCountingHelper::CallCountingHelper() {
num_cores_ = std::max(1u, gpr_cpu_num_cores());
num_cores_ = GPR_MAX(1, gpr_cpu_num_cores());
per_cpu_counter_data_storage_.reserve(num_cores_);
for (size_t i = 0; i < num_cores_; ++i) {
per_cpu_counter_data_storage_.emplace_back();
@ -398,7 +398,7 @@ void SecurityArgDestroy(void* p) {
xds_certificate_provider->Unref();
}
int SecurityArgCmp(void* p, void* q) { return grpc_core::QsortCompare(p, q); }
int SecurityArgCmp(void* p, void* q) { return GPR_ICMP(p, q); }
const grpc_arg_pointer_vtable kChannelArgVtable = {
SecurityArgCopy, SecurityArgDestroy, SecurityArgCmp};

@ -116,12 +116,12 @@ void grpc_compression_options_init(grpc_compression_options* opts) {
void grpc_compression_options_enable_algorithm(
grpc_compression_options* opts, grpc_compression_algorithm algorithm) {
grpc_core::SetBit(&opts->enabled_algorithms_bitset, algorithm);
GPR_BITSET(&opts->enabled_algorithms_bitset, algorithm);
}
void grpc_compression_options_disable_algorithm(
grpc_compression_options* opts, grpc_compression_algorithm algorithm) {
grpc_core::ClearBit(&opts->enabled_algorithms_bitset, algorithm);
GPR_BITCLEAR(&opts->enabled_algorithms_bitset, algorithm);
}
int grpc_compression_options_is_algorithm_enabled(

@ -101,9 +101,9 @@ grpc_channel_args* grpc_channel_args_compression_algorithm_set_state(
algo_name);
} else if (states_arg_found) {
if (state != 0) {
grpc_core::SetBit(reinterpret_cast<unsigned*>(states_arg), algorithm);
GPR_BITSET((unsigned*)states_arg, algorithm);
} else if (algorithm != GRPC_COMPRESS_NONE) {
grpc_core::ClearBit(reinterpret_cast<unsigned*>(states_arg), algorithm);
GPR_BITCLEAR((unsigned*)states_arg, algorithm);
}
} else {
/* create a new arg */
@ -114,11 +114,9 @@ grpc_channel_args* grpc_channel_args_compression_algorithm_set_state(
/* all enabled by default */
tmp.value.integer = (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1;
if (state != 0) {
grpc_core::SetBit(reinterpret_cast<unsigned*>(&tmp.value.integer),
algorithm);
GPR_BITSET((unsigned*)&tmp.value.integer, algorithm);
} else if (algorithm != GRPC_COMPRESS_NONE) {
grpc_core::ClearBit(reinterpret_cast<unsigned*>(&tmp.value.integer),
algorithm);
GPR_BITCLEAR((unsigned*)&tmp.value.integer, algorithm);
}
result = grpc_channel_args_copy_and_add(*a, &tmp, 1);
grpc_channel_args_destroy(*a);

@ -207,7 +207,7 @@ grpc_message_compression_algorithm grpc_message_compression_algorithm_for_level(
}
const size_t num_supported =
grpc_core::BitCount(accepted_encodings) - 1; /* discard NONE */
GPR_BITCOUNT(accepted_encodings) - 1; /* discard NONE */
if (level == GRPC_COMPRESS_LEVEL_NONE || num_supported == 0) {
return GRPC_MESSAGE_COMPRESS_NONE;
}
@ -228,7 +228,7 @@ grpc_message_compression_algorithm grpc_message_compression_algorithm_for_level(
for (size_t i = 0; i < GPR_ARRAY_SIZE(algos_ranking); i++) {
const grpc_message_compression_algorithm alg = algos_ranking[i];
for (size_t j = 0; j < num_supported; j++) {
if (grpc_core::GetBit(accepted_encodings, alg) == 1) {
if (GPR_BITGET(accepted_encodings, alg) == 1) {
/* if \a alg in supported */
sorted_supported_algos[algos_supported_idx++] = alg;
break;

@ -91,7 +91,7 @@ int grpc_stream_compression_algorithm_parse(
inline int grpc_compression_options_is_algorithm_enabled_internal(
const grpc_compression_options* opts,
grpc_compression_algorithm algorithm) {
return grpc_core::GetBit(opts->enabled_algorithms_bitset, algorithm);
return GPR_BITGET(opts->enabled_algorithms_bitset, algorithm);
}
#endif /* GRPC_CORE_LIB_COMPRESSION_COMPRESSION_INTERNAL_H */

@ -38,7 +38,7 @@ grpc_stats_data* grpc_stats_per_cpu_storage = nullptr;
static size_t g_num_cores;
void grpc_stats_init(void) {
g_num_cores = std::max(1u, gpr_cpu_num_cores());
g_num_cores = GPR_MAX(1, gpr_cpu_num_cores());
grpc_stats_per_cpu_storage = static_cast<grpc_stats_data*>(
gpr_zalloc(sizeof(grpc_stats_data) * g_num_cores));
}

@ -353,7 +353,7 @@ const uint8_t grpc_stats_table_7[102] = {
const int grpc_stats_table_8[9] = {0, 1, 2, 4, 7, 13, 23, 39, 64};
const uint8_t grpc_stats_table_9[9] = {0, 0, 1, 2, 2, 3, 4, 4, 5};
void grpc_stats_inc_call_initial_size(int value) {
value = grpc_core::Clamp(value, 0, 262144);
value = GPR_CLAMP(value, 0, 262144);
if (value < 6) {
GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, value);
return;
@ -376,7 +376,7 @@ void grpc_stats_inc_call_initial_size(int value) {
grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_0, 64));
}
void grpc_stats_inc_poll_events_returned(int value) {
value = grpc_core::Clamp(value, 0, 1024);
value = GPR_CLAMP(value, 0, 1024);
if (value < 29) {
GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, value);
return;
@ -399,7 +399,7 @@ void grpc_stats_inc_poll_events_returned(int value) {
grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_2, 128));
}
void grpc_stats_inc_tcp_write_size(int value) {
value = grpc_core::Clamp(value, 0, 16777216);
value = GPR_CLAMP(value, 0, 16777216);
if (value < 5) {
GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, value);
return;
@ -422,7 +422,7 @@ void grpc_stats_inc_tcp_write_size(int value) {
grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_4, 64));
}
void grpc_stats_inc_tcp_write_iov_size(int value) {
value = grpc_core::Clamp(value, 0, 1024);
value = GPR_CLAMP(value, 0, 1024);
if (value < 13) {
GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, value);
return;
@ -445,7 +445,7 @@ void grpc_stats_inc_tcp_write_iov_size(int value) {
grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64));
}
void grpc_stats_inc_tcp_read_size(int value) {
value = grpc_core::Clamp(value, 0, 16777216);
value = GPR_CLAMP(value, 0, 16777216);
if (value < 5) {
GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, value);
return;
@ -468,7 +468,7 @@ void grpc_stats_inc_tcp_read_size(int value) {
grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_4, 64));
}
void grpc_stats_inc_tcp_read_offer(int value) {
value = grpc_core::Clamp(value, 0, 16777216);
value = GPR_CLAMP(value, 0, 16777216);
if (value < 5) {
GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, value);
return;
@ -491,7 +491,7 @@ void grpc_stats_inc_tcp_read_offer(int value) {
grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_4, 64));
}
void grpc_stats_inc_tcp_read_offer_iov_size(int value) {
value = grpc_core::Clamp(value, 0, 1024);
value = GPR_CLAMP(value, 0, 1024);
if (value < 13) {
GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_TCP_READ_OFFER_IOV_SIZE,
value);
@ -516,7 +516,7 @@ void grpc_stats_inc_tcp_read_offer_iov_size(int value) {
grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64));
}
void grpc_stats_inc_http2_send_message_size(int value) {
value = grpc_core::Clamp(value, 0, 16777216);
value = GPR_CLAMP(value, 0, 16777216);
if (value < 5) {
GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE,
value);
@ -541,7 +541,7 @@ void grpc_stats_inc_http2_send_message_size(int value) {
grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_4, 64));
}
void grpc_stats_inc_http2_send_initial_metadata_per_write(int value) {
value = grpc_core::Clamp(value, 0, 1024);
value = GPR_CLAMP(value, 0, 1024);
if (value < 13) {
GRPC_STATS_INC_HISTOGRAM(
GRPC_STATS_HISTOGRAM_HTTP2_SEND_INITIAL_METADATA_PER_WRITE, value);
@ -566,7 +566,7 @@ void grpc_stats_inc_http2_send_initial_metadata_per_write(int value) {
grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64));
}
void grpc_stats_inc_http2_send_message_per_write(int value) {
value = grpc_core::Clamp(value, 0, 1024);
value = GPR_CLAMP(value, 0, 1024);
if (value < 13) {
GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_PER_WRITE,
value);
@ -591,7 +591,7 @@ void grpc_stats_inc_http2_send_message_per_write(int value) {
grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64));
}
void grpc_stats_inc_http2_send_trailing_metadata_per_write(int value) {
value = grpc_core::Clamp(value, 0, 1024);
value = GPR_CLAMP(value, 0, 1024);
if (value < 13) {
GRPC_STATS_INC_HISTOGRAM(
GRPC_STATS_HISTOGRAM_HTTP2_SEND_TRAILING_METADATA_PER_WRITE, value);
@ -616,7 +616,7 @@ void grpc_stats_inc_http2_send_trailing_metadata_per_write(int value) {
grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64));
}
void grpc_stats_inc_http2_send_flowctl_per_write(int value) {
value = grpc_core::Clamp(value, 0, 1024);
value = GPR_CLAMP(value, 0, 1024);
if (value < 13) {
GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_HTTP2_SEND_FLOWCTL_PER_WRITE,
value);
@ -641,7 +641,7 @@ void grpc_stats_inc_http2_send_flowctl_per_write(int value) {
grpc_stats_histo_find_bucket_slow(value, grpc_stats_table_6, 64));
}
void grpc_stats_inc_server_cqs_checked(int value) {
value = grpc_core::Clamp(value, 0, 64);
value = GPR_CLAMP(value, 0, 64);
if (value < 3) {
GRPC_STATS_INC_HISTOGRAM(GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED, value);
return;

@ -28,7 +28,7 @@ gpr_atm gpr_atm_no_barrier_clamped_add(gpr_atm* value, gpr_atm delta,
gpr_atm new_value;
do {
current_value = gpr_atm_no_barrier_load(value);
new_value = grpc_core::Clamp(current_value + delta, min, max);
new_value = GPR_CLAMP(current_value + delta, min, max);
if (new_value == current_value) break;
} while (!gpr_atm_no_barrier_cas(value, current_value, new_value));
return new_value;

@ -77,7 +77,7 @@ unsigned gpr_cpu_current_cpu(void) {
pthread_setspecific(thread_id_key, thread_id);
}
return (unsigned)grpc_core::HashPointer(thread_id, gpr_cpu_num_cores());
return (unsigned)GPR_HASH_POINTER(thread_id, gpr_cpu_num_cores());
}
#endif /* GPR_CPU_POSIX */

@ -89,7 +89,7 @@ static dump_out dump_out_create(void) {
static void dump_out_append(dump_out* out, char c) {
if (out->length == out->capacity) {
out->capacity = std::max(size_t(8), 2 * out->capacity);
out->capacity = GPR_MAX(8, 2 * out->capacity);
out->data = static_cast<char*>(gpr_realloc(out->data, out->capacity));
}
out->data[out->length++] = c;
@ -290,7 +290,7 @@ static void add_string_to_split(const char* beg, const char* end, char*** strs,
memcpy(out, beg, static_cast<size_t>(end - beg));
out[end - beg] = 0;
if (*nstrs == *capstrs) {
*capstrs = std::max(size_t(8), 2 * *capstrs);
*capstrs = GPR_MAX(8, 2 * *capstrs);
*strs = static_cast<char**>(gpr_realloc(*strs, sizeof(*strs) * *capstrs));
}
(*strs)[*nstrs] = out;

@ -19,84 +19,48 @@
#ifndef GRPC_CORE_LIB_GPR_USEFUL_H
#define GRPC_CORE_LIB_GPR_USEFUL_H
#include <grpc/impl/codegen/port_platform.h>
#include <cstddef>
/** useful utilities that don't belong anywhere else */
namespace grpc_core {
template <typename T>
T Clamp(T val, T min, T max) {
if (val < min) return min;
if (max < val) return max;
return val;
}
/** useful macros that don't belong anywhere else */
#define GPR_MIN(a, b) ((a) < (b) ? (a) : (b))
#define GPR_MAX(a, b) ((a) > (b) ? (a) : (b))
#define GPR_CLAMP(a, min, max) ((a) < (min) ? (min) : (a) > (max) ? (max) : (a))
/** rotl, rotr assume x is unsigned */
template <typename T>
constexpr T RotateLeft(T x, T n) {
return ((x << n) | (x >> (sizeof(x) * 8 - n)));
}
template <typename T>
constexpr T RotateRight(T x, T n) {
return ((x >> n) | (x << (sizeof(x) * 8 - n)));
}
#define GPR_ROTL(x, n) (((x) << (n)) | ((x) >> (sizeof(x) * 8 - (n))))
#define GPR_ROTR(x, n) (((x) >> (n)) | ((x) << (sizeof(x) * 8 - (n))))
// Set the n-th bit of i
template <typename T>
T SetBit(T* i, size_t n) {
return *i |= (T(1) << n);
}
#define GPR_ARRAY_SIZE(array) (sizeof(array) / sizeof(*(array)))
// Clear the n-th bit of i
template <typename T>
T ClearBit(T* i, size_t n) {
return *i &= ~(T(1) << n);
}
#define GPR_SWAP(type, a, b) \
do { \
type x = a; \
(a) = b; \
(b) = x; \
} while (0)
// Get the n-th bit of i
template <typename T>
bool GetBit(T i, size_t n) {
return (i & (T(1) << n)) != 0;
}
/** Set the \a n-th bit of \a i (a mutable pointer). */
#define GPR_BITSET(i, n) ((*(i)) |= (1u << (n)))
namespace useful_detail {
inline constexpr uint32_t HexdigitBitcount(uint32_t x) {
return (x - ((x >> 1) & 0x77777777) - ((x >> 2) & 0x33333333) -
((x >> 3) & 0x11111111));
}
} // namespace useful_detail
/** Clear the \a n-th bit of \a i (a mutable pointer). */
#define GPR_BITCLEAR(i, n) ((*(i)) &= ~(1u << (n)))
inline constexpr uint32_t BitCount(uint32_t i) {
return (((useful_detail::HexdigitBitcount(i) +
(useful_detail::HexdigitBitcount(i) >> 4)) &
0x0f0f0f0f) %
255);
}
/** Get the \a n-th bit of \a i */
#define GPR_BITGET(i, n) (((i) & (1u << (n))) != 0)
// This function uses operator< to implement a qsort-style comparison, whereby:
// if a is smaller than b, a number smaller than 0 is returned.
// if a is bigger than b, a number greater than 0 is returned.
// if a is neither smaller nor bigger than b, 0 is returned.
template <typename T>
int QsortCompare(const T& a, const T& b) {
if (a < b) return -1;
if (b < a) return 1;
return 0;
}
#define GPR_INTERNAL_HEXDIGIT_BITCOUNT(x) \
((x) - (((x) >> 1) & 0x77777777) - (((x) >> 2) & 0x33333333) - \
(((x) >> 3) & 0x11111111))
template <typename T>
constexpr size_t HashPointer(T* p, size_t range) {
return (((reinterpret_cast<size_t>(p)) >> 4) ^
((reinterpret_cast<size_t>(p)) >> 9) ^
((reinterpret_cast<size_t>(p)) >> 14)) %
range;
}
/** Returns number of bits set in bitset \a i */
#define GPR_BITCOUNT(i) \
(((GPR_INTERNAL_HEXDIGIT_BITCOUNT(i) + \
(GPR_INTERNAL_HEXDIGIT_BITCOUNT(i) >> 4)) & \
0x0f0f0f0f) % \
255)
} // namespace grpc_core
#define GPR_ICMP(a, b) ((a) < (b) ? -1 : ((a) > (b) ? 1 : 0))
#define GPR_ARRAY_SIZE(array) (sizeof(array) / sizeof(*(array)))
#define GPR_HASH_POINTER(x, range) \
(((((size_t)(x)) >> 4) ^ (((size_t)(x)) >> 9) ^ (((size_t)(x)) >> 14)) % \
(range))
#endif /* GRPC_CORE_LIB_GPR_USEFUL_H */

@ -221,7 +221,7 @@ static grpc_error_handle add_header(grpc_http_parser* parser) {
if (*hdr_count == parser->hdr_capacity) {
parser->hdr_capacity =
std::max(parser->hdr_capacity + 1, parser->hdr_capacity * 3 / 2);
GPR_MAX(parser->hdr_capacity + 1, parser->hdr_capacity * 3 / 2);
*hdrs = static_cast<grpc_http_header*>(
gpr_realloc(*hdrs, parser->hdr_capacity * sizeof(**hdrs)));
}
@ -280,7 +280,7 @@ static grpc_error_handle addbyte_body(grpc_http_parser* parser, uint8_t byte) {
}
if (*body_length == parser->body_capacity) {
parser->body_capacity = std::max(size_t(8), parser->body_capacity * 3 / 2);
parser->body_capacity = GPR_MAX(8, parser->body_capacity * 3 / 2);
*body = static_cast<char*>(gpr_realloc(*body, parser->body_capacity));
}
(*body)[*body_length] = static_cast<char>(byte);

@ -300,8 +300,8 @@ static uint8_t get_placement(grpc_error_handle* err, size_t size) {
GPR_ASSERT(*err);
uint8_t slots = static_cast<uint8_t>(size / sizeof(intptr_t));
if ((*err)->arena_size + slots > (*err)->arena_capacity) {
(*err)->arena_capacity = static_cast<uint8_t>(
std::min(UINT8_MAX - 1, (3 * (*err)->arena_capacity / 2)));
(*err)->arena_capacity = static_cast<uint8_t> GPR_MIN(
UINT8_MAX - 1, (3 * (*err)->arena_capacity / 2));
if ((*err)->arena_size + slots > (*err)->arena_capacity) {
return UINT8_MAX;
}
@ -646,7 +646,7 @@ struct kv_pairs {
};
static void append_chr(char c, char** s, size_t* sz, size_t* cap) {
if (*sz == *cap) {
*cap = std::max(size_t(8), 3 * *cap / 2);
*cap = GPR_MAX(8, 3 * *cap / 2);
*s = static_cast<char*>(gpr_realloc(*s, *cap));
}
(*s)[(*sz)++] = c;
@ -698,7 +698,7 @@ static void append_esc_str(const uint8_t* str, size_t len, char** s, size_t* sz,
static void append_kv(kv_pairs* kvs, char* key, char* value) {
if (kvs->num_kvs == kvs->cap_kvs) {
kvs->cap_kvs = std::max(3 * kvs->cap_kvs / 2, size_t(4));
kvs->cap_kvs = GPR_MAX(3 * kvs->cap_kvs / 2, 4);
kvs->kvs = static_cast<kv_pair*>(
gpr_realloc(kvs->kvs, sizeof(*kvs->kvs) * kvs->cap_kvs));
}

@ -195,7 +195,7 @@ struct grpc_pollset_worker {
(worker)->kick_state_mutator = __LINE__; \
} while (false)
#define MAX_NEIGHBORHOODS 1024u
#define MAX_NEIGHBORHOODS 1024
typedef struct pollset_neighborhood {
union {
@ -525,8 +525,7 @@ static grpc_error_handle pollset_global_init(void) {
&ev) != 0) {
return GRPC_OS_ERROR(errno, "epoll_ctl");
}
g_num_neighborhoods =
grpc_core::Clamp(gpr_cpu_num_cores(), 1u, MAX_NEIGHBORHOODS);
g_num_neighborhoods = GPR_CLAMP(gpr_cpu_num_cores(), 1, MAX_NEIGHBORHOODS);
g_neighborhoods = static_cast<pollset_neighborhood*>(
gpr_zalloc(sizeof(*g_neighborhoods) * g_num_neighborhoods));
for (size_t i = 0; i < g_num_neighborhoods; i++) {

@ -1357,7 +1357,7 @@ static void pollset_set_add_fd(grpc_pollset_set* pss, grpc_fd* fd) {
err_desc);
}
if (pss->fd_count == pss->fd_capacity) {
pss->fd_capacity = std::max(pss->fd_capacity * 2, size_t(8));
pss->fd_capacity = GPR_MAX(pss->fd_capacity * 2, 8);
pss->fds = static_cast<grpc_fd**>(
gpr_realloc(pss->fds, pss->fd_capacity * sizeof(*pss->fds)));
}
@ -1467,7 +1467,7 @@ static void pollset_set_add_pollset(grpc_pollset_set* pss, grpc_pollset* ps) {
pss->fds, &pss->fd_count),
err_desc);
if (pss->pollset_count == pss->pollset_capacity) {
pss->pollset_capacity = std::max(pss->pollset_capacity * 2, size_t(8));
pss->pollset_capacity = GPR_MAX(pss->pollset_capacity * 2, 8);
pss->pollsets = static_cast<grpc_pollset**>(gpr_realloc(
pss->pollsets, pss->pollset_capacity * sizeof(*pss->pollsets)));
}
@ -1492,7 +1492,7 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a,
return;
}
if (a > b) {
std::swap(a, b);
GPR_SWAP(grpc_pollset_set*, a, b);
}
gpr_mu* a_mu = &a->mu;
gpr_mu* b_mu = &b->mu;
@ -1513,7 +1513,7 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a,
const size_t a_size = a->fd_count + a->pollset_count;
const size_t b_size = b->fd_count + b->pollset_count;
if (b_size > a_size) {
std::swap(a, b);
GPR_SWAP(grpc_pollset_set*, a, b);
}
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO, "PSS: parent %p to %p", b, a);
@ -1521,7 +1521,7 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a,
a->refs.Ref();
b->parent = a;
if (a->fd_capacity < a->fd_count + b->fd_count) {
a->fd_capacity = std::max(2 * a->fd_capacity, a->fd_count + b->fd_count);
a->fd_capacity = GPR_MAX(2 * a->fd_capacity, a->fd_count + b->fd_count);
a->fds = static_cast<grpc_fd**>(
gpr_realloc(a->fds, a->fd_capacity * sizeof(*a->fds)));
}
@ -1539,7 +1539,7 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* a,
err_desc);
if (a->pollset_capacity < a->pollset_count + b->pollset_count) {
a->pollset_capacity =
std::max(2 * a->pollset_capacity, a->pollset_count + b->pollset_count);
GPR_MAX(2 * a->pollset_capacity, a->pollset_count + b->pollset_count);
a->pollsets = static_cast<grpc_pollset**>(
gpr_realloc(a->pollsets, a->pollset_capacity * sizeof(*a->pollsets)));
}

@ -873,7 +873,7 @@ static void pollset_add_fd(grpc_pollset* pollset, grpc_fd* fd) {
}
if (pollset->fd_count == pollset->fd_capacity) {
pollset->fd_capacity =
std::max(pollset->fd_capacity + 8, pollset->fd_count * 3 / 2);
GPR_MAX(pollset->fd_capacity + 8, pollset->fd_count * 3 / 2);
pollset->fds = static_cast<grpc_fd**>(
gpr_realloc(pollset->fds, sizeof(grpc_fd*) * pollset->fd_capacity));
}
@ -1198,7 +1198,7 @@ static void pollset_set_add_pollset(grpc_pollset_set* pollset_set,
gpr_mu_lock(&pollset_set->mu);
if (pollset_set->pollset_count == pollset_set->pollset_capacity) {
pollset_set->pollset_capacity =
std::max(size_t(8), 2 * pollset_set->pollset_capacity);
GPR_MAX(8, 2 * pollset_set->pollset_capacity);
pollset_set->pollsets = static_cast<grpc_pollset**>(gpr_realloc(
pollset_set->pollsets,
pollset_set->pollset_capacity * sizeof(*pollset_set->pollsets)));
@ -1223,8 +1223,8 @@ static void pollset_set_del_pollset(grpc_pollset_set* pollset_set,
for (i = 0; i < pollset_set->pollset_count; i++) {
if (pollset_set->pollsets[i] == pollset) {
pollset_set->pollset_count--;
std::swap(pollset_set->pollsets[i],
pollset_set->pollsets[pollset_set->pollset_count]);
GPR_SWAP(grpc_pollset*, pollset_set->pollsets[i],
pollset_set->pollsets[pollset_set->pollset_count]);
break;
}
}
@ -1247,8 +1247,7 @@ static void pollset_set_add_pollset_set(grpc_pollset_set* bag,
size_t i, j;
gpr_mu_lock(&bag->mu);
if (bag->pollset_set_count == bag->pollset_set_capacity) {
bag->pollset_set_capacity =
std::max(size_t(8), 2 * bag->pollset_set_capacity);
bag->pollset_set_capacity = GPR_MAX(8, 2 * bag->pollset_set_capacity);
bag->pollset_sets = static_cast<grpc_pollset_set**>(
gpr_realloc(bag->pollset_sets,
bag->pollset_set_capacity * sizeof(*bag->pollset_sets)));
@ -1273,8 +1272,8 @@ static void pollset_set_del_pollset_set(grpc_pollset_set* bag,
for (i = 0; i < bag->pollset_set_count; i++) {
if (bag->pollset_sets[i] == item) {
bag->pollset_set_count--;
std::swap(bag->pollset_sets[i],
bag->pollset_sets[bag->pollset_set_count]);
GPR_SWAP(grpc_pollset_set*, bag->pollset_sets[i],
bag->pollset_sets[bag->pollset_set_count]);
break;
}
}
@ -1285,8 +1284,7 @@ static void pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) {
size_t i;
gpr_mu_lock(&pollset_set->mu);
if (pollset_set->fd_count == pollset_set->fd_capacity) {
pollset_set->fd_capacity =
std::max(size_t(8), 2 * pollset_set->fd_capacity);
pollset_set->fd_capacity = GPR_MAX(8, 2 * pollset_set->fd_capacity);
pollset_set->fds = static_cast<grpc_fd**>(
gpr_realloc(pollset_set->fds,
pollset_set->fd_capacity * sizeof(*pollset_set->fds)));
@ -1308,7 +1306,8 @@ static void pollset_set_del_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) {
for (i = 0; i < pollset_set->fd_count; i++) {
if (pollset_set->fds[i] == fd) {
pollset_set->fd_count--;
std::swap(pollset_set->fds[i], pollset_set->fds[pollset_set->fd_count]);
GPR_SWAP(grpc_fd*, pollset_set->fds[i],
pollset_set->fds[pollset_set->fd_count]);
GRPC_FD_UNREF(fd, "pollset_set");
break;
}

@ -92,7 +92,7 @@ TraceFlag executor_trace(false, "executor");
Executor::Executor(const char* name) : name_(name) {
adding_thread_lock_ = GPR_SPINLOCK_STATIC_INITIALIZER;
gpr_atm_rel_store(&num_threads_, 0);
max_threads_ = std::max(1u, 2 * gpr_cpu_num_cores());
max_threads_ = GPR_MAX(1, 2 * gpr_cpu_num_cores());
}
void Executor::Init() { SetThreading(true); }
@ -285,8 +285,8 @@ void Executor::Enqueue(grpc_closure* closure, grpc_error_handle error,
ThreadState* ts = g_this_thread_state;
if (ts == nullptr) {
ts = &thd_state_[grpc_core::HashPointer(grpc_core::ExecCtx::Get(),
cur_thread_count)];
ts = &thd_state_[GPR_HASH_POINTER(grpc_core::ExecCtx::Get(),
cur_thread_count)];
} else {
GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF();
}

@ -305,12 +305,11 @@ static void rq_step_sched(grpc_resource_quota* resource_quota) {
static void rq_update_estimate(grpc_resource_quota* resource_quota) {
gpr_atm memory_usage_estimation = MEMORY_USAGE_ESTIMATION_MAX;
if (resource_quota->size != 0) {
memory_usage_estimation = grpc_core::Clamp(
static_cast<gpr_atm>(
(1.0 - (static_cast<double>(resource_quota->free_pool)) /
(static_cast<double>(resource_quota->size))) *
MEMORY_USAGE_ESTIMATION_MAX),
gpr_atm(0), gpr_atm(MEMORY_USAGE_ESTIMATION_MAX));
memory_usage_estimation =
GPR_CLAMP((gpr_atm)((1.0 - ((double)resource_quota->free_pool) /
((double)resource_quota->size)) *
MEMORY_USAGE_ESTIMATION_MAX),
0, MEMORY_USAGE_ESTIMATION_MAX);
}
gpr_atm_no_barrier_store(&resource_quota->memory_usage_estimation,
memory_usage_estimation);
@ -730,7 +729,7 @@ void grpc_resource_quota_resize(grpc_resource_quota* resource_quota,
a->resource_quota = grpc_resource_quota_ref_internal(resource_quota);
a->size = static_cast<int64_t>(size);
gpr_atm_no_barrier_store(&resource_quota->last_size,
(gpr_atm)std::min((size_t)GPR_ATM_MAX, size));
(gpr_atm)GPR_MIN((size_t)GPR_ATM_MAX, size));
GRPC_CLOSURE_INIT(&a->closure, rq_resize, a, grpc_schedule_on_exec_ctx);
grpc_core::ExecCtx::Run(DEBUG_LOCATION, &a->closure, GRPC_ERROR_NONE);
}
@ -763,7 +762,7 @@ static void rq_destroy(void* rq) {
grpc_resource_quota_unref_internal(static_cast<grpc_resource_quota*>(rq));
}
static int rq_cmp(void* a, void* b) { return grpc_core::QsortCompare(a, b); }
static int rq_cmp(void* a, void* b) { return GPR_ICMP(a, b); }
const grpc_arg_pointer_vtable* grpc_resource_quota_arg_vtable(void) {
static const grpc_arg_pointer_vtable vtable = {rq_copy, rq_destroy, rq_cmp};
@ -1036,11 +1035,10 @@ static size_t grpc_slice_allocator_adjust_allocation_length(
size_t target =
requested_length * (pressure > 0.8 ? (1.0 - pressure) / 0.2 : 1.0);
// Target will be some multiple of 8 bytes, rounded up
target =
(static_cast<size_t>(grpc_core::Clamp(target, slice_allocator->min_length,
slice_allocator->max_length)) +
255) &
~static_cast<size_t>(255);
target = ((static_cast<size_t> GPR_CLAMP(target, slice_allocator->min_length,
slice_allocator->max_length)) +
255) &
~static_cast<size_t>(255);
// Don't use more than 1/16th of the overall resource quota for a single
// read alloc
size_t rqmax = grpc_resource_quota_peek_size(

@ -47,11 +47,11 @@ int grpc_socket_factory_bind(grpc_socket_factory* factory, int sockfd,
int grpc_socket_factory_compare(grpc_socket_factory* a,
grpc_socket_factory* b) {
int c = grpc_core::QsortCompare(a, b);
int c = GPR_ICMP(a, b);
if (c != 0) {
grpc_socket_factory* sma = a;
grpc_socket_factory* smb = b;
c = grpc_core::QsortCompare(sma->vtable, smb->vtable);
c = GPR_ICMP(sma->vtable, smb->vtable);
if (c == 0) {
c = sma->vtable->compare(sma, smb);
}

@ -56,11 +56,11 @@ bool grpc_socket_mutator_mutate_fd(grpc_socket_mutator* mutator, int fd,
int grpc_socket_mutator_compare(grpc_socket_mutator* a,
grpc_socket_mutator* b) {
int c = grpc_core::QsortCompare(a, b);
int c = GPR_ICMP(a, b);
if (c != 0) {
grpc_socket_mutator* sma = a;
grpc_socket_mutator* smb = b;
c = grpc_core::QsortCompare(sma->vtable, smb->vtable);
c = GPR_ICMP(sma->vtable, smb->vtable);
if (c == 0) {
c = sma->vtable->compare(sma, smb);
}

@ -576,7 +576,7 @@ static void finish_estimate(grpc_tcp* tcp) {
value */
if (tcp->bytes_read_this_round > tcp->target_length * 0.8) {
tcp->target_length =
std::max(2 * tcp->target_length, tcp->bytes_read_this_round);
GPR_MAX(2 * tcp->target_length, tcp->bytes_read_this_round);
} else {
tcp->target_length =
0.99 * tcp->target_length + 0.01 * tcp->bytes_read_this_round;
@ -1722,8 +1722,8 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd,
if (tcp_min_read_chunk_size > tcp_max_read_chunk_size) {
tcp_min_read_chunk_size = tcp_max_read_chunk_size;
}
tcp_read_chunk_size = grpc_core::Clamp(
tcp_read_chunk_size, tcp_min_read_chunk_size, tcp_max_read_chunk_size);
tcp_read_chunk_size = GPR_CLAMP(tcp_read_chunk_size, tcp_min_read_chunk_size,
tcp_max_read_chunk_size);
grpc_tcp* tcp = new grpc_tcp(tcp_tx_zerocopy_max_simult_sends,
tcp_tx_zerocopy_send_bytes_thresh);

@ -43,7 +43,7 @@
#define ADD_DEADLINE_SCALE 0.33
#define MIN_QUEUE_WINDOW_DURATION 0.01
#define MAX_QUEUE_WINDOW_DURATION 1.0
#define MAX_QUEUE_WINDOW_DURATION 1
grpc_core::TraceFlag grpc_timer_trace(false, "timer");
grpc_core::TraceFlag grpc_timer_check_trace(false, "timer_check");
@ -105,7 +105,7 @@ static void destroy_timer_ht() {
}
static bool is_in_ht(grpc_timer* t) {
size_t i = grpc_core::HashPointer(t, NUM_HASH_BUCKETS);
size_t i = GPR_HASH_POINTER(t, NUM_HASH_BUCKETS);
gpr_mu_lock(&g_hash_mu[i]);
grpc_timer* p = g_timer_ht[i];
@ -119,7 +119,7 @@ static bool is_in_ht(grpc_timer* t) {
static void add_to_ht(grpc_timer* t) {
GPR_ASSERT(!t->hash_table_next);
size_t i = grpc_core::HashPointer(t, NUM_HASH_BUCKETS);
size_t i = GPR_HASH_POINTER(t, NUM_HASH_BUCKETS);
gpr_mu_lock(&g_hash_mu[i]);
grpc_timer* p = g_timer_ht[i];
@ -144,7 +144,7 @@ static void add_to_ht(grpc_timer* t) {
}
static void remove_from_ht(grpc_timer* t) {
size_t i = grpc_core::HashPointer(t, NUM_HASH_BUCKETS);
size_t i = GPR_HASH_POINTER(t, NUM_HASH_BUCKETS);
bool removed = false;
gpr_mu_lock(&g_hash_mu[i]);
@ -248,7 +248,7 @@ static grpc_millis compute_min_deadline(timer_shard* shard) {
static void timer_list_init() {
uint32_t i;
g_num_shards = grpc_core::Clamp(2 * gpr_cpu_num_cores(), 1u, 32u);
g_num_shards = GPR_CLAMP(2 * gpr_cpu_num_cores(), 1, 32);
g_shards =
static_cast<timer_shard*>(gpr_zalloc(g_num_shards * sizeof(*g_shards)));
g_shard_queue = static_cast<timer_shard**>(
@ -337,7 +337,7 @@ void grpc_timer_init_unset(grpc_timer* timer) { timer->pending = false; }
static void timer_init(grpc_timer* timer, grpc_millis deadline,
grpc_closure* closure) {
int is_first_timer = 0;
timer_shard* shard = &g_shards[grpc_core::HashPointer(timer, g_num_shards)];
timer_shard* shard = &g_shards[GPR_HASH_POINTER(timer, g_num_shards)];
timer->closure = closure;
timer->deadline = deadline;
@ -444,7 +444,7 @@ static void timer_cancel(grpc_timer* timer) {
return;
}
timer_shard* shard = &g_shards[grpc_core::HashPointer(timer, g_num_shards)];
timer_shard* shard = &g_shards[GPR_HASH_POINTER(timer, g_num_shards)];
gpr_mu_lock(&shard->mu);
if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_trace)) {
gpr_log(GPR_INFO, "TIMER %p: CANCEL pending=%s", timer,
@ -479,13 +479,13 @@ static bool refill_heap(timer_shard* shard, grpc_millis now) {
grpc_time_averaged_stats_update_average(&shard->stats) *
ADD_DEADLINE_SCALE;
double deadline_delta =
grpc_core::Clamp(computed_deadline_delta, MIN_QUEUE_WINDOW_DURATION,
MAX_QUEUE_WINDOW_DURATION);
GPR_CLAMP(computed_deadline_delta, MIN_QUEUE_WINDOW_DURATION,
MAX_QUEUE_WINDOW_DURATION);
grpc_timer *timer, *next;
/* Compute the new cap and put all timers under it into the queue: */
shard->queue_deadline_cap =
saturating_add(std::max(now, shard->queue_deadline_cap),
saturating_add(GPR_MAX(now, shard->queue_deadline_cap),
static_cast<grpc_millis>(deadline_delta * 1000.0));
if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
@ -583,7 +583,7 @@ static grpc_timer_check_result run_some_expired_timers(
g_last_seen_min_timer = min_timer;
if (now < min_timer) {
if (next != nullptr) *next = std::min(*next, min_timer);
if (next != nullptr) *next = GPR_MIN(*next, min_timer);
return GRPC_TIMERS_CHECKED_AND_EMPTY;
}
@ -628,7 +628,7 @@ static grpc_timer_check_result run_some_expired_timers(
}
if (next) {
*next = std::min(*next, g_shard_queue[0]->min_deadline);
*next = GPR_MIN(*next, g_shard_queue[0]->min_deadline);
}
#if GPR_ARCH_64
@ -663,7 +663,7 @@ static grpc_timer_check_result timer_check(grpc_millis* next) {
if (now < min_timer) {
if (next != nullptr) {
*next = std::min(*next, min_timer);
*next = GPR_MIN(*next, min_timer);
}
if (GRPC_TRACE_FLAG_ENABLED(grpc_timer_check_trace)) {
gpr_log(GPR_INFO, "TIMER CHECK SKIP: now=%" PRId64 " min_timer=%" PRId64,

@ -97,7 +97,7 @@ void grpc_timer_heap_destroy(grpc_timer_heap* heap) { gpr_free(heap->timers); }
bool grpc_timer_heap_add(grpc_timer_heap* heap, grpc_timer* timer) {
if (heap->timer_count == heap->timer_capacity) {
heap->timer_capacity =
std::max(heap->timer_capacity + 1, heap->timer_capacity * 3 / 2);
GPR_MAX(heap->timer_capacity + 1, heap->timer_capacity * 3 / 2);
heap->timers = static_cast<grpc_timer**>(
gpr_realloc(heap->timers, heap->timer_capacity * sizeof(grpc_timer*)));
}

@ -33,7 +33,7 @@ void ProviderArgDestroy(void* p) {
provider->Unref();
}
int ProviderArgCmp(void* p, void* q) { return grpc_core::QsortCompare(p, q); }
int ProviderArgCmp(void* p, void* q) { return GPR_ICMP(p, q); }
} // namespace

@ -20,6 +20,7 @@
#include "absl/strings/str_format.h"
#include "absl/strings/strip.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/matchers/matchers.h"
namespace grpc_core {

@ -223,7 +223,7 @@ grpc_auth_property_iterator grpc_auth_context_peer_identity(
void grpc_auth_context::ensure_capacity() {
if (properties_.count == properties_.capacity) {
properties_.capacity =
std::max(properties_.capacity + 8, properties_.capacity * 2);
GPR_MAX(properties_.capacity + 8, properties_.capacity * 2);
properties_.array = static_cast<grpc_auth_property*>(gpr_realloc(
properties_.array, properties_.capacity * sizeof(grpc_auth_property)));
}
@ -289,9 +289,7 @@ static void* auth_context_pointer_arg_copy(void* p) {
: ctx->Ref(DEBUG_LOCATION, "auth_context_pointer_arg").release();
}
static int auth_context_pointer_cmp(void* a, void* b) {
return grpc_core::QsortCompare(a, b);
}
static int auth_context_pointer_cmp(void* a, void* b) { return GPR_ICMP(a, b); }
static const grpc_arg_pointer_vtable auth_context_pointer_vtable = {
auth_context_pointer_arg_copy, auth_context_pointer_arg_destroy,

@ -59,9 +59,7 @@ static void* credentials_pointer_arg_copy(void* p) {
return static_cast<grpc_channel_credentials*>(p)->Ref().release();
}
static int credentials_pointer_cmp(void* a, void* b) {
return grpc_core::QsortCompare(a, b);
}
static int credentials_pointer_cmp(void* a, void* b) { return GPR_ICMP(a, b); }
static const grpc_arg_pointer_vtable credentials_pointer_vtable = {
credentials_pointer_arg_copy, credentials_pointer_arg_destroy,
@ -129,7 +127,7 @@ static void* server_credentials_pointer_arg_copy(void* p) {
}
static int server_credentials_pointer_cmp(void* a, void* b) {
return grpc_core::QsortCompare(a, b);
return GPR_ICMP(a, b);
}
static const grpc_arg_pointer_vtable cred_ptr_vtable = {

@ -92,12 +92,12 @@ class grpc_fake_channel_security_connector final
c = strcmp(target_, other->target_);
if (c != 0) return c;
if (expected_targets_ == nullptr || other->expected_targets_ == nullptr) {
c = grpc_core::QsortCompare(expected_targets_, other->expected_targets_);
c = GPR_ICMP(expected_targets_, other->expected_targets_);
} else {
c = strcmp(expected_targets_, other->expected_targets_);
}
if (c != 0) return c;
return grpc_core::QsortCompare(is_lb_channel_, other->is_lb_channel_);
return GPR_ICMP(is_lb_channel_, other->is_lb_channel_);
}
void add_handshakers(const grpc_channel_args* args,

@ -60,9 +60,7 @@ grpc_channel_security_connector::~grpc_channel_security_connector() {}
int grpc_security_connector_cmp(const grpc_security_connector* sc,
const grpc_security_connector* other) {
if (sc == nullptr || other == nullptr) {
return grpc_core::QsortCompare(sc, other);
}
if (sc == nullptr || other == nullptr) return GPR_ICMP(sc, other);
return sc->cmp(other);
}
@ -72,10 +70,9 @@ int grpc_channel_security_connector::channel_security_connector_cmp(
static_cast<const grpc_channel_security_connector*>(other);
GPR_ASSERT(channel_creds() != nullptr);
GPR_ASSERT(other_sc->channel_creds() != nullptr);
int c = grpc_core::QsortCompare(channel_creds(), other_sc->channel_creds());
int c = GPR_ICMP(channel_creds(), other_sc->channel_creds());
if (c != 0) return c;
return grpc_core::QsortCompare(request_metadata_creds(),
other_sc->request_metadata_creds());
return GPR_ICMP(request_metadata_creds(), other_sc->request_metadata_creds());
}
int grpc_server_security_connector::server_security_connector_cmp(
@ -84,7 +81,7 @@ int grpc_server_security_connector::server_security_connector_cmp(
static_cast<const grpc_server_security_connector*>(other);
GPR_ASSERT(server_creds() != nullptr);
GPR_ASSERT(other_sc->server_creds() != nullptr);
return grpc_core::QsortCompare(server_creds(), other_sc->server_creds());
return GPR_ICMP(server_creds(), other_sc->server_creds());
}
static void connector_arg_destroy(void* p) {

@ -523,7 +523,7 @@ static void grpc_ssl_session_cache_arg_destroy(void* p) {
}
static int grpc_ssl_session_cache_arg_cmp(void* p, void* q) {
return grpc_core::QsortCompare(p, q);
return GPR_ICMP(p, q);
}
grpc_arg grpc_ssl_session_cache_create_channel_arg(

@ -103,7 +103,7 @@ static grpc_metadata_array metadata_batch_to_md_array(
grpc_slice key = GRPC_MDKEY(md);
grpc_slice value = GRPC_MDVALUE(md);
if (result.count == result.capacity) {
result.capacity = std::max(result.capacity + 8, result.capacity * 2);
result.capacity = GPR_MAX(result.capacity + 8, result.capacity * 2);
result.metadata = static_cast<grpc_metadata*>(gpr_realloc(
result.metadata, result.capacity * sizeof(grpc_metadata)));
}

@ -231,19 +231,19 @@ void grpc_slice_buffer_swap(grpc_slice_buffer* a, grpc_slice_buffer* b) {
memcpy(a->base_slices, b->inlined, b_count * sizeof(grpc_slice));
} else {
/* no inlining: easy swap */
std::swap(a->base_slices, b->base_slices);
GPR_SWAP(grpc_slice*, a->base_slices, b->base_slices);
}
/* Update the slices pointers (cannot do a std::swap on slices fields here).
/* Update the slices pointers (cannot do a GPR_SWAP on slices fields here).
* Also note that since the base_slices pointers are already swapped we need
* use 'b_offset' for 'a->base_slices' and vice versa */
a->slices = a->base_slices + b_offset;
b->slices = b->base_slices + a_offset;
/* base_slices and slices fields are correctly set. Swap all other fields */
std::swap(a->count, b->count);
std::swap(a->capacity, b->capacity);
std::swap(a->length, b->length);
GPR_SWAP(size_t, a->count, b->count);
GPR_SWAP(size_t, a->capacity, b->capacity);
GPR_SWAP(size_t, a->length, b->length);
}
void grpc_slice_buffer_move_into(grpc_slice_buffer* src,

@ -407,7 +407,7 @@ grpc_error_handle grpc_call_create(const grpc_call_create_args* args,
GPR_ASSERT(!args->parent->is_client);
if (args->propagation_mask & GRPC_PROPAGATE_DEADLINE) {
send_deadline = std::min(send_deadline, args->parent->send_deadline);
send_deadline = GPR_MIN(send_deadline, args->parent->send_deadline);
}
/* for now GRPC_PROPAGATE_TRACING_CONTEXT *MUST* be passed with
* GRPC_PROPAGATE_STATS_CONTEXT */
@ -848,7 +848,7 @@ static void set_encodings_accepted_by_peer(grpc_call* /*call*/,
grpc_slice_split_without_space(accept_encoding_slice, ",",
&accept_encoding_parts);
grpc_core::SetBit(encodings_accepted_by_peer, GRPC_COMPRESS_NONE);
GPR_BITSET(encodings_accepted_by_peer, GRPC_COMPRESS_NONE);
for (i = 0; i < accept_encoding_parts.count; i++) {
int r;
grpc_slice accept_encoding_entry_slice = accept_encoding_parts.slices[i];
@ -862,7 +862,7 @@ static void set_encodings_accepted_by_peer(grpc_call* /*call*/,
reinterpret_cast<grpc_stream_compression_algorithm*>(&algorithm));
}
if (r) {
grpc_core::SetBit(encodings_accepted_by_peer, algorithm);
GPR_BITSET(encodings_accepted_by_peer, algorithm);
} else {
char* accept_encoding_entry_str =
grpc_slice_to_c_string(accept_encoding_entry_slice);
@ -1008,8 +1008,8 @@ static void publish_app_metadata(grpc_call* call, grpc_metadata_batch* b,
grpc_metadata* mdusr;
dest = call->buffered_metadata[is_trailing];
if (dest->count + (*b)->non_deadline_count() > dest->capacity) {
dest->capacity = std::max(dest->capacity + (*b)->non_deadline_count(),
dest->capacity * 3 / 2);
dest->capacity = GPR_MAX(dest->capacity + (*b)->non_deadline_count(),
dest->capacity * 3 / 2);
dest->metadata = static_cast<grpc_metadata*>(
gpr_realloc(dest->metadata, sizeof(grpc_metadata) * dest->capacity));
}
@ -1463,8 +1463,8 @@ static void validate_filtered_metadata(batch_control* bctl) {
}
/* GRPC_COMPRESS_NONE is always set. */
GPR_DEBUG_ASSERT(call->encodings_accepted_by_peer != 0);
if (GPR_UNLIKELY(!grpc_core::GetBit(call->encodings_accepted_by_peer,
compression_algorithm))) {
if (GPR_UNLIKELY(!GPR_BITGET(call->encodings_accepted_by_peer,
compression_algorithm))) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_compression_trace)) {
handle_compression_algorithm_not_accepted(call, compression_algorithm);
}

@ -187,9 +187,7 @@ void channelz_node_destroy(void* p) {
static_cast<grpc_core::channelz::ChannelNode*>(p);
node->Unref();
}
int channelz_node_cmp(void* p1, void* p2) {
return grpc_core::QsortCompare(p1, p2);
}
int channelz_node_cmp(void* p1, void* p2) { return GPR_ICMP(p1, p2); }
const grpc_arg_pointer_vtable channelz_node_arg_vtable = {
channelz_node_copy, channelz_node_destroy, channelz_node_cmp};
@ -323,7 +321,7 @@ void grpc_channel_update_call_size_estimate(grpc_channel* channel,
/* size shrank: decrease estimate */
gpr_atm_no_barrier_cas(
&channel->call_size_estimate, static_cast<gpr_atm>(cur),
static_cast<gpr_atm>(std::min(cur - 1, (255 * cur + size) / 256)));
static_cast<gpr_atm>(GPR_MIN(cur - 1, (255 * cur + size) / 256)));
/* if we lose: never mind, something else will likely update soon enough */
}
}

@ -53,8 +53,7 @@ void grpc_channel_init_register_stage(grpc_channel_stack_type type,
void* stage_arg) {
GPR_ASSERT(!g_finalized);
if (g_slots[type].cap_slots == g_slots[type].num_slots) {
g_slots[type].cap_slots =
std::max(size_t(8), 3 * g_slots[type].cap_slots / 2);
g_slots[type].cap_slots = GPR_MAX(8, 3 * g_slots[type].cap_slots / 2);
g_slots[type].slots = static_cast<stage_slot*>(
gpr_realloc(g_slots[type].slots,
g_slots[type].cap_slots * sizeof(*g_slots[type].slots)));
@ -70,9 +69,9 @@ static int compare_slots(const void* a, const void* b) {
const stage_slot* sa = static_cast<const stage_slot*>(a);
const stage_slot* sb = static_cast<const stage_slot*>(b);
int c = grpc_core::QsortCompare(sa->priority, sb->priority);
int c = GPR_ICMP(sa->priority, sb->priority);
if (c != 0) return c;
return grpc_core::QsortCompare(sa->insertion_order, sb->insertion_order);
return GPR_ICMP(sa->insertion_order, sb->insertion_order);
}
void grpc_channel_init_finalize(void) {

@ -628,8 +628,8 @@ static void cq_check_tag(grpc_completion_queue* cq, void* tag, bool lock_cq) {
for (int i = 0; i < static_cast<int>(cq->outstanding_tag_count); i++) {
if (cq->outstanding_tags[i] == tag) {
cq->outstanding_tag_count--;
std::swap(cq->outstanding_tags[i],
cq->outstanding_tags[cq->outstanding_tag_count]);
GPR_SWAP(void*, cq->outstanding_tags[i],
cq->outstanding_tags[cq->outstanding_tag_count]);
found = 1;
break;
}
@ -665,8 +665,7 @@ bool grpc_cq_begin_op(grpc_completion_queue* cq, void* tag) {
#ifndef NDEBUG
gpr_mu_lock(cq->mu);
if (cq->outstanding_tag_count == cq->outstanding_tag_capacity) {
cq->outstanding_tag_capacity =
std::max(size_t(4), 2 * cq->outstanding_tag_capacity);
cq->outstanding_tag_capacity = GPR_MAX(4, 2 * cq->outstanding_tag_capacity);
cq->outstanding_tags = static_cast<void**>(gpr_realloc(
cq->outstanding_tags,
sizeof(*cq->outstanding_tags) * cq->outstanding_tag_capacity));
@ -1144,7 +1143,7 @@ static void del_plucker(grpc_completion_queue* cq, void* tag,
for (int i = 0; i < cqd->num_pluckers; i++) {
if (cqd->pluckers[i].tag == tag && cqd->pluckers[i].worker == worker) {
cqd->num_pluckers--;
std::swap(cqd->pluckers[i], cqd->pluckers[cqd->num_pluckers]);
GPR_SWAP(plucker, cqd->pluckers[i], cqd->pluckers[cqd->num_pluckers]);
return;
}
}

@ -140,7 +140,7 @@ void ErrorDestroy(void* p) {
delete error;
}
}
int ErrorCompare(void* p, void* q) { return grpc_core::QsortCompare(p, q); }
int ErrorCompare(void* p, void* q) { return GPR_ICMP(p, q); }
const grpc_arg_pointer_vtable kLameFilterErrorArgVtable = {
ErrorCopy, ErrorDestroy, ErrorCompare};

@ -1248,7 +1248,7 @@ void Server::CallData::Publish(size_t cq_idx, RequestedCall* rc) {
grpc_call_set_completion_queue(call_, rc->cq_bound_to_call);
*rc->call = call_;
cq_new_ = server_->cqs_[cq_idx];
std::swap(*rc->initial_metadata, initial_metadata_);
GPR_SWAP(grpc_metadata_array, *rc->initial_metadata, initial_metadata_);
switch (rc->type) {
case RequestedCall::Type::BATCH_CALL:
GPR_ASSERT(host_.has_value());

@ -55,7 +55,7 @@ grpc_millis BdpEstimator::CompletePing() {
}
GPR_ASSERT(ping_state_ == PingState::STARTED);
if (accumulator_ > 2 * estimate_ / 3 && bw > bw_est_) {
estimate_ = std::max(accumulator_, estimate_ * 2);
estimate_ = GPR_MAX(accumulator_, estimate_ * 2);
bw_est_ = bw;
if (GRPC_TRACE_FLAG_ENABLED(grpc_bdp_estimator_trace)) {
gpr_log(GPR_INFO, "bdp[%s]: estimate increased to %" PRId64, name_,

@ -409,8 +409,7 @@ inline void grpc_mdelem_unref(grpc_mdelem gmd) {
(GRPC_SLICE_LENGTH(GRPC_MDKEY((e))) + GRPC_SLICE_LENGTH(GRPC_MDVALUE((e))) + \
32)
#define GRPC_MDSTR_KV_HASH(k_hash, v_hash) \
(::grpc_core::RotateLeft(size_t(k_hash), size_t(2)) ^ (v_hash))
#define GRPC_MDSTR_KV_HASH(k_hash, v_hash) (GPR_ROTL((k_hash), 2) ^ (v_hash))
void grpc_mdctx_global_init(void);
void grpc_mdctx_global_shutdown();

@ -31,8 +31,8 @@ double PidController::Update(double error, double dt) {
if (dt <= 0) return last_control_value_;
/* integrate error using the trapezoid rule */
error_integral_ += dt * (last_error_ + error) * 0.5;
error_integral_ = grpc_core::Clamp(error_integral_, -args_.integral_range(),
args_.integral_range());
error_integral_ = GPR_CLAMP(error_integral_, -args_.integral_range(),
args_.integral_range());
double diff_error = (error - last_error_) / dt;
/* calculate derivative of control value vs time */
double dc_dt = args_.gain_p() * error + args_.gain_i() * error_integral_ +
@ -40,8 +40,8 @@ double PidController::Update(double error, double dt) {
/* and perform trapezoidal integration */
double new_control_value =
last_control_value_ + dt * (last_dc_dt_ + dc_dt) * 0.5;
new_control_value = grpc_core::Clamp(
new_control_value, args_.min_control_value(), args_.max_control_value());
new_control_value = GPR_CLAMP(new_control_value, args_.min_control_value(),
args_.max_control_value());
last_error_ = error;
last_dc_dt_ = dc_dt;
last_control_value_ = new_control_value;

@ -23,8 +23,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -158,10 +156,10 @@ static tsi_result alts_protect(tsi_frame_protector* self,
*/
if (impl->in_place_protect_bytes_buffered + impl->overhead_length <
max_encrypted_payload_bytes(impl)) {
size_t bytes_to_buffer = std::min(
*unprotected_bytes_size, max_encrypted_payload_bytes(impl) -
impl->in_place_protect_bytes_buffered -
impl->overhead_length);
size_t bytes_to_buffer = GPR_MIN(*unprotected_bytes_size,
max_encrypted_payload_bytes(impl) -
impl->in_place_protect_bytes_buffered -
impl->overhead_length);
*unprotected_bytes_size = bytes_to_buffer;
if (bytes_to_buffer > 0) {
memcpy(
@ -268,9 +266,9 @@ static tsi_result alts_unprotect(tsi_frame_protector* self,
if (!alts_is_frame_reader_done(impl->reader)) {
ensure_buffer_size(impl);
*protected_frames_bytes_size =
std::min(impl->max_unprotected_frame_size -
alts_get_output_bytes_read(impl->reader),
*protected_frames_bytes_size);
GPR_MIN(impl->max_unprotected_frame_size -
alts_get_output_bytes_read(impl->reader),
*protected_frames_bytes_size);
size_t read_frames_bytes_size = *protected_frames_bytes_size;
if (!alts_read_frame_bytes(impl->reader, protected_frames_bytes,
&read_frames_bytes_size)) {
@ -292,7 +290,7 @@ static tsi_result alts_unprotect(tsi_frame_protector* self,
return result;
}
}
size_t bytes_to_write = std::min(
size_t bytes_to_write = GPR_MIN(
*unprotected_bytes_size, alts_get_output_bytes_read(impl->reader) -
impl->in_place_unprotect_bytes_processed -
impl->overhead_length);
@ -387,9 +385,9 @@ tsi_result alts_create_frame_protector(const uint8_t* key, size_t key_size,
size_t max_protected_frame_size_to_set = kDefaultFrameLength;
if (max_protected_frame_size != nullptr) {
*max_protected_frame_size =
std::min(*max_protected_frame_size, kMaxFrameLength);
GPR_MIN(*max_protected_frame_size, kMaxFrameLength);
*max_protected_frame_size =
std::max(*max_protected_frame_size, kMinFrameLength);
GPR_MAX(*max_protected_frame_size, kMinFrameLength);
max_protected_frame_size_to_set = *max_protected_frame_size;
}
impl->max_protected_frame_size = max_protected_frame_size_to_set;

@ -24,11 +24,11 @@
#include <stdint.h>
#include <string.h>
#include <algorithm>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/gpr/useful.h"
/* Use little endian to interpret a string of bytes as uint32_t. */
static uint32_t load_32_le(const unsigned char* buffer) {
return (static_cast<uint32_t>(buffer[3]) << 24) |
@ -82,8 +82,8 @@ bool alts_write_frame_bytes(alts_frame_writer* writer, unsigned char* output,
/* Write some header bytes, if needed. */
if (writer->header_bytes_written != sizeof(writer->header_buffer)) {
size_t bytes_to_write =
std::min(*bytes_size,
sizeof(writer->header_buffer) - writer->header_bytes_written);
GPR_MIN(*bytes_size,
sizeof(writer->header_buffer) - writer->header_bytes_written);
memcpy(output, writer->header_buffer + writer->header_bytes_written,
bytes_to_write);
bytes_written += bytes_to_write;
@ -97,7 +97,7 @@ bool alts_write_frame_bytes(alts_frame_writer* writer, unsigned char* output,
}
/* Write some non-header bytes. */
size_t bytes_to_write =
std::min(writer->input_size - writer->input_bytes_written, *bytes_size);
GPR_MIN(writer->input_size - writer->input_bytes_written, *bytes_size);
memcpy(output, writer->input_buffer, bytes_to_write);
writer->input_buffer += bytes_to_write;
bytes_written += bytes_to_write;
@ -167,7 +167,7 @@ bool alts_read_frame_bytes(alts_frame_reader* reader,
size_t bytes_processed = 0;
/* Process the header, if needed. */
if (reader->header_bytes_read != sizeof(reader->header_buffer)) {
size_t bytes_to_write = std::min(
size_t bytes_to_write = GPR_MIN(
*bytes_size, sizeof(reader->header_buffer) - reader->header_bytes_read);
memcpy(reader->header_buffer + reader->header_bytes_read, bytes,
bytes_to_write);
@ -199,7 +199,7 @@ bool alts_read_frame_bytes(alts_frame_reader* reader,
reader->bytes_remaining = frame_length - kFrameMessageTypeFieldSize;
}
/* Process the non-header bytes. */
size_t bytes_to_write = std::min(*bytes_size, reader->bytes_remaining);
size_t bytes_to_write = GPR_MIN(*bytes_size, reader->bytes_remaining);
memcpy(reader->output_buffer, bytes, bytes_to_write);
reader->output_buffer += bytes_to_write;
bytes_processed += bytes_to_write;

@ -39,7 +39,7 @@ static void ensure_iovec_buf_size(alts_grpc_record_protocol* rp,
return;
}
/* At least double the iovec buffer size. */
rp->iovec_buf_length = std::max(sb->count, 2 * rp->iovec_buf_length);
rp->iovec_buf_length = GPR_MAX(sb->count, 2 * rp->iovec_buf_length);
rp->iovec_buf = static_cast<iovec_t*>(
gpr_realloc(rp->iovec_buf, rp->iovec_buf_length * sizeof(iovec_t)));
}

@ -278,9 +278,9 @@ tsi_result alts_zero_copy_grpc_protector_create(
size_t max_protected_frame_size_to_set = kDefaultFrameLength;
if (max_protected_frame_size != nullptr) {
*max_protected_frame_size =
std::min(*max_protected_frame_size, kMaxFrameLength);
GPR_MIN(*max_protected_frame_size, kMaxFrameLength);
*max_protected_frame_size =
std::max(*max_protected_frame_size, kMinFrameLength);
GPR_MAX(*max_protected_frame_size, kMinFrameLength);
max_protected_frame_size_to_set = *max_protected_frame_size;
}
impl->max_protected_frame_size = max_protected_frame_size_to_set;

@ -416,8 +416,8 @@ static tsi_result fake_zero_copy_grpc_protector_protect(
/* Protects each frame. */
while (unprotected_slices->length > 0) {
size_t frame_length =
std::min(impl->max_frame_size,
unprotected_slices->length + TSI_FAKE_FRAME_HEADER_SIZE);
GPR_MIN(impl->max_frame_size,
unprotected_slices->length + TSI_FAKE_FRAME_HEADER_SIZE);
grpc_slice slice = GRPC_SLICE_MALLOC(TSI_FAKE_FRAME_HEADER_SIZE);
store32_little_endian(static_cast<uint32_t>(frame_length),
GRPC_SLICE_START_PTR(slice));

@ -52,8 +52,7 @@ struct CallbackAlternativeCQ {
refs++;
if (refs == 1) {
cq = new CompletionQueue;
int num_nexting_threads =
grpc_core::Clamp(gpr_cpu_num_cores() / 2, 2u, 16u);
int num_nexting_threads = GPR_CLAMP(gpr_cpu_num_cores() / 2, 2, 16);
nexting_threads = new std::vector<grpc_core::Thread>;
for (int i = 0; i < num_nexting_threads; i++) {
nexting_threads->emplace_back(

@ -167,9 +167,9 @@ ServerBuilder& ServerBuilder::SetSyncServerOption(
ServerBuilder& ServerBuilder::SetCompressionAlgorithmSupportStatus(
grpc_compression_algorithm algorithm, bool enabled) {
if (enabled) {
grpc_core::SetBit(&enabled_compression_algorithms_bitset_, algorithm);
GPR_BITSET(&enabled_compression_algorithms_bitset_, algorithm);
} else {
grpc_core::ClearBit(&enabled_compression_algorithms_bitset_, algorithm);
GPR_BITCLEAR(&enabled_compression_algorithms_bitset_, algorithm);
}
return *this;
}

@ -99,7 +99,7 @@ size_t g_count = 0;
static void addbuf(const void* data, size_t len) {
if (g_count + len > g_cap) {
g_cap = std::max(g_count + len, g_cap * 2);
g_cap = GPR_MAX(g_count + len, g_cap * 2);
g_buffer = static_cast<char*>(gpr_realloc(g_buffer, g_cap));
}
memcpy(g_buffer + g_count, data, len);

@ -56,7 +56,7 @@ size_t g_count = 0;
static void addbuf(const void* data, size_t len) {
if (g_count + len > g_cap) {
g_cap = std::max(g_count + len, g_cap * 2);
g_cap = GPR_MAX(g_count + len, g_cap * 2);
g_buffer = static_cast<char*>(gpr_realloc(g_buffer, g_cap));
}
memcpy(g_buffer + g_count, data, len);

@ -72,9 +72,7 @@ static void fake_pointer_arg_destroy(void* arg) {
gpr_free(fc);
}
static int fake_pointer_cmp(void* a, void* b) {
return grpc_core::QsortCompare(a, b);
}
static int fake_pointer_cmp(void* a, void* b) { return GPR_ICMP(a, b); }
static const grpc_arg_pointer_vtable fake_pointer_arg_vtable = {
fake_pointer_arg_copy, fake_pointer_arg_destroy, fake_pointer_cmp};

@ -88,7 +88,7 @@ static void test_compression_algorithm_for_level(void) {
{
/* accept only identity (aka none) */
uint32_t accepted_encodings = 0;
grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
GPR_ASSERT(GRPC_COMPRESS_NONE ==
grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE,
@ -110,8 +110,8 @@ static void test_compression_algorithm_for_level(void) {
{
/* accept only gzip */
uint32_t accepted_encodings = 0;
grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_GZIP);
GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_GZIP);
GPR_ASSERT(GRPC_COMPRESS_NONE ==
grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE,
@ -133,8 +133,8 @@ static void test_compression_algorithm_for_level(void) {
{
/* accept only deflate */
uint32_t accepted_encodings = 0;
grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_DEFLATE);
GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_DEFLATE);
GPR_ASSERT(GRPC_COMPRESS_NONE ==
grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE,
@ -156,9 +156,9 @@ static void test_compression_algorithm_for_level(void) {
{
/* accept gzip and deflate */
uint32_t accepted_encodings = 0;
grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_GZIP);
grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_DEFLATE);
GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_GZIP);
GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_DEFLATE);
GPR_ASSERT(GRPC_COMPRESS_NONE ==
grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE,
@ -180,8 +180,8 @@ static void test_compression_algorithm_for_level(void) {
{
/* accept stream gzip */
uint32_t accepted_encodings = 0;
grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_STREAM_GZIP);
GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_STREAM_GZIP);
GPR_ASSERT(GRPC_COMPRESS_NONE ==
grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE,
@ -203,10 +203,10 @@ static void test_compression_algorithm_for_level(void) {
{
/* accept all algorithms */
uint32_t accepted_encodings = 0;
grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_GZIP);
grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_DEFLATE);
grpc_core::SetBit(&accepted_encodings, GRPC_COMPRESS_STREAM_GZIP);
GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_NONE); /* always */
GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_GZIP);
GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_DEFLATE);
GPR_BITSET(&accepted_encodings, GRPC_COMPRESS_STREAM_GZIP);
GPR_ASSERT(GRPC_COMPRESS_NONE ==
grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE,
@ -288,7 +288,7 @@ static void test_channel_args_compression_algorithm_states(void) {
grpc_channel_args_compression_algorithm_get_states(ch_args));
for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) {
GPR_ASSERT(grpc_core::GetBit(states_bitset, i));
GPR_ASSERT(GPR_BITGET(states_bitset, i));
}
/* disable gzip and deflate and stream/gzip */
@ -309,9 +309,9 @@ static void test_channel_args_compression_algorithm_states(void) {
for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) {
if (i == GRPC_COMPRESS_GZIP || i == GRPC_COMPRESS_DEFLATE ||
i == GRPC_COMPRESS_STREAM_GZIP) {
GPR_ASSERT(grpc_core::GetBit(states_bitset, i) == 0);
GPR_ASSERT(GPR_BITGET(states_bitset, i) == 0);
} else {
GPR_ASSERT(grpc_core::GetBit(states_bitset, i) != 0);
GPR_ASSERT(GPR_BITGET(states_bitset, i) != 0);
}
}
@ -326,9 +326,9 @@ static void test_channel_args_compression_algorithm_states(void) {
grpc_channel_args_compression_algorithm_get_states(ch_args_wo_gzip));
for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) {
if (i == GRPC_COMPRESS_DEFLATE) {
GPR_ASSERT(grpc_core::GetBit(states_bitset, i) == 0);
GPR_ASSERT(GPR_BITGET(states_bitset, i) == 0);
} else {
GPR_ASSERT(grpc_core::GetBit(states_bitset, i) != 0);
GPR_ASSERT(GPR_BITGET(states_bitset, i) != 0);
}
}

@ -353,7 +353,8 @@ static void on_new_call(void* arg, int success) {
proxy_call* pc = static_cast<proxy_call*>(gpr_malloc(sizeof(*pc)));
memset(pc, 0, sizeof(*pc));
pc->proxy = proxy;
std::swap(pc->c2p_initial_metadata, proxy->new_call_metadata);
GPR_SWAP(grpc_metadata_array, pc->c2p_initial_metadata,
proxy->new_call_metadata);
pc->c2p = proxy->new_call;
pc->p2s = grpc_channel_create_call(
proxy->client, pc->c2p, GRPC_PROPAGATE_DEFAULTS, proxy->cq,

@ -399,17 +399,13 @@ static void request_with_payload_template_inner(
CQ_EXPECT_COMPLETION(cqv, tag(100), true);
cq_verify(cqv);
GPR_ASSERT(grpc_core::BitCount(
grpc_call_test_only_get_encodings_accepted_by_peer(s)) ==
GRPC_COMPRESS_ALGORITHMS_COUNT);
GPR_ASSERT(
grpc_core::GetBit(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GPR_ASSERT(GPR_BITCOUNT(grpc_call_test_only_get_encodings_accepted_by_peer(
s)) == GRPC_COMPRESS_ALGORITHMS_COUNT);
GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GRPC_COMPRESS_NONE) != 0);
GPR_ASSERT(
grpc_core::GetBit(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GRPC_COMPRESS_DEFLATE) != 0);
GPR_ASSERT(
grpc_core::GetBit(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GRPC_COMPRESS_GZIP) != 0);
memset(ops, 0, sizeof(ops));
op = ops;

@ -384,24 +384,18 @@ static void request_with_payload_template(
CQ_EXPECT_COMPLETION(cqv, tag(100), true);
cq_verify(cqv);
GPR_ASSERT(grpc_core::BitCount(
grpc_call_test_only_get_encodings_accepted_by_peer(s)) ==
GRPC_COMPRESS_ALGORITHMS_COUNT);
GPR_ASSERT(
grpc_core::GetBit(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GPR_ASSERT(GPR_BITCOUNT(grpc_call_test_only_get_encodings_accepted_by_peer(
s)) == GRPC_COMPRESS_ALGORITHMS_COUNT);
GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GRPC_COMPRESS_NONE) != 0);
GPR_ASSERT(
grpc_core::GetBit(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GRPC_COMPRESS_DEFLATE) != 0);
GPR_ASSERT(
grpc_core::GetBit(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GRPC_COMPRESS_GZIP) != 0);
GPR_ASSERT(
grpc_core::GetBit(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GRPC_COMPRESS_STREAM_GZIP) != 0);
GPR_ASSERT(grpc_core::BitCount(
grpc_call_test_only_get_encodings_accepted_by_peer(s)) ==
GRPC_COMPRESS_ALGORITHMS_COUNT);
GPR_ASSERT(GPR_BITCOUNT(grpc_call_test_only_get_encodings_accepted_by_peer(
s)) == GRPC_COMPRESS_ALGORITHMS_COUNT);
memset(ops, 0, sizeof(ops));
op = ops;

@ -212,17 +212,13 @@ static void request_with_payload_template(
CQ_EXPECT_COMPLETION(cqv, tag(100), true);
cq_verify(cqv);
GPR_ASSERT(grpc_core::BitCount(
grpc_call_test_only_get_encodings_accepted_by_peer(s)) ==
GRPC_COMPRESS_ALGORITHMS_COUNT);
GPR_ASSERT(
grpc_core::GetBit(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GPR_ASSERT(GPR_BITCOUNT(grpc_call_test_only_get_encodings_accepted_by_peer(
s)) == GRPC_COMPRESS_ALGORITHMS_COUNT);
GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GRPC_COMPRESS_NONE) != 0);
GPR_ASSERT(
grpc_core::GetBit(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GRPC_COMPRESS_DEFLATE) != 0);
GPR_ASSERT(
grpc_core::GetBit(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
GRPC_COMPRESS_GZIP) != 0);
memset(ops, 0, sizeof(ops));

@ -148,12 +148,10 @@ grpc_cc_test(
grpc_cc_test(
name = "useful_test",
srcs = ["useful_test.cc"],
external_deps = ["gtest"],
language = "C++",
uses_polling = False,
deps = [
"//:gpr_platform",
"//:useful",
"//test/core/util:grpc_suppressions",
"//:gpr",
"//test/core/util:grpc_test_util",
],
)

@ -16,54 +16,46 @@
*
*/
#include <grpc/impl/codegen/port_platform.h>
#include <grpc/support/port_platform.h>
#include "src/core/lib/gpr/useful.h"
#include <gtest/gtest.h>
#include <grpc/support/log.h>
namespace grpc_core {
#include "test/core/util/test_config.h"
TEST(UsefulTest, ClampWorks) {
EXPECT_EQ(grpc_core::Clamp(1, 0, 2), 1);
EXPECT_EQ(grpc_core::Clamp(0, 0, 2), 0);
EXPECT_EQ(grpc_core::Clamp(2, 0, 2), 2);
EXPECT_EQ(grpc_core::Clamp(-1, 0, 2), 0);
EXPECT_EQ(grpc_core::Clamp(3, 0, 2), 2);
}
TEST(UsefulTest, Rotate) {
EXPECT_EQ(grpc_core::RotateLeft(0x80000001u, 1u), 3);
EXPECT_EQ(grpc_core::RotateRight(0x80000001u, 1u), 0xc0000000);
}
TEST(UsefulTest, ArraySize) {
int main(int argc, char** argv) {
int four[4];
int five[5];
EXPECT_EQ(GPR_ARRAY_SIZE(four), 4);
EXPECT_EQ(GPR_ARRAY_SIZE(five), 5);
}
TEST(UsefulTest, BitOps) {
uint32_t bitset = 0;
EXPECT_EQ(grpc_core::BitCount((1u << 31) - 1), 31);
EXPECT_EQ(grpc_core::BitCount(1u << 3), 1);
EXPECT_EQ(grpc_core::BitCount(0), 0);
EXPECT_EQ(grpc_core::SetBit(&bitset, 3), 8);
EXPECT_EQ(grpc_core::BitCount(bitset), 1);
EXPECT_EQ(grpc_core::GetBit(bitset, 3), 1);
EXPECT_EQ(grpc_core::SetBit(&bitset, 1), 10);
EXPECT_EQ(grpc_core::BitCount(bitset), 2);
EXPECT_EQ(grpc_core::ClearBit(&bitset, 3), 2);
EXPECT_EQ(grpc_core::BitCount(bitset), 1);
EXPECT_EQ(grpc_core::GetBit(bitset, 3), 0);
}
} // namespace grpc_core
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
grpc::testing::TestEnvironment env(argc, argv);
GPR_ASSERT(GPR_MIN(1, 2) == 1);
GPR_ASSERT(GPR_MAX(1, 2) == 2);
GPR_ASSERT(GPR_MIN(2, 1) == 1);
GPR_ASSERT(GPR_MAX(2, 1) == 2);
GPR_ASSERT(GPR_CLAMP(1, 0, 2) == 1);
GPR_ASSERT(GPR_CLAMP(0, 0, 2) == 0);
GPR_ASSERT(GPR_CLAMP(2, 0, 2) == 2);
GPR_ASSERT(GPR_CLAMP(-1, 0, 2) == 0);
GPR_ASSERT(GPR_CLAMP(3, 0, 2) == 2);
GPR_ASSERT(GPR_ROTL((uint32_t)0x80000001, 1) == 3);
GPR_ASSERT(GPR_ROTR((uint32_t)0x80000001, 1) == 0xc0000000);
GPR_ASSERT(GPR_ARRAY_SIZE(four) == 4);
GPR_ASSERT(GPR_ARRAY_SIZE(five) == 5);
GPR_ASSERT(GPR_BITCOUNT((1u << 31) - 1) == 31);
GPR_ASSERT(GPR_BITCOUNT(1u << 3) == 1);
GPR_ASSERT(GPR_BITCOUNT(0) == 0);
GPR_ASSERT(GPR_BITSET(&bitset, 3) == 8);
GPR_ASSERT(GPR_BITCOUNT(bitset) == 1);
GPR_ASSERT(GPR_BITGET(bitset, 3) == 1);
GPR_ASSERT(GPR_BITSET(&bitset, 1) == 10);
GPR_ASSERT(GPR_BITCOUNT(bitset) == 2);
GPR_ASSERT(GPR_BITCLEAR(&bitset, 3) == 2);
GPR_ASSERT(GPR_BITCOUNT(bitset) == 1);
GPR_ASSERT(GPR_BITGET(bitset, 3) == 0);
return 0;
}

@ -347,7 +347,7 @@ void grpc_endpoint_tests(grpc_endpoint_test_config config,
read_and_write_test(config, 10000000, 100000, 8192, false);
read_and_write_test(config, 1000000, 100000, 1, false);
read_and_write_test(config, 100000000, 100000, 1, true);
for (i = 1; i < 1000; i = std::max(i + 1, i * 5 / 4)) {
for (i = 1; i < 1000; i = GPR_MAX(i + 1, i * 5 / 4)) {
read_and_write_test(config, 40320, i, i, false);
}
g_pollset = nullptr;

@ -91,7 +91,7 @@ static int compare_test_mutator(grpc_socket_mutator* a,
reinterpret_cast<struct test_socket_mutator*>(a);
struct test_socket_mutator* mb =
reinterpret_cast<struct test_socket_mutator*>(b);
return grpc_core::QsortCompare(ma->option_value, mb->option_value);
return GPR_ICMP(ma->option_value, mb->option_value);
}
static const grpc_socket_mutator_vtable mutator_vtable = {

@ -580,7 +580,7 @@ void run_tests(void) {
write_test(100000, 1, true);
write_test(100, 137, true);
for (i = 1; i < 1000; i = std::max(i + 1, i * 5 / 4)) {
for (i = 1; i < 1000; i = GPR_MAX(i + 1, i * 5 / 4)) {
write_test(40320, i, false);
write_test(40320, i, true);
}

@ -140,7 +140,7 @@ static elem_struct* search_elems(elem_struct* elems, size_t count,
for (size_t i = 0; i < count * 2; i++) {
size_t a = static_cast<size_t>(rand()) % count;
size_t b = static_cast<size_t>(rand()) % count;
std::swap(search_order[a], search_order[b]);
GPR_SWAP(size_t, search_order[a], search_order[b]);
}
elem_struct* out = nullptr;
for (size_t i = 0; out == nullptr && i < count; i++) {

@ -150,7 +150,7 @@ static int test_socket_factory_bind(grpc_socket_factory* factory, int sockfd,
static int test_socket_factory_compare(grpc_socket_factory* a,
grpc_socket_factory* b) {
return grpc_core::QsortCompare(a, b);
return GPR_ICMP(a, b);
}
static void test_socket_factory_destroy(grpc_socket_factory* factory) {

@ -126,7 +126,7 @@ TEST_P(BdpEstimatorRandomTest, GetEstimateRandomValues) {
if (sample > max) max = sample;
AddSample(&est, sample);
if (i >= 3) {
EXPECT_LE(est.EstimateBdp(), std::max(int64_t(65536), 2 * NextPow2(max)))
EXPECT_LE(est.EstimateBdp(), GPR_MAX(65536, 2 * NextPow2(max)))
<< " min:" << min << " max:" << max << " sample:" << sample;
}
}

@ -180,7 +180,7 @@ static void verify(const verify_params params, const char* expected,
va_end(l);
if (cap_to_delete == num_to_delete) {
cap_to_delete = std::max(2 * cap_to_delete, size_t(1000));
cap_to_delete = GPR_MAX(2 * cap_to_delete, 1000);
to_delete = static_cast<void**>(
gpr_realloc(to_delete, sizeof(*to_delete) * cap_to_delete));
}

@ -22,8 +22,6 @@
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -71,8 +69,7 @@ static void frame(frame_handler* handler, unsigned char* payload,
size_t offset = 0;
while (offset < handler->buffer_size &&
!alts_is_frame_writer_done(handler->writer)) {
size_t bytes_written =
std::min(write_length, handler->buffer_size - offset);
size_t bytes_written = GPR_MIN(write_length, handler->buffer_size - offset);
GPR_ASSERT(alts_write_frame_bytes(handler->writer, handler->buffer + offset,
&bytes_written));
offset += bytes_written;
@ -87,7 +84,7 @@ static size_t deframe(frame_handler* handler, unsigned char* bytes,
size_t offset = 0;
while (offset < handler->buffer_size &&
!alts_is_frame_reader_done(handler->reader)) {
size_t bytes_read = std::min(read_length, handler->buffer_size - offset);
size_t bytes_read = GPR_MIN(read_length, handler->buffer_size - offset);
GPR_ASSERT(alts_read_frame_bytes(handler->reader, handler->buffer + offset,
&bytes_read));
offset += bytes_read;

@ -18,8 +18,6 @@
#include "test/core/util/fuzzer_util.h"
#include <algorithm>
#include <grpc/support/alloc.h>
#include "src/core/lib/gpr/useful.h"
@ -41,7 +39,7 @@ char* grpc_fuzzer_get_next_string(input_stream* inp, bool* special) {
char c;
do {
if (cap == sz) {
cap = std::max(3 * cap / 2, cap + 8);
cap = GPR_MAX(3 * cap / 2, cap + 8);
str = static_cast<char*>(gpr_realloc(str, cap));
}
c = static_cast<char>(grpc_fuzzer_get_next_byte(inp));

@ -63,8 +63,7 @@ static size_t bucket_for_unchecked(grpc_histogram* h, double x) {
/* bounds checked version of the above */
static size_t bucket_for(grpc_histogram* h, double x) {
size_t bucket =
bucket_for_unchecked(h, grpc_core::Clamp(x, 1.0, h->max_possible));
size_t bucket = bucket_for_unchecked(h, GPR_CLAMP(x, 1.0, h->max_possible));
GPR_ASSERT(bucket < h->num_buckets);
return bucket;
}
@ -188,10 +187,10 @@ static double threshold_for_count_below(grpc_histogram* h, double count_below) {
should lie */
lower_bound = bucket_start(h, static_cast<double>(lower_idx));
upper_bound = bucket_start(h, static_cast<double>(lower_idx + 1));
return grpc_core::Clamp(upper_bound - (upper_bound - lower_bound) *
(count_so_far - count_below) /
h->buckets[lower_idx],
h->min_seen, h->max_seen);
return GPR_CLAMP(upper_bound - (upper_bound - lower_bound) *
(count_so_far - count_below) /
h->buckets[lower_idx],
h->min_seen, h->max_seen);
}
}

@ -20,8 +20,6 @@
#include <string.h>
#include <algorithm>
#include <grpc/support/alloc.h>
#include "src/core/lib/gpr/useful.h"
@ -116,7 +114,7 @@ grpc_slice grpc_slice_merge(grpc_slice* slices, size_t nslices) {
for (i = 0; i < nslices; i++) {
if (GRPC_SLICE_LENGTH(slices[i]) + length > capacity) {
capacity = std::max(capacity * 2, GRPC_SLICE_LENGTH(slices[i]) + length);
capacity = GPR_MAX(capacity * 2, GRPC_SLICE_LENGTH(slices[i]) + length);
out = static_cast<uint8_t*>(gpr_realloc(out, capacity));
}
memcpy(out + length, GRPC_SLICE_START_PTR(slices[i]),

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save