From 2a9b82bfba2d146a8cf1738af0674995d78a673e Mon Sep 17 00:00:00 2001 From: William Woodall Date: Wed, 11 Mar 2015 22:41:10 -0700 Subject: [PATCH 1/7] [windows] use unsigned long to fix warning --- rclcpp/include/rclcpp/executor.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rclcpp/include/rclcpp/executor.hpp b/rclcpp/include/rclcpp/executor.hpp index 237082534d..1980b294f3 100644 --- a/rclcpp/include/rclcpp/executor.hpp +++ b/rclcpp/include/rclcpp/executor.hpp @@ -270,7 +270,7 @@ class Executor })); } // Use the number of subscriptions to allocate memory in the handles - size_t number_of_subscriptions = subs.size(); + unsigned long number_of_subscriptions = subs.size(); rmw_subscriptions_t subscriber_handles; subscriber_handles.subscriber_count = number_of_subscriptions; // TODO(wjwwood): Avoid redundant malloc's @@ -291,7 +291,7 @@ class Executor } // Use the number of services to allocate memory in the handles - size_t number_of_services = services.size(); + unsigned long number_of_services = services.size(); rmw_services_t service_handles; service_handles.service_count = number_of_services; // TODO(esteve): Avoid redundant malloc's @@ -312,7 +312,7 @@ class Executor } // Use the number of clients to allocate memory in the handles - size_t number_of_clients = clients.size(); + unsigned long number_of_clients = clients.size(); rmw_clients_t client_handles; client_handles.client_count = number_of_clients; // TODO: Avoid redundant malloc's @@ -335,7 +335,8 @@ class Executor // Use the number of guard conditions to allocate memory in the handles // Add 2 to the number for the ctrl-c guard cond and the executor's size_t start_of_timer_guard_conds = 2; - size_t number_of_guard_conds = timers.size() + start_of_timer_guard_conds; + unsigned long number_of_guard_conds = + timers.size() + start_of_timer_guard_conds; rmw_guard_conditions_t guard_condition_handles; guard_condition_handles.guard_condition_count = number_of_guard_conds; // TODO(wjwwood): Avoid redundant malloc's From 5a03ec1d0ec4a82e0c404ae4dfae34b11fe292a5 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Wed, 11 Mar 2015 22:41:44 -0700 Subject: [PATCH 2/7] [windows] use macro to declare thread local storage --- rclcpp/include/rclcpp/utilities.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rclcpp/include/rclcpp/utilities.hpp b/rclcpp/include/rclcpp/utilities.hpp index 92cab04506..1e03b19edd 100644 --- a/rclcpp/include/rclcpp/utilities.hpp +++ b/rclcpp/include/rclcpp/utilities.hpp @@ -27,6 +27,7 @@ #include #include +#include #include // Determine if sigaction is available @@ -89,7 +90,7 @@ namespace namespace rclcpp { -__thread size_t thread_id = 0; +RMW_THREAD_LOCAL size_t thread_id = 0; namespace utilities { @@ -115,6 +116,7 @@ init(int argc, char *argv[]) throw std::runtime_error( std::string("Failed to set SIGINT signal handler: (" + std::to_string(errno) + ")") + + // TODO(wjwwood): use strerror_r on POSIX and strerror_s on Windows. std::strerror(errno)); } } From 1e5b98f167d085e83e37dcd62d89ced2f5fb3572 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Thu, 12 Mar 2015 02:00:54 -0700 Subject: [PATCH 3/7] [windows] fix compiler errors and warnings --- .../include/rclcpp/executors/multi_threaded_executor.hpp | 4 ++-- rclcpp/include/rclcpp/rclcpp.hpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp b/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp index 7f748bc6ce..d8d9d498f0 100644 --- a/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp +++ b/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp @@ -58,11 +58,11 @@ class MultiThreadedExecutor : public executor::Executor std::vector threads; { std::lock_guard wait_lock(wait_mutex_); - size_t thread_id = 1; + size_t thread_id_ = 1; for (size_t i = number_of_threads_; i > 0; --i) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); - auto func = std::bind(&MultiThreadedExecutor::run, this, thread_id++); + auto func = std::bind(&MultiThreadedExecutor::run, this, thread_id_++); threads.emplace_back(func); } } diff --git a/rclcpp/include/rclcpp/rclcpp.hpp b/rclcpp/include/rclcpp/rclcpp.hpp index 72ca557a75..d4004fd98e 100644 --- a/rclcpp/include/rclcpp/rclcpp.hpp +++ b/rclcpp/include/rclcpp/rclcpp.hpp @@ -27,21 +27,21 @@ namespace rclcpp { -constexpr std::chrono::seconds operator "" _s(unsigned long long s) +const std::chrono::seconds operator "" _s(unsigned long long s) { return std::chrono::seconds(s); } -constexpr std::chrono::duration operator "" _s(long double s) +const std::chrono::duration operator "" _s(long double s) { return std::chrono::duration(s); } -constexpr std::chrono::nanoseconds +const std::chrono::nanoseconds operator "" _ns(unsigned long long ns) { return std::chrono::nanoseconds(ns); } -constexpr std::chrono::duration +const std::chrono::duration operator "" _ns(long double ns) { return std::chrono::duration(ns); From 22b53b991da097558f42ee1bcbdc119a1a8f0ddd Mon Sep 17 00:00:00 2001 From: William Woodall Date: Fri, 13 Mar 2015 20:41:10 -0700 Subject: [PATCH 4/7] [windows] workaround for compiler error in Windows See: https://connect.microsoft.com/VisualStudio/feedback/details/1179590 --- rclcpp/include/rclcpp/rclcpp.hpp | 10 ++++++---- rclcpp/include/rclcpp/utilities.hpp | 5 ++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/rclcpp/include/rclcpp/rclcpp.hpp b/rclcpp/include/rclcpp/rclcpp.hpp index d4004fd98e..848308d711 100644 --- a/rclcpp/include/rclcpp/rclcpp.hpp +++ b/rclcpp/include/rclcpp/rclcpp.hpp @@ -31,9 +31,10 @@ const std::chrono::seconds operator "" _s(unsigned long long s) { return std::chrono::seconds(s); } -const std::chrono::duration operator "" _s(long double s) +const std::chrono::nanoseconds operator "" _s(long double s) { - return std::chrono::duration(s); + return std::chrono::duration_cast( + std::chrono::duration(s)); } const std::chrono::nanoseconds @@ -41,10 +42,11 @@ operator "" _ns(unsigned long long ns) { return std::chrono::nanoseconds(ns); } -const std::chrono::duration +const std::chrono::nanoseconds operator "" _ns(long double ns) { - return std::chrono::duration(ns); + return std::chrono::duration_cast( + std::chrono::duration(ns)); } using rclcpp::node::Node; diff --git a/rclcpp/include/rclcpp/utilities.hpp b/rclcpp/include/rclcpp/utilities.hpp index 1e03b19edd..b2afd8c8e6 100644 --- a/rclcpp/include/rclcpp/utilities.hpp +++ b/rclcpp/include/rclcpp/utilities.hpp @@ -133,13 +133,12 @@ get_global_sigint_guard_condition() return ::g_sigint_guard_cond_handle; } -template bool -sleep_for(const std::chrono::duration& sleep_duration) +sleep_for(const std::chrono::nanoseconds& nanoseconds) { // TODO: determine if posix's nanosleep(2) is more efficient here std::unique_lock lock(::g_interrupt_mutex); - auto cvs = ::g_interrupt_condition_variable.wait_for(lock, sleep_duration); + auto cvs = ::g_interrupt_condition_variable.wait_for(lock, nanoseconds); return cvs == std::cv_status::no_timeout; } From 81c4900e0184ab4e83a16785afae41da461d9f8e Mon Sep 17 00:00:00 2001 From: William Woodall Date: Fri, 13 Mar 2015 20:41:29 -0700 Subject: [PATCH 5/7] [windows] fix symbol exporting --- rclcpp/include/rclcpp/node.hpp | 3 ++- rclcpp/src/node_main.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/rclcpp/include/rclcpp/node.hpp b/rclcpp/include/rclcpp/node.hpp index bb54de58fd..c66d8f43cb 100644 --- a/rclcpp/include/rclcpp/node.hpp +++ b/rclcpp/include/rclcpp/node.hpp @@ -135,7 +135,8 @@ class Node } /* namespace node */ } /* namespace rclcpp */ -#define RCLCPP_REGISTER_NODE(Class) rclcpp::node::Node::SharedPtr \ +#define RCLCPP_REGISTER_NODE(Class) RMW_EXPORT \ +rclcpp::node::Node::SharedPtr \ create_node() \ { \ return rclcpp::node::Node::SharedPtr(new Class(rclcpp::contexts::default_context::DefaultContext::make_shared())); \ diff --git a/rclcpp/src/node_main.cpp b/rclcpp/src/node_main.cpp index 510b1bfeff..d6d07c44df 100644 --- a/rclcpp/src/node_main.cpp +++ b/rclcpp/src/node_main.cpp @@ -16,7 +16,7 @@ #include // This forward declaration is implemented by the RCLCPP_REGISTER_NODE macro -rclcpp::Node::SharedPtr create_node(); +RMW_IMPORT rclcpp::Node::SharedPtr create_node(); int main(int argc, char **argv) { From fd208336d33d13bb9e80e7c2c419e6a1aefd6142 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Mon, 16 Mar 2015 17:26:56 -0700 Subject: [PATCH 6/7] [style] replace tabs with spaces --- rclcpp/include/rclcpp/rclcpp.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rclcpp/include/rclcpp/rclcpp.hpp b/rclcpp/include/rclcpp/rclcpp.hpp index 848308d711..94fbeae287 100644 --- a/rclcpp/include/rclcpp/rclcpp.hpp +++ b/rclcpp/include/rclcpp/rclcpp.hpp @@ -34,7 +34,7 @@ const std::chrono::seconds operator "" _s(unsigned long long s) const std::chrono::nanoseconds operator "" _s(long double s) { return std::chrono::duration_cast( - std::chrono::duration(s)); + std::chrono::duration(s)); } const std::chrono::nanoseconds @@ -46,7 +46,7 @@ const std::chrono::nanoseconds operator "" _ns(long double ns) { return std::chrono::duration_cast( - std::chrono::duration(ns)); + std::chrono::duration(ns)); } using rclcpp::node::Node; From 30d7eb269e61648fc5d79b741195b7ee9ea9c934 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Mon, 16 Mar 2015 17:28:32 -0700 Subject: [PATCH 7/7] add a clarifying comment --- rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp b/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp index d8d9d498f0..9f70558be4 100644 --- a/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp +++ b/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp @@ -58,7 +58,7 @@ class MultiThreadedExecutor : public executor::Executor std::vector threads; { std::lock_guard wait_lock(wait_mutex_); - size_t thread_id_ = 1; + size_t thread_id_ = 1; // Use a _ suffix to avoid shadowing `rclcpp::thread_id` for (size_t i = number_of_threads_; i > 0; --i) { std::this_thread::sleep_for(std::chrono::milliseconds(100));