Skip to content

Commit

Permalink
chore: Bake the choice of ASIO_GRPC_USE_BOOST_CONTAINER into the inst…
Browse files Browse the repository at this point in the history
…alled header files in accordance to vcpkg's https://bit.ly/3DoQqOo
  • Loading branch information
Tradias committed Oct 8, 2021
1 parent 292492e commit 53f1c96
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 33 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ sonar-cfamily-reproducer.zip
.scannerwork

# https://github.com/aras-p/ClangBuildAnalyzer
ClangBuildAnalyzer.ini
ClangBuildAnalyzer.ini

# Generated files
src/agrpc/detail/memoryResource.hpp
test/utils/memoryResource.hpp
13 changes: 12 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,19 @@ target_include_directories(asio-grpc INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT
$<INSTALL_INTERFACE:include>)

if(ASIO_GRPC_USE_BOOST_CONTAINER)
target_compile_definitions(asio-grpc INTERFACE AGRPC_USE_BOOST_CONTAINER)
set(ASIO_GRPC_MEMORY_RESOURCE_INDLUCES
[[#include <boost/container/pmr/memory_resource.hpp>
#include <boost/container/pmr/polymorphic_allocator.hpp>
#include <boost/container/pmr/unsynchronized_pool_resource.hpp>]])
set(ASIO_GRPC_MEMORY_RESOURCE_NAMESPACE_ALIAS "namespace pmr = boost::container::pmr;")
else()
set(ASIO_GRPC_MEMORY_RESOURCE_INDLUCES "#include <memory_resource>")
set(ASIO_GRPC_MEMORY_RESOURCE_NAMESPACE_ALIAS "namespace pmr = std::pmr;")
endif()
configure_file("${CMAKE_CURRENT_LIST_DIR}/agrpc/detail/memoryResource.hpp.in"
"${CMAKE_CURRENT_LIST_DIR}/agrpc/detail/memoryResource.hpp" @ONLY)
unset(ASIO_GRPC_MEMORY_RESOURCE_INDLUCES)
unset(ASIO_GRPC_MEMORY_RESOURCE_NAMESPACE_ALIAS)

# installation
if(ASIO_GRPC_INSTALL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,11 @@
#ifndef AGRPC_DETAIL_MEMORYRESOURCE_HPP
#define AGRPC_DETAIL_MEMORYRESOURCE_HPP

#ifdef AGRPC_USE_BOOST_CONTAINER
#include <boost/container/pmr/memory_resource.hpp>
#include <boost/container/pmr/polymorphic_allocator.hpp>
#include <boost/container/pmr/unsynchronized_pool_resource.hpp>
#else
#include <memory_resource>
#endif
@ASIO_GRPC_MEMORY_RESOURCE_INDLUCES@

namespace agrpc::detail
{
#ifdef AGRPC_USE_BOOST_CONTAINER
namespace pmr = boost::container::pmr;
#else
namespace pmr = std::pmr;
#endif
@ASIO_GRPC_MEMORY_RESOURCE_NAMESPACE_ALIAS@
} // namespace agrpc::detail

#endif // AGRPC_DETAIL_MEMORYRESOURCE_HPP
3 changes: 1 addition & 2 deletions src/agrpc/grpcContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class GrpcContext : public asio::execution_context
using executor_type = agrpc::BasicGrpcExecutor<std::allocator<void>, detail::GrpcExecutorOptions::DEFAULT>;
using allocator_type = detail::GrpcContextLocalAllocator;

explicit GrpcContext(std::unique_ptr<grpc::CompletionQueue> completion_queue,
detail::pmr::memory_resource* local_upstream_resource = detail::pmr::new_delete_resource());
explicit GrpcContext(std::unique_ptr<grpc::CompletionQueue> completion_queue);

~GrpcContext();

Expand Down
5 changes: 2 additions & 3 deletions src/agrpc/grpcContext.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,13 @@ void run_event_loop(agrpc::GrpcContext& grpc_context, LoopPredicate loop_predica
}
} // namespace detail

inline GrpcContext::GrpcContext(std::unique_ptr<grpc::CompletionQueue> completion_queue,
detail::pmr::memory_resource* local_upstream_resource)
inline GrpcContext::GrpcContext(std::unique_ptr<grpc::CompletionQueue> completion_queue)
: outstanding_work(),
thread_id(std::this_thread::get_id()),
stopped(),
has_work(),
completion_queue(std::move(completion_queue)),
local_resource(local_upstream_resource),
local_resource(detail::pmr::new_delete_resource()),
is_processing_local_work(false),
remote_work_queue(32)
{
Expand Down
20 changes: 13 additions & 7 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,25 @@ asio_grpc_protobuf_generate(
"${CMAKE_CURRENT_LIST_DIR}/protos/test.proto")

# tests
if(ASIO_GRPC_USE_BOOST_CONTAINER)
set(ASIO_GRPC_MEMORY_RESOURCE_UTILS_INCLUDE "#include <boost/container/pmr/monotonic_buffer_resource.hpp>")
endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/utils/memoryResource.hpp.in"
"${CMAKE_CURRENT_SOURCE_DIR}/utils/memoryResource.hpp" @ONLY)

function(asio_grpc_add_test _asio-grpc_name)
add_executable(${_asio-grpc_name})

target_sources(
${_asio-grpc_name}
PRIVATE main.cpp
$<TARGET_PROPERTY:asio-grpc,ASIO_GRPC_HEADER_FILES>
"utils/asioUtils.hpp"
"utils/grpcContextTest.hpp"
"utils/grpcClientServerTest.cpp"
"utils/grpcClientServerTest.hpp"
"utils/freePort.cpp"
"utils/freePort.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/utils/asioUtils.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/utils/freePort.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/utils/freePort.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/utils/grpcClientServerTest.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/utils/grpcClientServerTest.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/utils/grpcContextTest.hpp"
"${ASIO_GRPC_GENERATED_SOURCES}"
${ARGN})

Expand All @@ -68,7 +74,7 @@ function(asio_grpc_add_test _asio-grpc_name)
${_asio-grpc_name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${ASIO_GRPC_GENERATED_PROTOS_OUT_DIR}> $<INSTALL_INTERFACE:include>)

target_precompile_headers(${_asio-grpc_name} PRIVATE "utils/precompiledHeader.hpp")
target_precompile_headers(${_asio-grpc_name} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/utils/precompiledHeader.hpp")
endfunction()

set(ASIO_GRPC_TEST_SOURCE_FILES "test-asio-grpc.cpp")
Expand Down
8 changes: 1 addition & 7 deletions test/utils/grpcContextTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define AGRPC_UTILS_GRPCTEST_HPP

#include "agrpc/asioGrpc.hpp"
#include "utils/memoryResource.hpp"

#include <boost/asio/execution/allocator.hpp>
#include <grpcpp/server.h>
Expand All @@ -26,13 +27,6 @@
#include <cstddef>
#include <memory>

#ifdef AGRPC_USE_BOOST_CONTAINER
#include <boost/container/pmr/monotonic_buffer_resource.hpp>
#include <boost/container/pmr/polymorphic_allocator.hpp>
#else
#include <memory_resource>
#endif

namespace agrpc::test
{
struct GrpcContextTest
Expand Down
21 changes: 21 additions & 0 deletions test/utils/memoryResource.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2021 Dennis Hezel
//
// 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 AGRPC_UTILS_MEMORYRESOURCE_HPP
#define AGRPC_UTILS_MEMORYRESOURCE_HPP

@ASIO_GRPC_MEMORY_RESOURCE_UTILS_INCLUDE@

#endif // AGRPC_UTILS_MEMORYRESOURCE_HPP

0 comments on commit 53f1c96

Please sign in to comment.