Skip to content

Commit

Permalink
add mutex lock when writing is_emergency_mode variable
Browse files Browse the repository at this point in the history
  • Loading branch information
mmurooka committed Jul 26, 2015
1 parent 70f68b2 commit ff6cbe4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rtc/EmergencyStopper/EmergencyStopper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "EmergencyStopper.h"
#include "../SoftErrorLimiter/beep.h"

typedef coil::Guard<coil::Mutex> Guard;

// Module specification
// <rtc-template block="module_spec">
static const char* emergencystopper_spec[] =
Expand Down Expand Up @@ -179,6 +181,7 @@ RTC::ReturnCode_t EmergencyStopper::onActivated(RTC::UniqueId ec_id)
RTC::ReturnCode_t EmergencyStopper::onDeactivated(RTC::UniqueId ec_id)
{
std::cout << m_profile.instance_name<< ": onDeactivated(" << ec_id << ")" << std::endl;
Guard guard(m_mutex);
if (is_stop_mode) {
is_stop_mode = false;
recover_time = 0;
Expand Down Expand Up @@ -229,6 +232,7 @@ RTC::ReturnCode_t EmergencyStopper::onExecute(RTC::UniqueId ec_id)
if (m_emergencySignalIn.isNew()){
m_emergencySignalIn.read();
if (!is_stop_mode) {
Guard guard(m_mutex);
std::cerr << "[" << m_profile.instance_name << "] emergencySignal is set!" << std::endl;
is_stop_mode = true;
}
Expand Down Expand Up @@ -338,6 +342,7 @@ RTC::ReturnCode_t EmergencyStopper::onExecute(RTC::UniqueId ec_id)

bool EmergencyStopper::stopMotion()
{
Guard guard(m_mutex);
if (!is_stop_mode) {
is_stop_mode = true;
std::cerr << "[" << m_profile.instance_name << "] stopMotion is called" << std::endl;
Expand All @@ -347,6 +352,7 @@ bool EmergencyStopper::stopMotion()

bool EmergencyStopper::releaseMotion()
{
Guard guard(m_mutex);
if (is_stop_mode) {
is_stop_mode = false;
std::cerr << "[" << m_profile.instance_name << "] releaseMotion is called" << std::endl;
Expand Down
1 change: 1 addition & 0 deletions rtc/EmergencyStopper/EmergencyStopper.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class EmergencyStopper
interpolator* m_interpolator;
std::queue<std::vector<double> > m_input_posture_queue;
int emergency_stopper_beep_count, emergency_stopper_beep_freq;
coil::Mutex m_mutex;
};


Expand Down

0 comments on commit ff6cbe4

Please sign in to comment.