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

Wait set two words #175

Merged
merged 5 commits into from
Nov 27, 2017
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
2 changes: 1 addition & 1 deletion rmw_fastrtps_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ add_library(rmw_fastrtps_cpp
src/rmw_topic_names_and_types.cpp
src/rmw_trigger_guard_condition.cpp
src/rmw_wait.cpp
src/rmw_waitset.cpp
src/rmw_wait_set.cpp
src/ros_message_serialization.cpp
src/type_support_common.cpp
)
Expand Down
26 changes: 13 additions & 13 deletions rmw_fastrtps_cpp/src/rmw_wait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#include "rmw_fastrtps_cpp/custom_client_info.hpp"
#include "rmw_fastrtps_cpp/custom_service_info.hpp"
#include "rmw_fastrtps_cpp/custom_subscriber_info.hpp"
#include "types/custom_waitset_info.hpp"
#include "types/custom_wait_set_info.hpp"
#include "types/guard_condition.hpp"

// helper function for wait
bool
check_waitset_for_data(
check_wait_set_for_data(
const rmw_subscriptions_t * subscriptions,
const rmw_guard_conditions_t * guard_conditions,
const rmw_services_t * services,
Expand Down Expand Up @@ -82,26 +82,26 @@ rmw_wait(
rmw_guard_conditions_t * guard_conditions,
rmw_services_t * services,
rmw_clients_t * clients,
rmw_waitset_t * waitset,
rmw_wait_set_t * wait_set,
const rmw_time_t * wait_timeout)
{
if (!waitset) {
RMW_SET_ERROR_MSG("Waitset handle is null");
if (!wait_set) {
RMW_SET_ERROR_MSG("wait set handle is null");
return RMW_RET_ERROR;
}
CustomWaitsetInfo * waitset_info = static_cast<CustomWaitsetInfo *>(waitset->data);
if (!waitset_info) {
CustomWaitsetInfo * wait_set_info = static_cast<CustomWaitsetInfo *>(wait_set->data);
if (!wait_set_info) {
RMW_SET_ERROR_MSG("Waitset info struct is null");
return RMW_RET_ERROR;
}
std::mutex * conditionMutex = &waitset_info->condition_mutex;
std::condition_variable * conditionVariable = &waitset_info->condition;
std::mutex * conditionMutex = &wait_set_info->condition_mutex;
std::condition_variable * conditionVariable = &wait_set_info->condition;
if (!conditionMutex) {
RMW_SET_ERROR_MSG("Mutex for waitset was null");
RMW_SET_ERROR_MSG("Mutex for wait set was null");
return RMW_RET_ERROR;
}
if (!conditionVariable) {
RMW_SET_ERROR_MSG("Condition variable for waitset was null");
RMW_SET_ERROR_MSG("Condition variable for wait set was null");
return RMW_RET_ERROR;
}

Expand Down Expand Up @@ -196,7 +196,7 @@ rmw_wait(
conditionVariable->wait(lock);
} else {
auto predicate = [subscriptions, guard_conditions, services, clients]() {
return check_waitset_for_data(subscriptions, guard_conditions, services, clients);
return check_wait_set_for_data(subscriptions, guard_conditions, services, clients);
};
auto n = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::seconds(wait_timeout->sec));
Expand All @@ -215,7 +215,7 @@ rmw_wait(
// Even if this was a non-blocking wait, signal a timeout if there's no data.
// This makes the return behavior consistent with rcl expectations for zero timeout value.
// Do this before detaching the listeners because the data gets cleared for guard conditions.
bool hasData = check_waitset_for_data(subscriptions, guard_conditions, services, clients);
bool hasData = check_wait_set_for_data(subscriptions, guard_conditions, services, clients);
if (!hasData && wait_timeout && wait_timeout->sec == 0 && wait_timeout->nsec == 0) {
timeout = true;
}
Expand Down
95 changes: 95 additions & 0 deletions rmw_fastrtps_cpp/src/rmw_wait_set.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// 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 "rmw/allocators.h"
#include "rmw/error_handling.h"
#include "rmw/rmw.h"
#include "rmw/impl/cpp/macros.hpp"

#include "rmw_fastrtps_cpp/identifier.hpp"
#include "types/custom_wait_set_info.hpp"

extern "C"
{
rmw_wait_set_t *
rmw_create_wait_set(size_t max_conditions)
{
(void)max_conditions;
rmw_wait_set_t * wait_set = rmw_wait_set_allocate();
CustomWaitsetInfo * wait_set_info = nullptr;

// From here onward, error results in unrolling in the goto fail block.
if (!wait_set) {
RMW_SET_ERROR_MSG("failed to allocate wait set");
goto fail;
}
wait_set->implementation_identifier = eprosima_fastrtps_identifier;
wait_set->data = rmw_allocate(sizeof(CustomWaitsetInfo));
// This should default-construct the fields of CustomWaitsetInfo
wait_set_info = static_cast<CustomWaitsetInfo *>(wait_set->data);
RMW_TRY_PLACEMENT_NEW(wait_set_info, wait_set_info, goto fail, CustomWaitsetInfo, )
if (!wait_set_info) {
RMW_SET_ERROR_MSG("failed to construct wait set info struct");
goto fail;
}

return wait_set;

fail:
if (wait_set) {
if (wait_set->data) {
RMW_TRY_DESTRUCTOR_FROM_WITHIN_FAILURE(
wait_set_info->~CustomWaitsetInfo(), wait_set_info)
rmw_free(wait_set->data);
}
rmw_wait_set_free(wait_set);
}
return nullptr;
}

rmw_ret_t
rmw_destroy_wait_set(rmw_wait_set_t * wait_set)
{
if (!wait_set) {
RMW_SET_ERROR_MSG("wait set handle is null");
return RMW_RET_ERROR;
}
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
wait set handle,
wait_set->implementation_identifier, eprosima_fastrtps_identifier,
return RMW_RET_ERROR)

auto result = RMW_RET_OK;
auto wait_set_info = static_cast<CustomWaitsetInfo *>(wait_set->data);
if (!wait_set_info) {
RMW_SET_ERROR_MSG("wait set info is null");
return RMW_RET_ERROR;
}
std::mutex * conditionMutex = &wait_set_info->condition_mutex;
if (!conditionMutex) {
RMW_SET_ERROR_MSG("wait set mutex is null");
return RMW_RET_ERROR;
}

if (wait_set->data) {
if (wait_set_info) {
RMW_TRY_DESTRUCTOR(
wait_set_info->~CustomWaitsetInfo(), wait_set_info, result = RMW_RET_ERROR)
}
rmw_free(wait_set->data);
}
rmw_wait_set_free(wait_set);
return result;
}
} // extern "C"
95 changes: 0 additions & 95 deletions rmw_fastrtps_cpp/src/rmw_waitset.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef TYPES__CUSTOM_WAITSET_INFO_HPP_
#define TYPES__CUSTOM_WAITSET_INFO_HPP_
#ifndef TYPES__CUSTOM_WAIT_SET_INFO_HPP_
#define TYPES__CUSTOM_WAIT_SET_INFO_HPP_

#include <condition_variable>
#include <mutex>
Expand All @@ -24,4 +24,4 @@ typedef struct CustomWaitsetInfo
std::mutex condition_mutex;
} CustomWaitsetInfo;

#endif // TYPES__CUSTOM_WAITSET_INFO_HPP_
#endif // TYPES__CUSTOM_WAIT_SET_INFO_HPP_