Skip to content

Commit

Permalink
Switch to RAII for saved_msg_data.
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette committed Feb 7, 2024
1 parent 7ef08b4 commit 7cfc81b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion rmw_zenoh_cpp/src/detail/rmw_data_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ saved_msg_data::saved_msg_data(zc_owned_payload_t p, uint64_t recv_ts, const uin
memcpy(publisher_gid, pub_gid, 16);
}

saved_msg_data::~saved_msg_data()
{
z_drop(z_move(payload));
}

void rmw_subscription_data_t::attach_condition(std::condition_variable * condition_variable)
{
std::lock_guard<std::mutex> lock(condition_mutex_);
Expand Down Expand Up @@ -92,7 +97,6 @@ void rmw_subscription_data_t::add_new_message(
// queue if it is non-empty.
if (!message_queue_.empty()) {
std::unique_ptr<saved_msg_data> old = std::move(message_queue_.front());
z_drop(z_move(old->payload));
message_queue_.pop_front();
}
}
Expand Down
2 changes: 2 additions & 0 deletions rmw_zenoh_cpp/src/detail/rmw_data_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ struct saved_msg_data
{
explicit saved_msg_data(zc_owned_payload_t p, uint64_t recv_ts, const uint8_t pub_gid[16]);

~saved_msg_data();

zc_owned_payload_t payload;
uint64_t recv_timestamp;
uint8_t publisher_gid[16];
Expand Down
1 change: 0 additions & 1 deletion rmw_zenoh_cpp/src/rmw_zenoh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,6 @@ static rmw_ret_t __rmw_take(
}

*taken = true;
z_drop(&msg_data->payload);

// TODO(clalancette): fill in source_timestamp
message_info->source_timestamp = 0;
Expand Down

0 comments on commit 7cfc81b

Please sign in to comment.