diff --git a/changelog/1.4.0.md b/changelog/1.4.0.md index d1f1a59c..58fa0a83 100644 --- a/changelog/1.4.0.md +++ b/changelog/1.4.0.md @@ -66,6 +66,7 @@ OATPP_ASSERT(decoded == data) | `oatpp/core/IODefinitions.hpp` | `oatpp/IODefinitions.hpp` | | `oatpp/core/base/Environment.hpp` | `oatpp/Environment.hpp` | | `oatpp/core/base/*` | `oatpp/base/*` | +| `oatpp/core/concurrency/*` | `oatpp/concurrency/*` | ### Namespaces diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 24e199a8..2f3c863b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,10 +56,10 @@ add_library(oatpp oatpp/codegen/DbClient_undef.hpp oatpp/codegen/DTO_define.hpp oatpp/codegen/DTO_undef.hpp - oatpp/core/concurrency/SpinLock.cpp - oatpp/core/concurrency/SpinLock.hpp - oatpp/core/concurrency/Thread.cpp - oatpp/core/concurrency/Thread.hpp + oatpp/concurrency/SpinLock.cpp + oatpp/concurrency/SpinLock.hpp + oatpp/concurrency/Utils.cpp + oatpp/concurrency/Utils.hpp oatpp/core/data/Bundle.cpp oatpp/core/data/Bundle.hpp oatpp/core/data/buffer/FIFOBuffer.cpp diff --git a/src/oatpp/async/Executor.cpp b/src/oatpp/async/Executor.cpp index 088c23aa..bae0c5ad 100644 --- a/src/oatpp/async/Executor.cpp +++ b/src/oatpp/async/Executor.cpp @@ -23,10 +23,13 @@ ***************************************************************************/ #include "Executor.hpp" + #include "oatpp/async/worker/IOEventWorker.hpp" #include "oatpp/async/worker/IOWorker.hpp" #include "oatpp/async/worker/TimerWorker.hpp" +#include "oatpp/concurrency/Utils.hpp" + namespace oatpp { namespace async { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -133,7 +136,7 @@ v_int32 Executor::chooseProcessorWorkersCount(v_int32 processorWorkersCount) { return processorWorkersCount; } if(processorWorkersCount == VALUE_SUGGESTED) { - return oatpp::concurrency::getHardwareConcurrency(); + return oatpp::concurrency::Utils::getHardwareConcurrency(); } throw std::runtime_error("[oatpp::async::Executor::chooseProcessorWorkersCount()]: Error. Invalid processor workers count specified."); } diff --git a/src/oatpp/async/Executor.hpp b/src/oatpp/async/Executor.hpp index 0b0870b7..38741c95 100644 --- a/src/oatpp/async/Executor.hpp +++ b/src/oatpp/async/Executor.hpp @@ -29,8 +29,7 @@ #include "oatpp/async/worker/Worker.hpp" #include "oatpp/base/Compiler.hpp" -#include "oatpp/core/concurrency/SpinLock.hpp" -#include "oatpp/core/concurrency/Thread.hpp" +#include "oatpp/concurrency/SpinLock.hpp" #include #include diff --git a/src/oatpp/async/Processor.hpp b/src/oatpp/async/Processor.hpp index 7ec3eba4..e4a75c18 100644 --- a/src/oatpp/async/Processor.hpp +++ b/src/oatpp/async/Processor.hpp @@ -29,6 +29,7 @@ #include "./Coroutine.hpp" #include "./CoroutineWaitList.hpp" #include "oatpp/async/utils/FastQueue.hpp" +#include "oatpp/concurrency/SpinLock.hpp" #include #include diff --git a/src/oatpp/async/utils/FastQueue.hpp b/src/oatpp/async/utils/FastQueue.hpp index 78f43335..a7c2efc3 100644 --- a/src/oatpp/async/utils/FastQueue.hpp +++ b/src/oatpp/async/utils/FastQueue.hpp @@ -25,7 +25,6 @@ #ifndef oatpp_async_utils_FastQueue_hpp #define oatpp_async_utils_FastQueue_hpp -#include "oatpp/core/concurrency/SpinLock.hpp" #include "oatpp/Environment.hpp" namespace oatpp { namespace async { namespace utils { diff --git a/src/oatpp/async/worker/IOEventWorker.hpp b/src/oatpp/async/worker/IOEventWorker.hpp index 81e2b2fd..ffbf57f6 100644 --- a/src/oatpp/async/worker/IOEventWorker.hpp +++ b/src/oatpp/async/worker/IOEventWorker.hpp @@ -26,7 +26,7 @@ #define oatpp_async_worker_IOEventWorker_hpp #include "./Worker.hpp" -#include "oatpp/core/concurrency/SpinLock.hpp" +#include "oatpp/concurrency/SpinLock.hpp" #include #include diff --git a/src/oatpp/async/worker/IOWorker.hpp b/src/oatpp/async/worker/IOWorker.hpp index c83118e9..fed398d8 100644 --- a/src/oatpp/async/worker/IOWorker.hpp +++ b/src/oatpp/async/worker/IOWorker.hpp @@ -26,7 +26,7 @@ #define oatpp_async_worker_IOWorker_hpp #include "./Worker.hpp" -#include "oatpp/core/concurrency/SpinLock.hpp" +#include "oatpp/concurrency/SpinLock.hpp" #include #include diff --git a/src/oatpp/async/worker/TimerWorker.hpp b/src/oatpp/async/worker/TimerWorker.hpp index 89e5e5fe..2a439f27 100644 --- a/src/oatpp/async/worker/TimerWorker.hpp +++ b/src/oatpp/async/worker/TimerWorker.hpp @@ -26,7 +26,7 @@ #define oatpp_async_worker_TimerWorker_hpp #include "./Worker.hpp" -#include "oatpp/core/concurrency/SpinLock.hpp" +#include "oatpp/concurrency/SpinLock.hpp" #include #include diff --git a/src/oatpp/core/concurrency/SpinLock.cpp b/src/oatpp/concurrency/SpinLock.cpp similarity index 100% rename from src/oatpp/core/concurrency/SpinLock.cpp rename to src/oatpp/concurrency/SpinLock.cpp diff --git a/src/oatpp/core/concurrency/SpinLock.hpp b/src/oatpp/concurrency/SpinLock.hpp similarity index 100% rename from src/oatpp/core/concurrency/SpinLock.hpp rename to src/oatpp/concurrency/SpinLock.hpp diff --git a/src/oatpp/core/concurrency/Thread.cpp b/src/oatpp/concurrency/Utils.cpp similarity index 86% rename from src/oatpp/core/concurrency/Thread.cpp rename to src/oatpp/concurrency/Utils.cpp index 99e565c9..963b80e8 100644 --- a/src/oatpp/core/concurrency/Thread.cpp +++ b/src/oatpp/concurrency/Utils.cpp @@ -22,19 +22,15 @@ * ***************************************************************************/ -#include "Thread.hpp" - -#if defined(_GNU_SOURCE) - #include -#endif +#include "Utils.hpp" namespace oatpp { namespace concurrency { -v_int32 setThreadAffinityToOneCpu(std::thread::native_handle_type nativeHandle, v_int32 cpuIndex) { +v_int32 Utils::setThreadAffinityToOneCpu(std::thread::native_handle_type nativeHandle, v_int32 cpuIndex) { return setThreadAffinityToCpuRange(nativeHandle, cpuIndex, cpuIndex); } - -v_int32 setThreadAffinityToCpuRange(std::thread::native_handle_type nativeHandle, v_int32 firstCpuIndex, v_int32 lastCpuIndex) { + +v_int32 Utils::setThreadAffinityToCpuRange(std::thread::native_handle_type nativeHandle, v_int32 firstCpuIndex, v_int32 lastCpuIndex) { #if defined(_GNU_SOURCE) // NOTE: @@ -73,8 +69,8 @@ v_int32 setThreadAffinityToCpuRange(std::thread::native_handle_type nativeHandle return -1; #endif } - -static v_int32 calcHardwareConcurrency() { + +v_int32 Utils::calcHardwareConcurrency() { #if !defined(OATPP_THREAD_HARDWARE_CONCURRENCY) v_int32 concurrency = static_cast(std::thread::hardware_concurrency()); if(concurrency == 0) { @@ -86,11 +82,10 @@ static v_int32 calcHardwareConcurrency() { return OATPP_THREAD_HARDWARE_CONCURRENCY; #endif } - -v_int32 getHardwareConcurrency() { + +v_int32 Utils::getHardwareConcurrency() { static v_int32 concurrency = calcHardwareConcurrency(); return concurrency; } - -}} +}} diff --git a/src/oatpp/concurrency/Utils.hpp b/src/oatpp/concurrency/Utils.hpp new file mode 100644 index 00000000..70017f5b --- /dev/null +++ b/src/oatpp/concurrency/Utils.hpp @@ -0,0 +1,69 @@ +/*************************************************************************** + * + * Project _____ __ ____ _ _ + * ( _ ) /__\ (_ _)_| |_ _| |_ + * )(_)( /(__)\ )( (_ _)(_ _) + * (_____)(__)(__)(__) |_| |_| + * + * + * Copyright 2018-present, Leonid Stryzhevskyi + * + * 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 oatpp_concurrency_Utils_hpp +#define oatpp_concurrency_Utils_hpp + +#include "oatpp/Environment.hpp" +#include + +namespace oatpp { namespace concurrency { + +class Utils { +private: + static v_int32 calcHardwareConcurrency(); +public: + + /** + * Set thread affinity to one CPU. + * @param nativeHandle - `std::thread::native_handle_type`. + * @param cpuIndex - index of CPU. + * @return - zero on success. Negative value on failure. + * -1 if platform that runs application does not support this call. + */ + static v_int32 setThreadAffinityToOneCpu(std::thread::native_handle_type nativeHandle, v_int32 cpuIndex); + + /** + * Set thread affinity [firstCpuIndex..lastCpuIndex]. + * @param nativeHandle - `std::thread::native_handle_type`. + * @param firstCpuIndex - from CPU-index. + * @param lastCpuIndex - to CPU-index included. + * @return - zero on success. Negative value on failure. + * -1 if platform that runs application does not support this call. + */ + static v_int32 setThreadAffinityToCpuRange(std::thread::native_handle_type nativeHandle, v_int32 firstCpuIndex, v_int32 lastCpuIndex); + + /** + * Get hardware concurrency. + * @return - OATPP_THREAD_HARDWARE_CONCURRENCY config value if set
+ * else return std::thread::hardware_concurrency()
+ * else return 1.
+ */ + static v_int32 getHardwareConcurrency(); + +}; + +}} + +#endif //oatpp_concurrency_Utils_hpp diff --git a/src/oatpp/core/concurrency/Thread.hpp b/src/oatpp/core/concurrency/Thread.hpp deleted file mode 100644 index 93d540ca..00000000 --- a/src/oatpp/core/concurrency/Thread.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - * - * Project _____ __ ____ _ _ - * ( _ ) /__\ (_ _)_| |_ _| |_ - * )(_)( /(__)\ )( (_ _)(_ _) - * (_____)(__)(__)(__) |_| |_| - * - * - * Copyright 2018-present, Leonid Stryzhevskyi - * - * 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 oatpp_concurrency_Thread_hpp -#define oatpp_concurrency_Thread_hpp - -#include "oatpp/Environment.hpp" -#include - -namespace oatpp { namespace concurrency { - -/** - * Set thread affinity to one CPU. - * @param nativeHandle - `std::thread::native_handle_type`. - * @param cpuIndex - index of CPU. - * @return - zero on success. Negative value on failure. - * -1 if platform that runs application does not support this call. - */ -v_int32 setThreadAffinityToOneCpu(std::thread::native_handle_type nativeHandle, v_int32 cpuIndex); - -/** - * Set thread affinity [firstCpuIndex..lastCpuIndex]. - * @param nativeHandle - `std::thread::native_handle_type`. - * @param firstCpuIndex - from CPU-index. - * @param lastCpuIndex - to CPU-index included. - * @return - zero on success. Negative value on failure. - * -1 if platform that runs application does not support this call. - */ -v_int32 setThreadAffinityToCpuRange(std::thread::native_handle_type nativeHandle, v_int32 firstCpuIndex, v_int32 lastCpuIndex); - -/** - * Get hardware concurrency. - * @return - OATPP_THREAD_HARDWARE_CONCURRENCY config value if set
- * else return std::thread::hardware_concurrency()
- * else return 1.
- */ -v_int32 getHardwareConcurrency(); - -}} - -#endif /* concurrency_Thread_hpp */ diff --git a/src/oatpp/core/data/buffer/FIFOBuffer.hpp b/src/oatpp/core/data/buffer/FIFOBuffer.hpp index c1a8745b..e91ff3c4 100644 --- a/src/oatpp/core/data/buffer/FIFOBuffer.hpp +++ b/src/oatpp/core/data/buffer/FIFOBuffer.hpp @@ -28,7 +28,7 @@ #include "oatpp/core/data/stream/Stream.hpp" #include "oatpp/IODefinitions.hpp" #include "oatpp/async/Coroutine.hpp" -#include "oatpp/core/concurrency/SpinLock.hpp" +#include "oatpp/concurrency/SpinLock.hpp" namespace oatpp { namespace data { namespace buffer { diff --git a/src/oatpp/core/data/share/LazyStringMap.hpp b/src/oatpp/core/data/share/LazyStringMap.hpp index 83e06880..e82070ec 100644 --- a/src/oatpp/core/data/share/LazyStringMap.hpp +++ b/src/oatpp/core/data/share/LazyStringMap.hpp @@ -26,7 +26,7 @@ #define oatpp_data_share_LazyStringMap_hpp #include "./MemoryLabel.hpp" -#include "oatpp/core/concurrency/SpinLock.hpp" +#include "oatpp/concurrency/SpinLock.hpp" #include diff --git a/src/oatpp/network/virtual_/Pipe.hpp b/src/oatpp/network/virtual_/Pipe.hpp index 5bcc4715..ff20f356 100644 --- a/src/oatpp/network/virtual_/Pipe.hpp +++ b/src/oatpp/network/virtual_/Pipe.hpp @@ -32,7 +32,7 @@ #include "oatpp/core/data/buffer/FIFOBuffer.hpp" #include "oatpp/core/data/buffer/IOBuffer.hpp" -#include "oatpp/core/concurrency/SpinLock.hpp" +#include "oatpp/concurrency/SpinLock.hpp" #include #include diff --git a/src/oatpp/utils/Random.hpp b/src/oatpp/utils/Random.hpp index 993ccd6f..35f46f8f 100644 --- a/src/oatpp/utils/Random.hpp +++ b/src/oatpp/utils/Random.hpp @@ -25,7 +25,7 @@ #ifndef oatpp_utils_Random_hpp #define oatpp_utils_Random_hpp -#include "oatpp/core/concurrency/SpinLock.hpp" +#include "oatpp/concurrency/SpinLock.hpp" #include "oatpp/Types.hpp" #include diff --git a/src/oatpp/web/server/AsyncHttpConnectionHandler.hpp b/src/oatpp/web/server/AsyncHttpConnectionHandler.hpp index b999590b..41fc7941 100644 --- a/src/oatpp/web/server/AsyncHttpConnectionHandler.hpp +++ b/src/oatpp/web/server/AsyncHttpConnectionHandler.hpp @@ -28,7 +28,7 @@ #include "oatpp/web/server/HttpProcessor.hpp" #include "oatpp/network/ConnectionHandler.hpp" #include "oatpp/async/Executor.hpp" -#include "oatpp/core/concurrency/SpinLock.hpp" +#include "oatpp/concurrency/SpinLock.hpp" #include diff --git a/src/oatpp/web/server/HttpConnectionHandler.cpp b/src/oatpp/web/server/HttpConnectionHandler.cpp index aaf78766..56a31efb 100644 --- a/src/oatpp/web/server/HttpConnectionHandler.cpp +++ b/src/oatpp/web/server/HttpConnectionHandler.cpp @@ -27,7 +27,7 @@ #include "oatpp/web/protocol/http/incoming/Request.hpp" #include "oatpp/web/protocol/http/Http.hpp" -#include "oatpp/core/concurrency/Thread.hpp" +#include "oatpp/concurrency/Utils.hpp" #include "oatpp/core/data/buffer/IOBuffer.hpp" @@ -105,15 +105,15 @@ void HttpConnectionHandler::handleConnection(const provider::ResourceHandle 1) { concurrency -= 1; } /* Set thread affinity group CPUs [0..cpu_count - 1]. Leave one cpu free of workers */ - oatpp::concurrency::setThreadAffinityToCpuRange(thread.native_handle(), - 0, - concurrency - 1 /* -1 because 0-based index */); + oatpp::concurrency::Utils::setThreadAffinityToCpuRange(thread.native_handle(), + 0, + concurrency - 1 /* -1 because 0-based index */); thread.detach(); } diff --git a/src/oatpp/web/server/HttpConnectionHandler.hpp b/src/oatpp/web/server/HttpConnectionHandler.hpp index 4c43bdb4..e9e312c8 100644 --- a/src/oatpp/web/server/HttpConnectionHandler.hpp +++ b/src/oatpp/web/server/HttpConnectionHandler.hpp @@ -27,7 +27,7 @@ #include "oatpp/web/server/HttpProcessor.hpp" #include "oatpp/network/ConnectionHandler.hpp" -#include "oatpp/core/concurrency/SpinLock.hpp" +#include "oatpp/concurrency/SpinLock.hpp" #include