diff --git a/core/base/memory/MemoryPool.cpp b/core/base/memory/MemoryPool.cpp index 0e9e2a7e..577ed32d 100644 --- a/core/base/memory/MemoryPool.cpp +++ b/core/base/memory/MemoryPool.cpp @@ -32,7 +32,7 @@ oatpp::concurrency::SpinLock::Atom MemoryPool::POOLS_ATOM(false); std::unordered_map MemoryPool::POOLS; std::atomic MemoryPool::poolIdCounter(0); -ThreadDistributedMemoryPool::ThreadDistributedMemoryPool(const std::string& name, v_int32 entrySize, v_int32 chunkSize, v_word32 shardsCount) +ThreadDistributedMemoryPool::ThreadDistributedMemoryPool(const std::string& name, v_int32 entrySize, v_int32 chunkSize, v_int32 shardsCount) : m_shardsCount(shardsCount) , m_shards(new MemoryPool*[m_shardsCount]) { @@ -50,7 +50,7 @@ ThreadDistributedMemoryPool::~ThreadDistributedMemoryPool(){ void* ThreadDistributedMemoryPool::obtain() { static std::hash hashFunction; - static thread_local v_word32 hash = hashFunction(std::this_thread::get_id()) % m_shardsCount; + static thread_local v_int32 hash = hashFunction(std::this_thread::get_id()) % m_shardsCount; return m_shards[hash]->obtain(); } diff --git a/core/base/memory/MemoryPool.hpp b/core/base/memory/MemoryPool.hpp index 3b6c662f..38cbf1df 100644 --- a/core/base/memory/MemoryPool.hpp +++ b/core/base/memory/MemoryPool.hpp @@ -175,7 +175,7 @@ private: MemoryPool** m_shards; public: ThreadDistributedMemoryPool(const std::string& name, v_int32 entrySize, v_int32 chunkSize, - v_word32 shardsCount = OATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT); + v_int32 shardsCount = OATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT); virtual ~ThreadDistributedMemoryPool(); void* obtain(); }; diff --git a/core/concurrency/Thread.cpp b/core/concurrency/Thread.cpp index fb85da19..21babe6a 100644 --- a/core/concurrency/Thread.cpp +++ b/core/concurrency/Thread.cpp @@ -38,12 +38,19 @@ v_int32 Thread::getThreadSuggestedCpuIndex(std::thread::id threadId, v_int32 cpu } v_int32 Thread::assignThreadToCpu(std::thread::native_handle_type nativeHandle, v_int32 cpuIndex) { + return assignThreadToCpuRange(nativeHandle, cpuIndex, cpuIndex); +} + +v_int32 Thread::assignThreadToCpuRange(std::thread::native_handle_type nativeHandle, v_int32 fromCpu, v_int32 toCpu) { #if defined(_GNU_SOURCE) cpu_set_t cpuset; CPU_ZERO(&cpuset); - CPU_SET(cpuIndex, &cpuset); + for(v_int32 i = fromCpu; i <= toCpu; i++) { + CPU_SET(cpuIndex, &cpuset); + } + v_int32 result = pthread_setaffinity_np(nativeHandle, sizeof(cpu_set_t), &cpuset); if (result != 0) { diff --git a/core/concurrency/Thread.hpp b/core/concurrency/Thread.hpp index 9d734f91..2871b581 100644 --- a/core/concurrency/Thread.hpp +++ b/core/concurrency/Thread.hpp @@ -44,6 +44,7 @@ private: public: static v_int32 getThreadSuggestedCpuIndex(std::thread::id threadId, v_int32 cpuCount); static v_int32 assignThreadToCpu(std::thread::native_handle_type nativeHandle, v_int32 cpuIndex); + static v_int32 assignThreadToCpuRange(std::thread::native_handle_type nativeHandle, v_int32 fromCpu, v_int32 toCpu); static v_int32 getHardwareConcurrency(); private: std::thread m_thread; diff --git a/web/server/HttpConnectionHandler.cpp b/web/server/HttpConnectionHandler.cpp index 135ad8fc..fddebb32 100644 --- a/web/server/HttpConnectionHandler.cpp +++ b/web/server/HttpConnectionHandler.cpp @@ -75,8 +75,7 @@ void HttpConnectionHandler::handleConnection(const std::shared_ptrget_id(), concurrency); - oatpp::concurrency::Thread::assignThreadToCpu(thread.getStdThread()->native_handle(), cpu); + oatpp::concurrency::Thread::assignThreadToCpuRange(thread.getStdThread()->native_handle(), 0, concurrency); thread.detach(); }