move oatpp/core/concurrency/* to the root folder

This commit is contained in:
Leonid Stryzhevskyi 2024-04-23 03:19:49 +03:00
parent acf598433d
commit 36f298c8d4
21 changed files with 103 additions and 98 deletions

View File

@ -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

View File

@ -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

View File

@ -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.");
}

View File

@ -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 <tuple>
#include <mutex>

View File

@ -29,6 +29,7 @@
#include "./Coroutine.hpp"
#include "./CoroutineWaitList.hpp"
#include "oatpp/async/utils/FastQueue.hpp"
#include "oatpp/concurrency/SpinLock.hpp"
#include <thread>
#include <condition_variable>

View File

@ -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 {

View File

@ -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 <thread>
#include <mutex>

View File

@ -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 <thread>
#include <mutex>

View File

@ -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 <thread>
#include <mutex>

View File

@ -22,19 +22,15 @@
*
***************************************************************************/
#include "Thread.hpp"
#if defined(_GNU_SOURCE)
#include <pthread.h>
#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<v_int32>(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;
}
}}
}}

View File

@ -0,0 +1,69 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* 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 <thread>
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 <br>
* else return std::thread::hardware_concurrency() <br>
* else return 1. <br>
*/
static v_int32 getHardwareConcurrency();
};
}}
#endif //oatpp_concurrency_Utils_hpp

View File

@ -1,62 +0,0 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* 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 <thread>
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 <br>
* else return std::thread::hardware_concurrency() <br>
* else return 1. <br>
*/
v_int32 getHardwareConcurrency();
}}
#endif /* concurrency_Thread_hpp */

View File

@ -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 {

View File

@ -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 <unordered_map>

View File

@ -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 <mutex>
#include <condition_variable>

View File

@ -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 <random>

View File

@ -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 <unordered_map>

View File

@ -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<data
std::thread thread(&HttpProcessor::Task::run, std::move(HttpProcessor::Task(m_components, connection, this)));
/* Get hardware concurrency -1 in order to have 1cpu free of workers. */
v_int32 concurrency = oatpp::concurrency::getHardwareConcurrency();
v_int32 concurrency = oatpp::concurrency::Utils::getHardwareConcurrency();
if (concurrency > 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();
}

View File

@ -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 <unordered_map>