Skip to content

Commit f3cee19

Browse files
committed
memory pool works, placement new was wrong
1 parent 678d83d commit f3cee19

8 files changed

+69
-86
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
"cmake.configureArgs": ["-DExecutionGraph_BUILD_TESTS=ON",
161161
"-DExecutionGraph_BUILD_GUI=ON",
162162
"-DExecutionGraph_EXTERNAL_BUILD_DIR_POSTFIX=../buildExternal",
163-
"-DExecutionGraph_USE_CEF_DEBUG=ON"],
163+
"-ExecutionGraph_USE_CEF_DSYM_FILE=ON"],
164164
"plantuml.exportFormat": "svg",
165165
"plantuml.exportSubFolder": false,
166166
"markdown-preview-enhanced.previewTheme": "github-dark.css",

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ if(ExecutionGraph_USE_OPENMP)
203203
endif()
204204
# ======================================================================
205205

206+
# Get Version
207+
include(GetVersion)
208+
get_version_ExecutionGraph()
209+
206210
# Define all ExecutionGraph Source files
207211
include(DefineExecutionGraphSources)
208212
set(ExecutionGraph_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include/ExecutionGraph")

cmake/DefineExecutionGraphSources.cmake

+18-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
macro(include_all_source_ExecutionGraph
2-
SRC
3-
INC
4-
INCLUDE_DIRS
5-
DEPENDING_TARGETS # Input variable names
6-
ExecutionGraph_ROOT_DIR
7-
ExecutionGraph_BINARY_DIR)
8-
9-
# WRITE CONFIGURATION FILE
1+
function(include_all_source_ExecutionGraph
2+
SRC
3+
INC
4+
INCLUDE_DIRS
5+
DEPENDING_TARGETS # Input variable names
6+
ExecutionGraph_ROOT_DIR
7+
ExecutionGraph_BINARY_DIR)
8+
9+
# Write Config files
1010
include(${ExecutionGraph_ROOT_DIR}/cmake/WriteConfigFile.cmake)
1111
set(ExecutionGraph_CONFIG_FILE ${ExecutionGraph_BINARY_DIR}/include/executionGraph/config/Config.hpp)
1212
message(STATUS "ExecutionGraph: Write config file ${ExecutionGraph_CONFIG_FILE}")
1313
ExecutionGraph_write_config_file( ${ExecutionGraph_CONFIG_FILE} ${ExecutionGraph_ROOT_DIR})
14-
#=========================
1514

1615
# Add all external sources/headers
1716
# include(${ExecutionGraph_ROOT_DIR}/cmake/DefineExecutionGraphExternalSources.cmake)
@@ -25,6 +24,7 @@ macro(include_all_source_ExecutionGraph
2524
${ExecutionGraph_ROOT_DIR}/src/LogicNode.cpp
2625

2726
${ExecutionGraph_ROOT_DIR}/src/FileSystem.cpp
27+
PARENT_SCOPE
2828
)
2929

3030
set(${INC}
@@ -53,11 +53,13 @@ macro(include_all_source_ExecutionGraph
5353
${ExecutionGraph_ROOT_DIR}/include/executionGraph/graphs/ExecutionTreeInOut.hpp
5454

5555
${ExecutionGraph_CONFIG_FILE}
56+
PARENT_SCOPE
5657
)
5758

5859
set(${INCLUDE_DIRS}
5960
$<BUILD_INTERFACE:${ExecutionGraph_ROOT_DIR}/include>
6061
$<BUILD_INTERFACE:${ExecutionGraph_BINARY_DIR}/include>
62+
PARENT_SCOPE
6163
)
6264

6365
include(InstallMacros)
@@ -66,13 +68,13 @@ macro(include_all_source_ExecutionGraph
6668
if("${postfix}" STREQUAL "")
6769
message(FATAL_ERROR "wrong path ${PATH}")
6870
endif()
69-
install( FILES ${file} DESTINATION "include/${postfix}" )
71+
install(FILES ${file} DESTINATION "include/${postfix}" )
7072
endforeach()
7173

72-
endmacro()
74+
endfunction()
7375

7476

75-
macro(setTargetCompileOptionsExecutionGraph target)
77+
function(setTargetCompileOptionsExecutionGraph target)
7678

7779
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
7880
CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
@@ -91,11 +93,10 @@ macro(setTargetCompileOptionsExecutionGraph target)
9193
message(ERROR "MSVC is not yet supported!")
9294
endif()
9395

94-
9596
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
9697
# with clang 5.0.1: -fsanitize=address produces weird output in lldb for std::string ...
97-
list(APPEND CXX_FLAGS_DEBUG "-fsanitize=address" "-fsanitize=leak")
98-
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=leak -fsanitize=address -lc++experimental")
98+
list(APPEND CXX_FLAGS_DEBUG "-fsanitize=thread")
99+
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=thread -lc++experimental")
99100
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
100101
list(APPEND CXX_FLAGS_DEBUG "-fsanitize=address")
101102
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=address -lc++experimental")
@@ -119,4 +120,4 @@ macro(setTargetCompileOptionsExecutionGraph target)
119120
)
120121
endif()
121122

122-
endmacro()
123+
endfunction()

cmake/GetVersion.cmake

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
macro(get_version_ExecutionGraph)
2+
3+
# Get the version of the project ExecutionGraph
4+
execute_process(COMMAND "cmake" "-P" "cmake/GetGitRevisionDescriptionExtern.cmake"
5+
WORKING_DIRECTORY "${ExecutionGraph_ROOT_DIR}"
6+
OUTPUT_VARIABLE ExecutionGraph_VERSION ERROR_VARIABLE Error
7+
)
8+
9+
if(Error)
10+
message(FATAL_ERROR "Error in getting version of ExecutionGraph ${Error}" FATAL)
11+
endif()
12+
13+
14+
string(REGEX REPLACE "^.*v([0-9]+)\\..*" "\\1" ExecutionGraph_VERSION_MAJOR "${ExecutionGraph_VERSION}")
15+
string(REGEX REPLACE "^.*v[0-9]+\\.([0-9]+).*" "\\1" ExecutionGraph_VERSION_MINOR "${ExecutionGraph_VERSION}")
16+
string(REGEX REPLACE "^.*v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" ExecutionGraph_VERSION_PATCH "${ExecutionGraph_VERSION}")
17+
string(REGEX REPLACE "^.*v[0-9]+\\.[0-9]+\\.[0-9]+(.*)" "\\1" ExecutionGraph_VERSION_SHA1 "${ExecutionGraph_VERSION}")
18+
set(ExecutionGraph_VERSION_STRING "${ExecutionGraph_VERSION_MAJOR}.${ExecutionGraph_VERSION_MINOR}.${ExecutionGraph_VERSION_PATCH}")
19+
MESSAGE(STATUS "ExecutionGraph Version: ${ExecutionGraph_VERSION_STRING} extracted from git tags!")
20+
21+
if("${ExecutionGraph_VERSION_MAJOR}" STREQUAL "" OR
22+
"${ExecutionGraph_VERSION_MINOR}" STREQUAL "" OR
23+
"${ExecutionGraph_VERSION_PATCH}" STREQUAL "")
24+
25+
MESSAGE(STATUS "ExecutionGraph Version is bogus!")
26+
endif()
27+
28+
29+
endmacro()

cmake/WriteConfigFile.cmake

+1-25
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
MACRO(ExecutionGraph_WRITE_CONFIG_FILE ExecutionGraph_CONFIG_FILE ExecutionGraph_ROOT_DIR )
22

3-
# Get the version of the project ExecutionGraph
4-
execute_process(COMMAND "cmake" "-P" "cmake/GetGitRevisionDescriptionExtern.cmake"
5-
WORKING_DIRECTORY "${ExecutionGraph_ROOT_DIR}"
6-
OUTPUT_VARIABLE ExecutionGraph_VERSION ERROR_VARIABLE Error
7-
)
8-
9-
if(Error)
10-
message(FATAL_ERROR "Error in getting version of ExecutionGraph ${Error}" FATAL)
11-
endif()
12-
13-
14-
string(REGEX REPLACE "^.*v([0-9]+)\\..*" "\\1" ExecutionGraph_VERSION_MAJOR "${ExecutionGraph_VERSION}")
15-
string(REGEX REPLACE "^.*v[0-9]+\\.([0-9]+).*" "\\1" ExecutionGraph_VERSION_MINOR "${ExecutionGraph_VERSION}")
16-
string(REGEX REPLACE "^.*v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" ExecutionGraph_VERSION_PATCH "${ExecutionGraph_VERSION}")
17-
string(REGEX REPLACE "^.*v[0-9]+\\.[0-9]+\\.[0-9]+(.*)" "\\1" ExecutionGraph_VERSION_SHA1 "${ExecutionGraph_VERSION}")
18-
set(ExecutionGraph_VERSION_STRING "${ExecutionGraph_VERSION_MAJOR}.${ExecutionGraph_VERSION_MINOR}.${ExecutionGraph_VERSION_PATCH}")
19-
MESSAGE(STATUS "ExecutionGraph Version: ${ExecutionGraph_VERSION_STRING} extracted from git tags!")
20-
21-
if("${ExecutionGraph_VERSION_MAJOR}" STREQUAL "" OR
22-
"${ExecutionGraph_VERSION_MINOR}" STREQUAL "" OR
23-
"${ExecutionGraph_VERSION_PATCH}" STREQUAL "")
24-
25-
MESSAGE(STATUS "ExecutionGraph Version is bogus!")
26-
endif()
27-
3+
284
configure_file(
295
${ExecutionGraph_ROOT_DIR}/include/ExecutionGraph/config/Config.hpp.in.cmake
306
${ExecutionGraph_CONFIG_FILE}

cmake/external/FindMemoryLib.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if(${USE_SUPERBUILD})
2424
PREFIX "${ExecutionGraph_EXTERNAL_BUILD_DIR}/memory"
2525
TIMEOUT 10
2626
UPDATE_DISCONNECTED ON
27-
CMAKE_ARGS "-DCMAKE_BUILD_TYPE=Release" "-DFOONATHAN_MEMORY_BUILD_EXAMPLES=OFF"
27+
CMAKE_ARGS "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" "-DFOONATHAN_MEMORY_BUILD_EXAMPLES=OFF"
2828
"-DFOONATHAN_MEMORY_BUILD_TESTS=OFF" "-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}"
2929
INSTALL_DIR "${INSTALL_DIR}")
3030

gui/executionGraphGui/cefapp/BackendSchemeHandlerFactory.cpp

+14-27
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,18 @@ CefRefPtr<CefResourceHandler> BackendSchemeHandlerFactory::Create(CefRefPtr<CefB
2929
{
3030
CEF_REQUIRE_IO_THREAD();
3131

32-
// {
33-
// using Type = BackendResourceHandler;
34-
// using RawAllocator = memory_pool<>;
35-
// using Ptr = std::unique_ptr<Type, allocator_deleter<Type, RawAllocator>>;
36-
// using RawPtr = std::unique_ptr<Type, allocator_deallocator<Type, RawAllocator>>;
37-
// std::vector<CefRefPtr<CefResourceHandler>> vec;
38-
39-
// std::vector<Ptr> vec2;
40-
// for(auto i = 0; i < 3; i++)
41-
// {
42-
43-
// // get the memory from the pool
44-
// auto memory = m_handlerPool.allocate_node(/*sizeof(Type), alignof(Type)*/);
45-
46-
// using RawPtr = std::unique_ptr<Type, allocator_deallocator<Type, RawAllocator>>;
47-
// // raw_ptr deallocates memory in case of constructor exception
48-
// RawPtr result(static_cast<Type*>(memory), {m_handlerPool});
49-
// // call constructor (placement new)
50-
// ::new(memory) Type(m_bufferPool, [this](auto* ptr) { allocator_deleter<Type, RawAllocator>{m_handlerPool}(ptr); });
51-
// // pass ownership to return value CefRefPtr which will use the internal BackendResourceHandler::m_deleter
52-
// EXECGRAPHGUI_APPLOG_INFO("Allocated node: {0}", i);
53-
// vec.emplace_back(result.release());
54-
// }
55-
// std::shuffle(vec.begin(), vec.end(), std::mt19937{});
56-
// }
57-
58-
return new BackendResourceHandler{m_bufferPool, [](auto* p) { delete p; }};
32+
// Handback a new Handler (use an efficient memory pool)
33+
using Type = BackendResourceHandler;
34+
using RawAllocator = decltype(m_handlerPool);
35+
using RawPtr = std::unique_ptr<Type, allocator_deallocator<Type, RawAllocator>>;
36+
37+
// get the memory from the pool
38+
auto memory = m_handlerPool.allocate_node();
39+
// using RawPtr = std::unique_ptr<Type, allocator_deallocator<Type, RawAllocator>>;
40+
// raw_ptr deallocates memory in case of constructor exception
41+
RawPtr result(static_cast<BackendResourceHandler*>(memory), {m_handlerPool});
42+
// call constructor (placement new)
43+
::new(memory) BackendResourceHandler(m_bufferPool, [this](auto* ptr) { allocator_deleter<Type, RawAllocator>{m_handlerPool}(ptr); });
44+
45+
return result.release();
5946
}

gui/executionGraphGui/cefapp/BackendSchemeHandlerFactory.hpp

+1-15
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class BackendSchemeHandlerFactory final : public CefSchemeHandlerFactory
3939
BackendSchemeHandlerFactory(const std::path& pathPrefix = "")
4040
: m_pathPrefix(pathPrefix)
4141
, m_bufferPool(std::make_shared<BufferPool>())
42-
, m_handlerPool(sizeof(m_bufferPool), sizeof(m_bufferPool) * 30000)
42+
, m_handlerPool(sizeof(BackendResourceHandler), sizeof(BackendResourceHandler) * 30)
4343
{
4444
}
4545
virtual ~BackendSchemeHandlerFactory() = default;
@@ -52,20 +52,6 @@ class BackendSchemeHandlerFactory final : public CefSchemeHandlerFactory
5252
private:
5353
const std::path m_pathPrefix;
5454

55-
private:
56-
// struct HandlerFactory
57-
// {
58-
// HandlerFactory(std::shared_ptr<BufferPool> bufferPool) : m_bufferPool(bufferPool){}
59-
// using Handler = CefRefPtr<BackendResourceHandler>;
60-
// template<typename... Args>
61-
// Handler create(Args&&... args)
62-
// {
63-
// // inject binary buffers, together with other arguments...
64-
// return new BackendResourceHandler(std::forward<Args>(args)..., m_bufferPool);
65-
// }
66-
// std::shared_ptr<BufferPool> m_bufferPool;
67-
// };
68-
6955
private:
7056
std::shared_ptr<BufferPool> m_bufferPool; //! Binary buffers for the messages.
7157
foonathan::memory::memory_pool<> m_handlerPool; //! Simple request handler pool.

0 commit comments

Comments
 (0)