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 diff --git a/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp b/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp index 7f748bc6ce..9f70558be4 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; // 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)); - 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/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/include/rclcpp/rclcpp.hpp b/rclcpp/include/rclcpp/rclcpp.hpp index 72ca557a75..94fbeae287 100644 --- a/rclcpp/include/rclcpp/rclcpp.hpp +++ b/rclcpp/include/rclcpp/rclcpp.hpp @@ -27,24 +27,26 @@ 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::nanoseconds operator "" _s(long double s) { - return std::chrono::duration(s); + return std::chrono::duration_cast( + 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::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 92cab04506..b2afd8c8e6 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)); } } @@ -131,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; } 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) {