diff --git a/src/oatpp/core/async/Executor.cpp b/src/oatpp/core/async/Executor.cpp index fd0b9ca6..5976b125 100644 --- a/src/oatpp/core/async/Executor.cpp +++ b/src/oatpp/core/async/Executor.cpp @@ -78,13 +78,14 @@ void Executor::SubmissionProcessor::detach() { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Executor -Executor::Executor(v_int32 processorWorkersCount, v_int32 ioWorkersCount, v_int32 timerWorkersCount, bool useIOEventWorker) +Executor::Executor(v_int32 processorWorkersCount, v_int32 ioWorkersCount, v_int32 timerWorkersCount, v_int32 ioWorkerType) : m_balancer(0) { processorWorkersCount = chooseProcessorWorkersCount(processorWorkersCount); ioWorkersCount = chooseIOWorkersCount(processorWorkersCount, ioWorkersCount); timerWorkersCount = chooseTimerWorkersCount(timerWorkersCount); + ioWorkerType = chooseIOWorkerType(ioWorkerType); for(v_int32 i = 0; i < processorWorkersCount; i ++) { m_processorWorkers.push_back(std::make_shared()); @@ -93,14 +94,26 @@ Executor::Executor(v_int32 processorWorkersCount, v_int32 ioWorkersCount, v_int3 m_allWorkers.insert(m_allWorkers.end(), m_processorWorkers.begin(), m_processorWorkers.end()); std::vector> ioWorkers; - if(useIOEventWorker) { - for (v_int32 i = 0; i < ioWorkersCount; i++) { - ioWorkers.push_back(std::make_shared()); + + switch(ioWorkerType) { + + case IO_WORKER_TYPE_NAIVE: { + for (v_int32 i = 0; i < ioWorkersCount; i++) { + ioWorkers.push_back(std::make_shared()); + } + break; } - } else { - for (v_int32 i = 0; i < ioWorkersCount; i++) { - ioWorkers.push_back(std::make_shared()); + + case IO_WORKER_TYPE_EVENT: { + for (v_int32 i = 0; i < ioWorkersCount; i++) { + ioWorkers.push_back(std::make_shared()); + } + break; } + + default: + throw std::runtime_error("[oatpp::async::Executor::Executor()]: Error. Unknown IO worker type."); + } linkWorkers(ioWorkers); @@ -148,6 +161,20 @@ v_int32 Executor::chooseTimerWorkersCount(v_int32 timerWorkersCount) { throw std::runtime_error("[oatpp::async::Executor::chooseTimerWorkersCount()]: Error. Invalid timer workers count specified."); } +v_int32 Executor::chooseIOWorkerType(v_int32 ioWorkerType) { + + if(ioWorkerType == VALUE_SUGGESTED) { +#if defined(WIN32) || defined(_WIN32) + return IO_WORKER_TYPE_NAIVE; +#else + return IO_WORKER_TYPE_EVENT; +#endif + } + + return ioWorkerType; + +} + void Executor::linkWorkers(const std::vector>& workers) { m_allWorkers.insert(m_allWorkers.end(), workers.begin(), workers.end()); diff --git a/src/oatpp/core/async/Executor.hpp b/src/oatpp/core/async/Executor.hpp index 0b3e4cef..e7e9d1d6 100644 --- a/src/oatpp/core/async/Executor.hpp +++ b/src/oatpp/core/async/Executor.hpp @@ -84,6 +84,17 @@ public: * Special value to indicate that Executor should choose it's own the value of specified parameter. */ static constexpr const v_int32 VALUE_SUGGESTED = -1000; +public: + + /** + * IO Worker type naive. + */ + static constexpr const v_int32 IO_WORKER_TYPE_NAIVE = 0; + + /** + * IO Worker type event. + */ + static constexpr const v_int32 IO_WORKER_TYPE_EVENT = 1; private: std::atomic m_balancer; private: @@ -93,6 +104,7 @@ private: static v_int32 chooseProcessorWorkersCount(v_int32 processorWorkersCount); static v_int32 chooseIOWorkersCount(v_int32 processorWorkersCount, v_int32 ioWorkersCount); static v_int32 chooseTimerWorkersCount(v_int32 timerWorkersCount); + static v_int32 chooseIOWorkerType(v_int32 ioWorkerType); void linkWorkers(const std::vector>& workers); public: @@ -101,16 +113,12 @@ public: * @param processorWorkersCount - number of data processing workers. * @param ioWorkersCount - number of I/O processing workers. * @param timerWorkersCount - number of timer processing workers. + * @param IOWorkerType */ Executor(v_int32 processorWorkersCount = VALUE_SUGGESTED, v_int32 ioWorkersCount = VALUE_SUGGESTED, v_int32 timerWorkersCount = VALUE_SUGGESTED, -#if defined(WIN32) || defined(_WIN32) - bool useIOEventWorker = false -#else - bool useIOEventWorker = true -#endif - ); + v_int32 ioWorkerType = VALUE_SUGGESTED); /** * Non-virtual Destructor.