Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use this_thread::sleep_for on Windows #375

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions controller_manager/src/controller_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
#include <controller_manager/controller_loader.h>
#include <controller_manager_msgs/ControllerState.h>

#ifdef _WIN32
#include <chrono>
#include <thread>
#endif

namespace controller_manager{


Expand Down Expand Up @@ -147,10 +152,17 @@ bool ControllerManager::loadController(const std::string& name)

// get reference to controller list
int free_controllers_list = (current_controllers_list_ + 1) % 2;
while (ros::ok() && free_controllers_list == used_by_realtime_){
while (ros::ok() && free_controllers_list == used_by_realtime_)
{
if (!ros::ok())
{
return false;
}
#ifdef _WIN32
std::this_thread::sleep_for(std::chrono::microseconds(200));
#else
usleep(200);
#endif
}
std::vector<ControllerSpec>
&from = controllers_lists_[current_controllers_list_],
Expand Down Expand Up @@ -259,10 +271,17 @@ bool ControllerManager::loadController(const std::string& name)
// Destroys the old controllers list when the realtime thread is finished with it.
int former_current_controllers_list_ = current_controllers_list_;
current_controllers_list_ = free_controllers_list;
while (ros::ok() && used_by_realtime_ == former_current_controllers_list_){
while (ros::ok() && used_by_realtime_ == former_current_controllers_list_)
{
if (!ros::ok())
{
return false;
}
#ifdef _WIN32
std::this_thread::sleep_for(std::chrono::microseconds(200));
#else
usleep(200);
#endif
}
from.clear();

Expand All @@ -282,10 +301,17 @@ bool ControllerManager::unloadController(const std::string &name)

// get reference to controller list
int free_controllers_list = (current_controllers_list_ + 1) % 2;
while (ros::ok() && free_controllers_list == used_by_realtime_){
while (ros::ok() && free_controllers_list == used_by_realtime_)
{
if (!ros::ok())
{
return false;
}
#ifdef _WIN32
std::this_thread::sleep_for(std::chrono::microseconds(200));
#else
usleep(200);
#endif
}
std::vector<ControllerSpec>
&from = controllers_lists_[current_controllers_list_],
Expand Down Expand Up @@ -322,10 +348,17 @@ bool ControllerManager::unloadController(const std::string &name)
ROS_DEBUG("Realtime switches over to new controller list");
int former_current_controllers_list_ = current_controllers_list_;
current_controllers_list_ = free_controllers_list;
while (ros::ok() && used_by_realtime_ == former_current_controllers_list_){
while (ros::ok() && used_by_realtime_ == former_current_controllers_list_)
{
if (!ros::ok())
{
return false;
}
#ifdef _WIN32
std::this_thread::sleep_for(std::chrono::microseconds(200));
#else
usleep(200);
#endif
}
ROS_DEBUG("Destruct controller");
from.clear();
Expand Down Expand Up @@ -503,10 +536,17 @@ bool ControllerManager::switchController(const std::vector<std::string>& start_c

// wait until switch is finished
ROS_DEBUG("Request atomic controller switch from realtime loop");
while (ros::ok() && please_switch_){
while (ros::ok() && please_switch_)
{
if (!ros::ok())
{
return false;
}
#ifdef _WIN32
std::this_thread::sleep_for(std::chrono::microseconds(100));
#else
usleep(100);
#endif
}
start_request_.clear();
stop_request_.clear();
Expand Down