74 lines
2.0 KiB
C++
74 lines
2.0 KiB
C++
#include <iostream>
|
|
#include <mind.h>
|
|
#include <componentThread.h>
|
|
|
|
namespace smo {
|
|
|
|
Mind mind;
|
|
|
|
void Mind::initialize()
|
|
{
|
|
/* Distribute threads across available CPUs */
|
|
try
|
|
{
|
|
ComponentThread::distributeAndPinThreadsAcrossCpus();
|
|
}
|
|
catch (const std::exception& e)
|
|
{
|
|
std::cerr << "Salmanoff couldn't distribute the mind threads across "
|
|
"the CPUs, so performance may be suboptimal.\n"
|
|
"Error: " << e.what() << "\n";
|
|
}
|
|
|
|
/* Jolt the threads, then start them */
|
|
ComponentThread::joltAllMindThreadsReq(
|
|
[]()
|
|
{
|
|
ComponentThread::threadsHaveBeenJolted.store(true);
|
|
std::cout << "Mrntt: All mind threads JOLTed." << "\n";
|
|
ComponentThread::startAllMindThreadsReq(
|
|
[]()
|
|
{
|
|
std::cout << "Mrntt: All mind threads started." << "\n";
|
|
}
|
|
);
|
|
}
|
|
);
|
|
}
|
|
|
|
void Mind::finalizeReq(std::function<void()> callback)
|
|
{
|
|
/* If the threads haven't been jolted, we need to do that first, because
|
|
* otherwise they'll just enter their main loops and wait for control
|
|
* messages from mrntt after processing the exit request.
|
|
*/
|
|
if (!ComponentThread::threadsHaveBeenJolted.load())
|
|
{
|
|
ComponentThread::joltAllMindThreadsReq(
|
|
[callback]()
|
|
{
|
|
ComponentThread::threadsHaveBeenJolted.store(true);
|
|
ComponentThread::exitAllMindThreadsReq(
|
|
[callback]()
|
|
{
|
|
std::cout << "Mrntt: All mind threads exited." << "\n";
|
|
if (callback) { callback(); }
|
|
}
|
|
);
|
|
}
|
|
);
|
|
}
|
|
else
|
|
{
|
|
ComponentThread::exitAllMindThreadsReq(
|
|
[callback]()
|
|
{
|
|
std::cout << "Mrntt: All mind threads exited." << "\n";
|
|
if (callback) { callback(); }
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
} // namespace smo
|