diff --git a/BUILD b/BUILD index 6641bd85bb8..ba438829f5f 100644 --- a/BUILD +++ b/BUILD @@ -1178,6 +1178,17 @@ grpc_cc_library( ], ) +grpc_cc_library( + name = "packed_table", + hdrs = ["src/core/lib/gprpp/packed_table.h"], + language = "c++", + deps = [ + "gpr_public_hdrs", + "sorted_pack", + "table", + ], +) + grpc_cc_library( name = "bitset", language = "c++", @@ -3141,6 +3152,7 @@ grpc_cc_library( "latch", "memory_quota", "orphanable", + "packed_table", "percent_encoding", "poll", "pollset_set", @@ -3699,6 +3711,15 @@ grpc_cc_library( ], ) +grpc_cc_library( + name = "sorted_pack", + hdrs = [ + "src/core/lib/gprpp/sorted_pack.h", + ], + language = "c++", + deps = ["gpr_platform"], +) + grpc_cc_library( name = "idle_filter_state", srcs = [ diff --git a/CMakeLists.txt b/CMakeLists.txt index af6d589e918..2076636fe79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1149,6 +1149,7 @@ if(gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_cxx socket_utils_test) endif() + add_dependencies(buildtests_cxx sorted_pack_test) add_dependencies(buildtests_cxx spinlock_test) add_dependencies(buildtests_cxx ssl_credentials_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) @@ -16904,6 +16905,40 @@ endif() endif() if(gRPC_BUILD_TESTS) +add_executable(sorted_pack_test + test/core/gprpp/sorted_pack_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + +target_include_directories(sorted_pack_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(sorted_pack_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} +) + + +endif() +if(gRPC_BUILD_TESTS) + add_executable(spinlock_test test/core/gpr/spinlock_test.cc third_party/googletest/googletest/src/gtest-all.cc diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 3496a629d51..350e57ea09e 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -792,9 +792,11 @@ libs: - src/core/lib/gprpp/no_destruct.h - src/core/lib/gprpp/orphanable.h - src/core/lib/gprpp/overload.h + - src/core/lib/gprpp/packed_table.h - src/core/lib/gprpp/ref_counted.h - src/core/lib/gprpp/ref_counted_ptr.h - src/core/lib/gprpp/single_set_ptr.h + - src/core/lib/gprpp/sorted_pack.h - src/core/lib/gprpp/status_helper.h - src/core/lib/gprpp/table.h - src/core/lib/gprpp/time.h @@ -1997,9 +1999,11 @@ libs: - src/core/lib/gprpp/no_destruct.h - src/core/lib/gprpp/orphanable.h - src/core/lib/gprpp/overload.h + - src/core/lib/gprpp/packed_table.h - src/core/lib/gprpp/ref_counted.h - src/core/lib/gprpp/ref_counted_ptr.h - src/core/lib/gprpp/single_set_ptr.h + - src/core/lib/gprpp/sorted_pack.h - src/core/lib/gprpp/status_helper.h - src/core/lib/gprpp/table.h - src/core/lib/gprpp/time.h @@ -9501,6 +9505,16 @@ targets: - linux - posix - mac +- name: sorted_pack_test + gtest: true + build: test + language: c++ + headers: + - src/core/lib/gprpp/sorted_pack.h + src: + - test/core/gprpp/sorted_pack_test.cc + deps: [] + uses_polling: false - name: spinlock_test gtest: true build: test diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 0bed4eaca8c..a6581ee1fd5 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -731,9 +731,11 @@ Pod::Spec.new do |s| 'src/core/lib/gprpp/no_destruct.h', 'src/core/lib/gprpp/orphanable.h', 'src/core/lib/gprpp/overload.h', + 'src/core/lib/gprpp/packed_table.h', 'src/core/lib/gprpp/ref_counted.h', 'src/core/lib/gprpp/ref_counted_ptr.h', 'src/core/lib/gprpp/single_set_ptr.h', + 'src/core/lib/gprpp/sorted_pack.h', 'src/core/lib/gprpp/stat.h', 'src/core/lib/gprpp/status_helper.h', 'src/core/lib/gprpp/sync.h', @@ -1587,9 +1589,11 @@ Pod::Spec.new do |s| 'src/core/lib/gprpp/no_destruct.h', 'src/core/lib/gprpp/orphanable.h', 'src/core/lib/gprpp/overload.h', + 'src/core/lib/gprpp/packed_table.h', 'src/core/lib/gprpp/ref_counted.h', 'src/core/lib/gprpp/ref_counted_ptr.h', 'src/core/lib/gprpp/single_set_ptr.h', + 'src/core/lib/gprpp/sorted_pack.h', 'src/core/lib/gprpp/stat.h', 'src/core/lib/gprpp/status_helper.h', 'src/core/lib/gprpp/sync.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 316ee51ac2a..003830dc34f 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -1153,9 +1153,11 @@ Pod::Spec.new do |s| 'src/core/lib/gprpp/no_destruct.h', 'src/core/lib/gprpp/orphanable.h', 'src/core/lib/gprpp/overload.h', + 'src/core/lib/gprpp/packed_table.h', 'src/core/lib/gprpp/ref_counted.h', 'src/core/lib/gprpp/ref_counted_ptr.h', 'src/core/lib/gprpp/single_set_ptr.h', + 'src/core/lib/gprpp/sorted_pack.h', 'src/core/lib/gprpp/stat.h', 'src/core/lib/gprpp/stat_posix.cc', 'src/core/lib/gprpp/stat_windows.cc', @@ -2211,9 +2213,11 @@ Pod::Spec.new do |s| 'src/core/lib/gprpp/no_destruct.h', 'src/core/lib/gprpp/orphanable.h', 'src/core/lib/gprpp/overload.h', + 'src/core/lib/gprpp/packed_table.h', 'src/core/lib/gprpp/ref_counted.h', 'src/core/lib/gprpp/ref_counted_ptr.h', 'src/core/lib/gprpp/single_set_ptr.h', + 'src/core/lib/gprpp/sorted_pack.h', 'src/core/lib/gprpp/stat.h', 'src/core/lib/gprpp/status_helper.h', 'src/core/lib/gprpp/sync.h', diff --git a/grpc.gemspec b/grpc.gemspec index ad13c0268f9..65605f443cb 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -1066,9 +1066,11 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/gprpp/no_destruct.h ) s.files += %w( src/core/lib/gprpp/orphanable.h ) s.files += %w( src/core/lib/gprpp/overload.h ) + s.files += %w( src/core/lib/gprpp/packed_table.h ) s.files += %w( src/core/lib/gprpp/ref_counted.h ) s.files += %w( src/core/lib/gprpp/ref_counted_ptr.h ) s.files += %w( src/core/lib/gprpp/single_set_ptr.h ) + s.files += %w( src/core/lib/gprpp/sorted_pack.h ) s.files += %w( src/core/lib/gprpp/stat.h ) s.files += %w( src/core/lib/gprpp/stat_posix.cc ) s.files += %w( src/core/lib/gprpp/stat_windows.cc ) diff --git a/package.xml b/package.xml index f54e7eb5543..bfffe777d28 100644 --- a/package.xml +++ b/package.xml @@ -1048,9 +1048,11 @@ + + diff --git a/src/core/lib/gprpp/packed_table.h b/src/core/lib/gprpp/packed_table.h new file mode 100644 index 00000000000..53f77b88537 --- /dev/null +++ b/src/core/lib/gprpp/packed_table.h @@ -0,0 +1,40 @@ +// Copyright 2022 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef GRPC_CORE_LIB_GPRPP_PACKED_TABLE_H +#define GRPC_CORE_LIB_GPRPP_PACKED_TABLE_H + +#include + +#include "src/core/lib/gprpp/sorted_pack.h" +#include "src/core/lib/gprpp/table.h" + +namespace grpc_core { + +namespace packed_table_detail { +template +struct Cmp { + static constexpr bool kValue = alignof(A) > alignof(B) || + (alignof(A) == alignof(B) && + sizeof(A) > sizeof(B)); +}; +}; // namespace packed_table_detail + +template +using PackedTable = + typename WithSortedPack::Type; + +} // namespace grpc_core + +#endif // GRPC_CORE_LIB_GPRPP_PACKED_TABLE_H diff --git a/src/core/lib/gprpp/sorted_pack.h b/src/core/lib/gprpp/sorted_pack.h new file mode 100644 index 00000000000..c103b980281 --- /dev/null +++ b/src/core/lib/gprpp/sorted_pack.h @@ -0,0 +1,98 @@ +// Copyright 2022 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef GRPC_CORE_LIB_GPRPP_SORTED_PACK_H +#define GRPC_CORE_LIB_GPRPP_SORTED_PACK_H + +#include + +#include + +namespace grpc_core { + +namespace sorted_pack_detail { + +// A list of types +template +struct Typelist { + template