Skip to content

Commit

Permalink
Add 'tools::Thread_pinning::is_init()' method.
Browse files Browse the repository at this point in the history
  • Loading branch information
kouchy committed Jul 30, 2024
1 parent fe0d852 commit c5a571e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions include/Tools/Thread_pinning/Thread_pinning.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace tools
class Thread_pinning
{
public:
static bool is_init();
static void init();
static void destroy();
static void pin(const size_t puid);
Expand Down
3 changes: 2 additions & 1 deletion src/Scheduler/Scheduler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Scheduler/Scheduler.hpp"
#include "Tools/Exception/exception.hpp"
#include "Tools/Thread_pinning/Thread_pinning.hpp"

#include <iostream>
#include <sstream>
Expand Down Expand Up @@ -201,5 +202,5 @@ Scheduler::generate_pipeline()

if (solution.empty()) this->schedule();

return this->instantiate_pipeline(1, false, true, this->perform_threads_mapping());
return this->instantiate_pipeline(1, false, tools::Thread_pinning::is_init(), this->perform_threads_mapping());
}
20 changes: 13 additions & 7 deletions src/Tools/Thread_pinning/Thread_pinning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ static bool g_is_init = false;
static std::mutex g_mtx;
static bool g_enable_logs = false;

bool
Thread_pinning::is_init()
{
return g_is_init;
}

void
Thread_pinning::init()
{
if (!g_is_init)
if (!Thread_pinning::is_init())
{
g_mtx.lock();
if (!g_is_init)
if (!Thread_pinning::is_init())
{
g_is_init = true;

Expand Down Expand Up @@ -60,10 +66,10 @@ Thread_pinning::init()
void
Thread_pinning::destroy()
{
if (g_is_init)
if (Thread_pinning::is_init())
{
g_mtx.lock();
if (g_is_init)
if (Thread_pinning::is_init())
{
#ifdef SPU_HWLOC
/* Destroy topology object. */
Expand Down Expand Up @@ -95,7 +101,7 @@ Thread_pinning::pin(const size_t puid)
{
g_mtx.lock();
#ifdef SPU_HWLOC
if (g_is_init)
if (Thread_pinning::is_init())
{
int pu_depth = hwloc_get_type_or_below_depth(g_topology, HWLOC_OBJ_PU);
hwloc_obj_t pu_obj = hwloc_get_obj_by_depth(g_topology, pu_depth, puid);
Expand Down Expand Up @@ -162,7 +168,7 @@ Thread_pinning::pin(const std::string hwloc_objects)
g_mtx.lock();

#ifdef SPU_HWLOC
if (g_is_init)
if (Thread_pinning::is_init())
{
// Objects parsing
std::vector<std::string> hwloc_objects_vector = Thread_pinning_utils::thread_parser(hwloc_objects);
Expand Down Expand Up @@ -242,7 +248,7 @@ Thread_pinning::unpin()
{
g_mtx.lock();
#ifdef SPU_HWLOC
if (!g_is_init)
if (!Thread_pinning::is_init())
{
if (g_enable_logs)
{
Expand Down

0 comments on commit c5a571e

Please sign in to comment.