From f388a0a3607c6668ff96f8b09d43fd6aa5f6cbf4 Mon Sep 17 00:00:00 2001 From: mutouyun Date: Fri, 4 Jan 2019 22:11:19 +0800 Subject: [PATCH] fix compiling error; preparing to refactor --- build/ipc/CMakeLists.txt | 11 ++++---- build/test/CMakeLists.txt | 4 +-- include/circ_elem_array.h | 4 +-- include/circ_elems_array.h | 11 +++++--- test/test_circ.cpp | 55 +++++++++++++++++++++++++++----------- 5 files changed, 57 insertions(+), 28 deletions(-) diff --git a/build/ipc/CMakeLists.txt b/build/ipc/CMakeLists.txt index 7f75256..15ea026 100644 --- a/build/ipc/CMakeLists.txt +++ b/build/ipc/CMakeLists.txt @@ -2,14 +2,15 @@ project(ipc) add_compile_options(-D__IPC_LIBRARY__) -include_directories(../../include ../../src) +include_directories(${CMAKE_SOURCE_DIR}/../include ${CMAKE_SOURCE_DIR}/../src) if(UNIX) - file(GLOB DIR_SRCS ../../src/platform/*_linux.cpp) + file(GLOB SRC_FILES ${CMAKE_SOURCE_DIR}/../src/platform/*_linux.cpp) else() - file(GLOB DIR_SRCS ../../src/platform/*_win.cpp) + file(GLOB SRC_FILES ${CMAKE_SOURCE_DIR}/../src/platform/*_win.cpp) endif() -aux_source_directory(../../src DIR_SRCS) +aux_source_directory(${CMAKE_SOURCE_DIR}/../src SRC_FILES) +file(GLOB HEAD_FILES ${CMAKE_SOURCE_DIR}/../include/*.h ${CMAKE_SOURCE_DIR}/../src/*.inc ${CMAKE_SOURCE_DIR}/../src/memory/*.hpp) -add_library(${PROJECT_NAME} SHARED ${DIR_SRCS}) +add_library(${PROJECT_NAME} SHARED ${SRC_FILES} ${HEAD_FILES}) set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/../output) diff --git a/build/test/CMakeLists.txt b/build/test/CMakeLists.txt index ed91661..10f0461 100644 --- a/build/test/CMakeLists.txt +++ b/build/test/CMakeLists.txt @@ -10,8 +10,8 @@ if(NOT MSVC) endif() include_directories(../../include ../../src ../../test ../../test/capo) -file(GLOB SRC_FILES "../../test/*.cpp") -file(GLOB HEAD_FILES "../../test/*.h") +file(GLOB SRC_FILES ../../test/*.cpp) +file(GLOB HEAD_FILES ../../test/*.h) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/../output) link_directories(${EXECUTABLE_OUTPUT_PATH}) diff --git a/include/circ_elem_array.h b/include/circ_elem_array.h index a5e2f23..f57329b 100644 --- a/include/circ_elem_array.h +++ b/include/circ_elem_array.h @@ -90,7 +90,7 @@ protected: template void* acquire(std::memory_order order, Acq&& acq, P&&... params) noexcept { - uint_t<32> conn_cnt = cc_.load(order); + uint_t<32> conn_cnt = this->cc_.load(order); if (conn_cnt == 0) return nullptr; elem_t* el = elem(std::forward(acq)(std::memory_order_relaxed, std::forward

(params)...)); @@ -102,7 +102,7 @@ protected: break; } std::this_thread::yield(); - conn_cnt = cc_.load(std::memory_order_acquire); + conn_cnt = this->cc_.load(std::memory_order_acquire); } return el->data_; } diff --git a/include/circ_elems_array.h b/include/circ_elems_array.h index 1a3472d..f367536 100644 --- a/include/circ_elems_array.h +++ b/include/circ_elems_array.h @@ -28,6 +28,11 @@ struct elem_t { byte_t data_[DataSize] {}; }; +template <> +struct elem_t<0> { + elem_head head_; +}; + template elem_t* elem_of(void* ptr) noexcept { return reinterpret_cast*>(static_cast(ptr) - sizeof(elem_head)); @@ -42,7 +47,7 @@ enum class relat { // multiplicity of the relationship enum class trans { // transmission unicast, - multicast + broadcast }; //////////////////////////////////////////////////////////////// @@ -58,7 +63,7 @@ struct prod_cons { std::atomic wt_ { 0 }; // write index template - constexpr static std::size_t elem_param = DataSize - sizeof(elem_head); + constexpr static std::size_t elem_param = DataSize - sizeof(detail::elem_head); constexpr detail::u2_t cursor() const noexcept { return 0; @@ -111,7 +116,7 @@ struct prod_cons }; template <> -struct prod_cons { +struct prod_cons { std::atomic wt_ { 0 }; // write index template diff --git a/test/test_circ.cpp b/test/test_circ.cpp index 2654a2a..4ce7ca0 100644 --- a/test/test_circ.cpp +++ b/test/test_circ.cpp @@ -49,6 +49,10 @@ struct test_verify { for (auto& c_dats : list_) { for (int n = 0; n < N; ++n) { auto& vec = c_dats[n]; + //for (int d : vec) { + // std::cout << d << " "; + //} + //std::cout << std::endl; QCOMPARE(vec.size(), static_cast(Loops)); int i = 0; for (int d : vec) { @@ -85,22 +89,39 @@ struct test_verify +struct quit_mode; + +template +struct quit_mode> { + using type = volatile bool; +}; + +template +struct quit_mode> { + struct type { + type(bool) {} + constexpr operator bool() const { return false; } + }; +}; + template struct test_cq> { using ca_t = ipc::circ::elems_array; + using cn_t = decltype(std::declval().cursor()); - volatile bool quit_ = false; + typename quit_mode

::type quit_ = false; ca_t* ca_; test_cq(ca_t* ca) : ca_(ca) {} - auto connect() { + cn_t connect() { auto cur = ca_->cursor(); ca_->connect(); return cur; } - void disconnect(int) { + void disconnect(cn_t) { ca_->disconnect(); } @@ -111,17 +132,17 @@ struct test_cq> { } template - void recv(decltype(std::declval().cursor()) cur, F&& proc) { + void recv(cn_t cur, F&& proc) { while(1) { - msg_t* pmsg; - while (ca_->pop(cur, [&pmsg](void* p) { - pmsg = static_cast(p); + msg_t msg; + while (ca_->pop(cur, [&msg](void* p) { + msg = *static_cast(p); })) { - if (pmsg->pid_ < 0) { + if (msg.pid_ < 0) { quit_ = true; return; } - proc(*pmsg); + proc(msg); } if (quit_) return; std::this_thread::yield(); @@ -264,6 +285,7 @@ private slots: #include "test_circ.moc" constexpr int LoopCount = 10000000; +//constexpr int LoopCount = 1000/*0000*/; void Unit::initTestCase() { TestSuite::initTestCase(); @@ -322,13 +344,14 @@ void Unit::test_prod_cons_1v3() { benchmark_prod_cons<1, 3, LoopCount, decltype(el_arr_smn)::policy_t>(&el_arr_smn); benchmark_prod_cons<1, 3, LoopCount, void>(&el_arr_smn); -// ipc::circ::elems_array< -// sizeof(msg_t), -// ipc::circ::prod_cons -// > el_arr_smm; -// benchmark_prod_cons<1, 3, LoopCount, cq_t>(&el_arr_smm); + ipc::circ::elems_array< + sizeof(msg_t), + ipc::circ::prod_cons + > el_arr_smm; + benchmark_prod_cons<1, 3, LoopCount, cq_t>(&el_arr_smm); + benchmark_prod_cons<1, 3, LoopCount, void>(&el_arr_smm); } void Unit::test_prod_cons_performance() {