Skip to content

Commit

Permalink
Move stdatomic helper to rcutils (#324)
Browse files Browse the repository at this point in the history
* move stdatomic_helper* to rcutils

Signed-off-by: William Woodall <william@osrfoundation.org>

* refactor after moving stdatomic_helper.h to rcutils

Signed-off-by: William Woodall <william@osrfoundation.org>
  • Loading branch information
wjwwood authored Nov 8, 2018
1 parent 5d12f54 commit 9351fd8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 980 deletions.
6 changes: 3 additions & 3 deletions rcl/src/rcl/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ extern "C"
#include "rcl/expand_topic_name.h"
#include "rcl/remap.h"
#include "rcutils/logging_macros.h"
#include "rcutils/stdatomic_helper.h"
#include "rmw/error_handling.h"
#include "rmw/rmw.h"
#include "rmw/validate_full_topic_name.h"

#include "./common.h"
#include "./stdatomic_helper.h"

typedef struct rcl_client_impl_t
{
Expand Down Expand Up @@ -269,14 +269,14 @@ rcl_send_request(const rcl_client_t * client, const void * ros_request, int64_t
}
RCL_CHECK_ARGUMENT_FOR_NULL(ros_request, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(sequence_number, RCL_RET_INVALID_ARGUMENT);
*sequence_number = rcl_atomic_load_int64_t(&client->impl->sequence_number);
*sequence_number = rcutils_atomic_load_int64_t(&client->impl->sequence_number);
if (rmw_send_request(
client->impl->rmw_handle, ros_request, sequence_number) != RMW_RET_OK)
{
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
return RCL_RET_ERROR;
}
rcl_atomic_exchange_int64_t(&client->impl->sequence_number, *sequence_number);
rcutils_atomic_exchange_int64_t(&client->impl->sequence_number, *sequence_number);
return RCL_RET_OK;
}

Expand Down
16 changes: 8 additions & 8 deletions rcl/src/rcl/rcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ extern "C"
#include <string.h>

#include "./arguments_impl.h"
#include "./stdatomic_helper.h"
#include "rcl/arguments.h"
#include "rcl/error_handling.h"
#include "rcutils/logging_macros.h"
#include "rcutils/stdatomic_helper.h"
#include "rmw/error_handling.h"

static atomic_bool __rcl_is_initialized = ATOMIC_VAR_INIT(false);
Expand Down Expand Up @@ -56,8 +56,8 @@ __clean_up_init()
if (NULL != global_args->impl && RCL_RET_OK != rcl_arguments_fini(global_args)) {
rcl_reset_error();
}
rcl_atomic_store(&__rcl_instance_id, 0);
rcl_atomic_store(&__rcl_is_initialized, false);
rcutils_atomic_store(&__rcl_instance_id, 0);
rcutils_atomic_store(&__rcl_is_initialized, false);
}

rcl_ret_t
Expand All @@ -71,7 +71,7 @@ rcl_init(int argc, char const * const * argv, rcl_allocator_t allocator)
if (argc > 0) {
RCL_CHECK_ARGUMENT_FOR_NULL(argv, RCL_RET_INVALID_ARGUMENT);
}
if (rcl_atomic_exchange_bool(&__rcl_is_initialized, true)) {
if (rcutils_atomic_exchange_bool(&__rcl_is_initialized, true)) {
RCL_SET_ERROR_MSG("rcl_init called while already initialized");
return RCL_RET_ALREADY_INIT;
}
Expand Down Expand Up @@ -123,8 +123,8 @@ rcl_init(int argc, char const * const * argv, rcl_allocator_t allocator)
rcutils_logging_set_default_logger_level(global_args->impl->log_level);
}

rcl_atomic_store(&__rcl_instance_id, ++__rcl_next_unique_id);
if (rcl_atomic_load_uint64_t(&__rcl_instance_id) == 0) {
rcutils_atomic_store(&__rcl_instance_id, ++__rcl_next_unique_id);
if (rcutils_atomic_load_uint64_t(&__rcl_instance_id) == 0) {
// Roll over occurred.
__rcl_next_unique_id--; // roll back to avoid the next call succeeding.
RCL_SET_ERROR_MSG("unique rcl instance ids exhausted");
Expand Down Expand Up @@ -152,13 +152,13 @@ rcl_shutdown()
uint64_t
rcl_get_instance_id()
{
return rcl_atomic_load_uint64_t(&__rcl_instance_id);
return rcutils_atomic_load_uint64_t(&__rcl_instance_id);
}

bool
rcl_ok()
{
return rcl_atomic_load_bool(&__rcl_is_initialized);
return rcutils_atomic_load_bool(&__rcl_is_initialized);
}

#ifdef __cplusplus
Expand Down
129 changes: 0 additions & 129 deletions rcl/src/rcl/stdatomic_helper.h

This file was deleted.

Loading

0 comments on commit 9351fd8

Please sign in to comment.