-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf51d9e
commit 9255490
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ Author: 李柯鹏 <[email protected]> | |
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
#include <thread> | ||
#include <string_view> | ||
#if __has_include(<filesystem>) | ||
#include <filesystem> | ||
|
@@ -33,6 +34,9 @@ class MYFRAME_EXPORT Common final { | |
static bool IsAbsolutePath(const std::string& path); | ||
|
||
static std::vector<std::string_view> SplitMsgName(const std::string& name); | ||
|
||
static int SetThreadAffinity(std::thread* t, int cpu_core); | ||
static int SetSelfThreadAffinity(int cpu_core); | ||
}; | ||
|
||
} // namespace myframe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ Author: 李柯鹏 <[email protected]> | |
#include "myframe/msg.h" | ||
#include "myframe/worker.h" | ||
#include "myframe/app.h" | ||
#include "myframe/common.h" | ||
|
||
namespace myframe { | ||
|
||
|
@@ -60,6 +61,18 @@ void WorkerContext::Join() { | |
} | ||
} | ||
|
||
bool WorkerContext::SetThreadAffinity(int cpu_core) { | ||
if (runing_.load()) { | ||
if (0 == Common::SetThreadAffinity(&th_, cpu_core)) { | ||
return true; | ||
} | ||
LOG(WARNING) << GetName() << " bind cpu " << cpu_core << " failed"; | ||
} else { | ||
LOG(WARNING) << GetName() << " not runing, skip SetThreadAffinity"; | ||
} | ||
return false; | ||
} | ||
|
||
void WorkerContext::Initialize() { | ||
mailbox_.SetAddr(worker_->GetWorkerName()); | ||
worker_->Init(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters