Skip to content

Commit

Permalink
Merge pull request #174 from dkroenke/iox-#171-Roudi-message-queue-th…
Browse files Browse the repository at this point in the history
…read-startup

 iox-#171 added option to defer mq thread startup
  • Loading branch information
dkroenke authored Jul 9, 2020
2 parents 74c153f + 5ef3f0c commit 2c8025b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,33 @@ using namespace iox::units::duration_literals;
class RouDiMultiProcess
{
public:

// indicate whether the message queue thread will start directly or deferred
// this is important for derived classes which may need to initialize their members before the thread starts
enum class MQThreadStart {
IMMEDIATE,
DEFER_START
};


RouDiMultiProcess& operator=(const RouDiMultiProcess& other) = delete;
RouDiMultiProcess(const RouDiMultiProcess& other) = delete;

RouDiMultiProcess(RouDiMemoryInterface& roudiMemoryInteface,
PortManager& portManager,
const MonitoringMode f_monitoringMode = MonitoringMode::ON,
const bool f_killProcessesInDestructor = true);
const bool f_killProcessesInDestructor = true,
const MQThreadStart mqThreadStart = MQThreadStart::IMMEDIATE);

virtual ~RouDiMultiProcess();

protected:

/// @brief Starts the roudi message queue thread
/// Once this is done, applications can register and Roudi is fully operational.
void startMQThread();


/// @brief Stops threads and kills all process known to RouDi
/// Called in d'tor
///
Expand Down
15 changes: 12 additions & 3 deletions iceoryx_posh/source/roudi/roudi_multi_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ namespace roudi
RouDiMultiProcess::RouDiMultiProcess(RouDiMemoryInterface& roudiMemoryInterface,
PortManager& portManager,
const MonitoringMode monitoringMode,
const bool killProcessesInDestructor)
const bool killProcessesInDestructor,
const MQThreadStart mqThreadStart)
: m_killProcessesInDestructor(killProcessesInDestructor)
, m_runThreads(true)
, m_roudiMemoryInterface(&roudiMemoryInterface)
Expand All @@ -54,15 +55,23 @@ RouDiMultiProcess::RouDiMultiProcess(RouDiMemoryInterface& roudiMemoryInterface,
m_processManagementThread = std::thread(&RouDiMultiProcess::processThread, this);
pthread_setname_np(m_processManagementThread.native_handle(), "ProcessMgmt");

m_processMQThread = std::thread(&RouDiMultiProcess::mqThread, this);
pthread_setname_np(m_processMQThread.native_handle(), "MQ-processing");
if(mqThreadStart == MQThreadStart::IMMEDIATE) {
startMQThread();
}

}

RouDiMultiProcess::~RouDiMultiProcess()
{
shutdown();
}

void RouDiMultiProcess::startMQThread()
{
m_processMQThread = std::thread(&RouDiMultiProcess::mqThread, this);
pthread_setname_np(m_processMQThread.native_handle(), "MQ-processing");
}

void RouDiMultiProcess::shutdown()
{
m_processIntrospection.stop();
Expand Down

0 comments on commit 2c8025b

Please sign in to comment.