Skip to content

Commit

Permalink
Align with recent zenoh-c changes for shm api correction
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowhatter committed Sep 10, 2024
1 parent 68ad8f8 commit a7cbd1b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
7 changes: 3 additions & 4 deletions include/zenoh/api/shm/buffer/zshm.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace zenoh {
/// @brief An immutable SHM buffer
class ZShm : public Owned<::z_owned_shm_t> {
friend class ZShmMut;
ZShm(zenoh::detail::null_object_t) : Owned(nullptr){};
ZShm(zenoh::detail::null_object_t) : Owned(nullptr) {};
friend struct interop::detail::Converter;

public:
Expand All @@ -48,12 +48,11 @@ class ZShm : public Owned<::z_owned_shm_t> {
std::size_t len() const { return ::z_shm_len(interop::as_loaned_c_ptr(*this)); }

/// @brief Create a new ZShmMut from ZShm.
/// @param immut immutable buffer
/// @param immut immutable buffer, NOTE: the value will not be moved if nullopt returned
/// @return mutable buffer or empty option if buffer mutation is impossible
static std::optional<ZShmMut> try_mutate(ZShm&& immut) {
z_owned_shm_mut_t mut_inner;
::z_shm_mut_try_from_immut(&mut_inner, z_move(immut._0));
if (::z_internal_check(mut_inner)) {
if (Z_OK == ::z_shm_mut_try_from_immut(&mut_inner, z_move(immut._0), &immut._0)) {
return std::move(interop::as_owned_cpp_ref<ZShmMut>(&mut_inner));
}
return std::nullopt;
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh/api/shm/client_storage/client_storage.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ShmClientStorage : public Owned<::z_owned_shm_client_storage_t> {
// fill list with clients
for (std::move_iterator<I> it = begin; it != end; ++it) {
__ZENOH_RESULT_CHECK(
zc_shm_client_list_add_client(it->first, z_move(it->second._0), interop::as_loaned_c_ptr(list)), err,
zc_shm_client_list_add_client(interop::as_loaned_c_ptr(list), it->first, z_move(it->second._0)), err,
"Failed to form list of SHM clients");
}

Expand Down
6 changes: 3 additions & 3 deletions include/zenoh/api/shm/provider/types.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef ::z_alloc_alignment_t AllocAlignment;

class MemoryLayout : public Owned<::z_owned_memory_layout_t> {
friend class PosixShmProvider;
MemoryLayout(zenoh::detail::null_object_t) : Owned(nullptr){};
MemoryLayout(zenoh::detail::null_object_t) : Owned(nullptr) {};
friend struct interop::detail::Converter;

public:
Expand All @@ -62,14 +62,14 @@ class MemoryLayout : public Owned<::z_owned_memory_layout_t> {
size_t size() const {
size_t size;
AllocAlignment alignment;
z_memory_layout_get_data(&size, &alignment, interop::as_loaned_c_ptr(*this));
z_memory_layout_get_data(interop::as_loaned_c_ptr(*this), &size, &alignment);
return size;
}

AllocAlignment alignment() const {
size_t size;
AllocAlignment alignment;
z_memory_layout_get_data(&size, &alignment, interop::as_loaned_c_ptr(*this));
z_memory_layout_get_data(interop::as_loaned_c_ptr(*this), &size, &alignment);
return alignment;
}
};
Expand Down
15 changes: 8 additions & 7 deletions tests/zenohc/shm_api.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ int test_shm_buffer(ZShmMut&& buf) {
ASSERT_VALID(immut);
ASSERT_NULL(buf);

ZShm immut2(immut);
ASSERT_VALID(immut);
ASSERT_VALID(immut2);

{
auto mut = ZShm::try_mutate(std::move(immut2));
ASSERT_FALSE(mut);
ASSERT_NULL(immut2);
ZShm immut2(immut);
ASSERT_VALID(immut);
ASSERT_VALID(immut2);
{
auto mut = ZShm::try_mutate(std::move(immut2));
ASSERT_FALSE(mut);
ASSERT_VALID(immut2);
}
}

auto mut = ZShm::try_mutate(std::move(immut));
Expand Down

0 comments on commit a7cbd1b

Please sign in to comment.