Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchao412 committed Aug 7, 2023
1 parent 568ffd3 commit 8ce625d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Common/VersionConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//VersionConfig.h.in
#define V_BUILD_TIME "2023-08-01_17:54:37"
#define V_GIT_INFO "master_v3.0.0-168-gda97086a"
19 changes: 19 additions & 0 deletions Common/define.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,24 @@ inline vector<std::string> string_split(const string& srcStr, const string& deli
return vec;
}

inline void bind_thread_to_cpu(std::thread* ptrthread)
{
if(nullptr == ptrthread)
{
return;
}
static std::size_t cpunum = std::thread::hardware_concurrency();
static std::size_t cpuidx = 0;
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET((cpuidx++)%cpunum,&cpuset);
int rc =pthread_setaffinity_np(ptrthread->native_handle(),sizeof(cpu_set_t), &cpuset);
if (rc != 0)
{
PSS_LOGGER_ERROR("[bind_thread_to_cpu]Error calling pthread_setaffinity_np:{}",rc);
}
return;
}

//接口函数模板
using Logic_message_dispose_fn = std::function<int(const CMessage_Source&, std::shared_ptr<CMessage_Packet>, std::shared_ptr<CMessage_Packet>)>;
5 changes: 3 additions & 2 deletions PSS_ASIO/Common/IoContextPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ CIoContextPool::CIoContextPool(std::size_t pool_size): next_io_context_(0)
void CIoContextPool::run()
{
// Create a pool of threads to run all of the io_contexts.
std::vector<std::shared_ptr<asio::thread> > threads;
std::vector<std::shared_ptr<std::thread> > threads;
for (std::size_t i = 0; i < io_contexts_.size(); ++i)
{
std::shared_ptr<asio::thread> thread(new asio::thread(std::bind(&IoContextRun, io_contexts_[i])));
std::shared_ptr<std::thread> thread(new std::thread(std::bind(&IoContextRun, io_contexts_[i])));
threads.push_back(thread);
bind_thread_to_cpu(thread.get());
}

// Wait for all threads in the pool to exit.
Expand Down

0 comments on commit 8ce625d

Please sign in to comment.