Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions rclc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ add_library(${PROJECT_NAME}
src/rclc/node.c
src/rclc/executor_handle.c
src/rclc/executor.c
src/rclc/sleep.c
)
if("${rcl_VERSION}" VERSION_LESS "1.0.0")
target_sources(${PROJECT_NAME} PRIVATE src/rclc/rcl_wait_set_is_valid_backport.c)
Expand Down
9 changes: 1 addition & 8 deletions rclc/include/rclc/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,9 @@ extern "C"

#include "rclc/executor_handle.h"
#include "rclc/types.h"
#include "rclc/sleep.h"
#include "rclc/visibility_control.h"

#ifdef WIN32
#include <Windows.h>
#define rclc_sleep_ms(x) Sleep(x)
#else
#include <unistd.h>
#define rclc_sleep_ms(x) usleep(x * 1000)
#endif

/*! \file executor.h
\brief The RCLC-Executor provides an Executor based on RCL in which all callbacks are
processed in a user-defined order.
Expand Down
48 changes: 48 additions & 0 deletions rclc/include/rclc/sleep.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2019 - for information on the respective copyright owner
// see the NOTICE file and/or the repository https://github.com/ros2/rclc.
// Copyright 2014 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef RCLC__SLEEP_H_
#define RCLC__SLEEP_H_

#if __cplusplus
extern "C"
{
#endif

#include "rclc/visibility_control.h"

/**
* Waits for milliseconds.
*
* * <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | No
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] ms milliseconds to wait
*/
RCLC_PUBLIC
void
rclc_sleep_ms(
unsigned int ms);

#if __cplusplus
}
#endif

#endif // RCLC__SLEEP_H_
34 changes: 34 additions & 0 deletions rclc/src/rclc/sleep.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2019 - for information on the respective copyright owner
// see the NOTICE file and/or the repository https://github.com/ros2/rclc.
// Copyright 2014 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "rclc/sleep.h"

#ifdef WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif

void
rclc_sleep_ms(
unsigned int ms)
{
#ifdef WIN32
Sleep(ms);
#else
usleep(ms * 1000);
#endif
}