Skip to content

Commit

Permalink
ifdef for shm
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernandez Cordero <[email protected]>
  • Loading branch information
ahcorde committed Dec 9, 2024
1 parent 26360a8 commit 385e012
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ class rmw_context_impl_s::Data final
throw std::runtime_error("Error configuring Zenoh session.");
}

#ifndef _MSC_VER
// Check if shm is enabled.
// z_owned_string_t shm_enabled;
// zc_config_get_from_str(z_loan(config), Z_CONFIG_SHARED_MEMORY_KEY, &shm_enabled);
// auto always_free_shm_enabled = rcpputils::make_scope_exit(
// [&shm_enabled]() {
// z_drop(z_move(shm_enabled));
// });
z_owned_string_t shm_enabled;
zc_config_get_from_str(z_loan(config), Z_CONFIG_SHARED_MEMORY_KEY, &shm_enabled);
auto always_free_shm_enabled = rcpputils::make_scope_exit(
[&shm_enabled]() {
z_drop(z_move(shm_enabled));
});
#endif

// Initialize the zenoh session.
if (z_open(&session_, z_move(config), NULL) != Z_OK) {
Expand Down Expand Up @@ -166,30 +168,31 @@ class rmw_context_impl_s::Data final

// Initialize the shm manager if shared_memory is enabled in the config.
shm_provider_ = std::nullopt;
// if (strncmp(
// z_string_data(z_loan(shm_enabled)),
// "true",
// z_string_len(z_loan(shm_enabled))) == 0)
// {
// // TODO(yuyuan): determine the default alignment of SHM
// z_alloc_alignment_t alignment = {5};
// z_owned_memory_layout_t layout;
// z_memory_layout_new(&layout, SHM_BUFFER_SIZE_MB * 1024 * 1024, alignment);

// z_owned_shm_provider_t provider;
// if (z_posix_shm_provider_new(&provider, z_loan(layout)) != Z_OK) {
// RMW_ZENOH_LOG_ERROR_NAMED("rmw_zenoh_cpp", "Unable to create an SHM provider.");
// throw std::runtime_error("Unable to create an SHM provider.");
// }
// shm_provider_ = provider;
// }
// auto free_shm_provider = rcpputils::make_scope_exit(
// [this]() {
// if (shm_provider_.has_value()) {
// z_drop(z_move(shm_provider_.value()));
// }
// });

#ifndef _MSC_VER
if (strncmp(
z_string_data(z_loan(shm_enabled)),
"true",
z_string_len(z_loan(shm_enabled))) == 0)
{
// TODO(yuyuan): determine the default alignment of SHM
z_alloc_alignment_t alignment = {5};
z_owned_memory_layout_t layout;
z_memory_layout_new(&layout, SHM_BUFFER_SIZE_MB * 1024 * 1024, alignment);

z_owned_shm_provider_t provider;
if (z_posix_shm_provider_new(&provider, z_loan(layout)) != Z_OK) {
RMW_ZENOH_LOG_ERROR_NAMED("rmw_zenoh_cpp", "Unable to create an SHM provider.");
throw std::runtime_error("Unable to create an SHM provider.");
}
shm_provider_ = provider;
}
auto free_shm_provider = rcpputils::make_scope_exit(
[this]() {
if (shm_provider_.has_value()) {
z_drop(z_move(shm_provider_.value()));
}
});
#endif
graph_guard_condition_ = std::make_unique<rmw_guard_condition_t>();
graph_guard_condition_->implementation_identifier = rmw_zenoh_cpp::rmw_zenoh_identifier;
graph_guard_condition_->data = &guard_condition_data_;
Expand All @@ -216,7 +219,9 @@ class rmw_context_impl_s::Data final
});

close_session.cancel();
// free_shm_provider.cancel();
#ifndef _MSC_VER
free_shm_provider.cancel();
#endif _MSC_VER
undeclare_z_sub.cancel();
}

Expand Down

0 comments on commit 385e012

Please sign in to comment.