diff --git a/CMakeLists.txt b/CMakeLists.txt index b4845b0..6d9b2a5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ if(NOT MSVC) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") endif() -if (MSVC AND LIBIPC_USE_STATIC_CRT) +if (MSVC) set(CompilerFlags CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG @@ -22,9 +22,17 @@ if (MSVC AND LIBIPC_USE_STATIC_CRT) CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE ) - foreach(CompilerFlag ${CompilerFlags}) - string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") - endforeach() + if (LIBIPC_USE_STATIC_CRT) + foreach(CompilerFlag ${CompilerFlags}) + string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") + string(REPLACE "/MDd" "/MTd" ${CompilerFlag} "${${CompilerFlag}}") + endforeach() + else() + foreach(CompilerFlag ${CompilerFlags}) + string(REPLACE "/MT" "/MD" ${CompilerFlag} "${${CompilerFlag}}") + string(REPLACE "/MTd" "/MDd" ${CompilerFlag} "${${CompilerFlag}}") + endforeach() + endif() endif() set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) @@ -50,6 +58,7 @@ endif() if (LIBIPC_BUILD_DEMOS) add_subdirectory(demo/chat) add_subdirectory(demo/msg_que) + add_subdirectory(demo/send_recv) endif() install( diff --git a/demo/msg_que/main.cpp b/demo/msg_que/main.cpp index 5635101..27c5ce6 100644 --- a/demo/msg_que/main.cpp +++ b/demo/msg_que/main.cpp @@ -127,10 +127,10 @@ int main(int argc, char ** argv) { ::signal(SIGHUP , exit); #endif - if (std::string{ argv[1] } == mode_s__) { + std::string mode {argv[1]}; + if (mode == mode_s__) { do_send(); - } - else if (std::string{ argv[1] } == mode_r__) { + } else if (mode == mode_r__) { do_recv(); } return 0; diff --git a/src/libipc/waiter_helper.h b/src/libipc/waiter_helper.h index f866cf1..a84f59c 100644 --- a/src/libipc/waiter_helper.h +++ b/src/libipc/waiter_helper.h @@ -34,7 +34,11 @@ struct waiter_helper { counter.waiting_.fetch_add(1, std::memory_order_release); flags.is_waiting_.store(true, std::memory_order_relaxed); auto finally = ipc::guard([&counter, &flags] { - counter.waiting_.fetch_sub(1, std::memory_order_release); + for (auto curr_wait = counter.waiting_.load(std::memory_order_acquire); curr_wait > 0;) { + if (counter.waiting_.compare_exchange_weak(curr_wait, curr_wait - 1, std::memory_order_release)) { + break; + } + } flags.is_waiting_.store(false, std::memory_order_relaxed); }); { @@ -107,6 +111,7 @@ struct waiter_helper { counter.counter_ -= 1; ret = ret && ctrl.handshake_wait(tm); } while (counter.counter_ > 0); + counter.waiting_.store(0, std::memory_order_release); } return ret; }