Spinscale: PuppetComponent takes PuppetApplication&
This commit is contained in:
@@ -5,10 +5,10 @@
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <spinscale/callback.h>
|
||||
#include <spinscale/puppetApplication.h>
|
||||
|
||||
namespace smo {
|
||||
|
||||
class Mind;
|
||||
class ComponentThread;
|
||||
|
||||
class Component
|
||||
@@ -27,11 +27,13 @@ class PuppetComponent
|
||||
: public Component
|
||||
{
|
||||
public:
|
||||
PuppetComponent(Mind &parent, const std::shared_ptr<ComponentThread> &thread);
|
||||
PuppetComponent(
|
||||
PuppetApplication &parent,
|
||||
const std::shared_ptr<ComponentThread> &thread);
|
||||
~PuppetComponent() = default;
|
||||
|
||||
public:
|
||||
Mind &parent;
|
||||
PuppetApplication &parent;
|
||||
};
|
||||
|
||||
} // namespace smo
|
||||
|
||||
@@ -31,6 +31,9 @@ public:
|
||||
void exitAllPuppetThreadsReq(
|
||||
Callback<puppetThreadLifetimeMgmtOpCbFn> callback);
|
||||
|
||||
// CPU distribution method
|
||||
void distributeAndPinThreadsAcrossCpus();
|
||||
|
||||
protected:
|
||||
// Collection of PuppetThread instances
|
||||
std::vector<std::shared_ptr<PuppetThread>> componentThreads;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <spinscale/component.h>
|
||||
#include <spinscale/puppetApplication.h>
|
||||
#include <marionette/marionette.h>
|
||||
|
||||
namespace smo {
|
||||
@@ -9,7 +10,7 @@ Component::Component(const std::shared_ptr<ComponentThread> &thread)
|
||||
}
|
||||
|
||||
PuppetComponent::PuppetComponent(
|
||||
Mind &parent, const std::shared_ptr<ComponentThread> &thread)
|
||||
PuppetApplication &parent, const std::shared_ptr<ComponentThread> &thread)
|
||||
: Component(thread),
|
||||
parent(parent)
|
||||
{
|
||||
|
||||
@@ -201,4 +201,21 @@ void PuppetApplication::exitAllPuppetThreadsReq(
|
||||
}
|
||||
}
|
||||
|
||||
void PuppetApplication::distributeAndPinThreadsAcrossCpus()
|
||||
{
|
||||
int cpuCount = ComponentThread::getAvailableCpuCount();
|
||||
|
||||
// Distribute and pin threads across CPUs
|
||||
int threadIndex = 0;
|
||||
for (auto& thread : componentThreads)
|
||||
{
|
||||
int targetCpu = threadIndex % cpuCount;
|
||||
thread->pinToCpu(targetCpu);
|
||||
++threadIndex;
|
||||
}
|
||||
|
||||
std::cout << __func__ << ": Distributed " << threadIndex << " threads "
|
||||
<< "across " << cpuCount << " CPUs\n";
|
||||
}
|
||||
|
||||
} // namespace smo
|
||||
|
||||
Reference in New Issue
Block a user