Skip to content

Commit

Permalink
Signal manager thread role
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Apr 15, 2024
1 parent 2b6ee63 commit 48214dc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions nano/lib/signal_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <nano/lib/signal_manager.hpp>
#include <nano/lib/thread_roles.hpp>
#include <nano/lib/utility.hpp>

#include <boost/asio.hpp>
Expand All @@ -10,7 +11,8 @@
nano::signal_manager::signal_manager () :
work (boost::asio::make_work_guard (ioc))
{
smthread = boost::thread ([&ioc = ioc] () {
thread = std::thread ([&ioc = ioc] () {
nano::thread_role::set (nano::thread_role::name::signal_manager);
ioc.run ();
});
}
Expand All @@ -21,7 +23,7 @@ nano::signal_manager::~signal_manager ()
/// io_context::run() function will exit once all other work has completed.
work.reset ();
ioc.stop ();
smthread.join ();
thread.join ();
}

nano::signal_manager::signal_descriptor::signal_descriptor (std::shared_ptr<boost::asio::signal_set> sigset_a, signal_manager & sigman_a, std::function<void (int)> handler_func_a, bool repeat_a) :
Expand Down
4 changes: 2 additions & 2 deletions nano/lib/signal_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

#include <boost/asio.hpp>
#include <boost/system/error_code.hpp>
#include <boost/thread.hpp>

#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <vector>

namespace nano
Expand Down Expand Up @@ -73,7 +73,7 @@ class signal_manager final
std::vector<signal_descriptor> descriptor_list;

/** thread to service the signal manager io context */
boost::thread smthread;
std::thread thread;
};

}
3 changes: 3 additions & 0 deletions nano/lib/thread_roles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ std::string nano::thread_role::get_string (nano::thread_role::name role)
case nano::thread_role::name::network_reachout:
thread_role_name_string = "Net reachout";
break;
case nano::thread_role::name::signal_manager:
thread_role_name_string = "Signal manager";
break;
default:
debug_assert (false && "nano::thread_role::get_string unhandled thread role");
}
Expand Down
1 change: 1 addition & 0 deletions nano/lib/thread_roles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum class name
network_cleanup,
network_keepalive,
network_reachout,
signal_manager,
};

std::string_view to_string (name);
Expand Down

0 comments on commit 48214dc

Please sign in to comment.