Skip to content

Commit

Permalink
Move loaned sample meta-data initialization to generic PSMX implement…
Browse files Browse the repository at this point in the history
…ation

Signed-off-by: Dennis Potman <[email protected]>
  • Loading branch information
dpotman committed Sep 18, 2023
1 parent 566ae36 commit 030802a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/core/ddsc/src/dds_psmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ dds_return_t dds_psmx_topic_cleanup_generic (struct dds_psmx_topic *psmx_topic)
dds_loaned_sample_t * dds_psmx_endpoint_request_loan (struct dds_psmx_endpoint *psmx_endpoint, uint32_t sz)
{
assert (psmx_endpoint->ops.request_loan);
return psmx_endpoint->ops.request_loan (psmx_endpoint, sz);
dds_loaned_sample_t *loaned_sample = psmx_endpoint->ops.request_loan (psmx_endpoint, sz);
loaned_sample->metadata->sample_state = DDS_LOANED_SAMPLE_STATE_UNITIALIZED;
loaned_sample->metadata->sample_size = sz;
loaned_sample->metadata->instance_id = psmx_endpoint->psmx_topic->psmx_instance->instance_id;
loaned_sample->metadata->data_type = psmx_endpoint->psmx_topic->data_type;
return loaned_sample;
}

static dds_psmx_instance_id_t get_psmx_instance_id (const struct ddsi_domaingv * gv, const char *config_name)
Expand Down
4 changes: 0 additions & 4 deletions src/core/ddsc/tests/psmx_cdds_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,6 @@ static dds_loaned_sample_t * cdds_psmx_ep_request_loan (struct dds_psmx_endpoint
ls->loan_origin.origin_kind = DDS_LOAN_ORIGIN_KIND_PSMX;
ls->loan_origin.psmx_endpoint = (struct dds_psmx_endpoint *) cep;
ls->metadata = dds_alloc (sizeof (*ls->metadata));
ls->metadata->sample_state = DDS_LOANED_SAMPLE_STATE_UNITIALIZED;
ls->metadata->sample_size = size_requested;
ls->metadata->instance_id = cep->c.psmx_topic->psmx_instance->instance_id;
ls->metadata->data_type = cep->c.psmx_topic->data_type;
ls->sample_ptr = dds_alloc (sz);
memset (ls->sample_ptr, 0, sz);
ddsrt_atomic_st32 (&ls->refc, 1);
Expand Down
13 changes: 4 additions & 9 deletions src/psmx_iox/src/psmx_iox_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,11 @@ iox_psmx_endpoint::~iox_psmx_endpoint()

struct iox_loaned_sample : public dds_loaned_sample_t
{
iox_loaned_sample(struct dds_psmx_endpoint * origin, uint32_t sz, const void * ptr, dds_loaned_sample_state_t st);
iox_loaned_sample(struct dds_psmx_endpoint * origin, const void * iox_payload);
~iox_loaned_sample();
};

iox_loaned_sample::iox_loaned_sample(struct dds_psmx_endpoint * origin, uint32_t sz, const void * iox_payload, dds_loaned_sample_state_t st):
iox_loaned_sample::iox_loaned_sample(struct dds_psmx_endpoint * origin, const void * iox_payload):
dds_loaned_sample_t {
.ops = ls_ops,
.loan_origin = { .origin_kind = DDS_LOAN_ORIGIN_KIND_PSMX, .psmx_endpoint = origin },
Expand All @@ -370,10 +370,6 @@ iox_loaned_sample::iox_loaned_sample(struct dds_psmx_endpoint * origin, uint32_t
.refc = { .v = 1 }
}
{
metadata->sample_state = st;
metadata->data_type = origin->psmx_topic->data_type;
metadata->instance_id = origin->psmx_topic->psmx_instance->instance_id;
metadata->sample_size = sz;
}

iox_loaned_sample::~iox_loaned_sample()
Expand Down Expand Up @@ -519,7 +515,7 @@ static dds_loaned_sample_t * iox_req_loan(struct dds_psmx_endpoint *psmx_endpoin
const std::lock_guard<std::mutex> lock(cpp_ep_ptr->lock);
publisher->loan(size_requested, iox::CHUNK_DEFAULT_USER_PAYLOAD_ALIGNMENT, sizeof(dds_psmx_metadata_t), alignof(dds_psmx_metadata_t))
.and_then([&](const void* iox_payload) {
loaned_sample = new iox_loaned_sample(psmx_endpoint, size_requested, iox_payload, DDS_LOANED_SAMPLE_STATE_UNITIALIZED);
loaned_sample = new iox_loaned_sample(psmx_endpoint, iox_payload);
})
.or_else([&](auto& error) {
std::cerr << ERROR_PREFIX "failure getting loan" << iox::popo::asStringLiteral(error) << std::endl;
Expand Down Expand Up @@ -570,8 +566,7 @@ static dds_return_t iox_write(struct dds_psmx_endpoint * psmx_endpoint, dds_loan

static dds_loaned_sample_t * incoming_sample_to_loan(iox_psmx_endpoint *psmx_endpoint, const void *iox_payload)
{
auto metadata = static_cast<const dds_psmx_metadata_t *>(iox::mepoo::ChunkHeader::fromUserPayload(iox_payload)->userHeader());
return new iox_loaned_sample(psmx_endpoint, metadata->sample_size, iox_payload, metadata->sample_state);
return new iox_loaned_sample(psmx_endpoint, iox_payload);
}

static dds_loaned_sample_t * iox_take(struct dds_psmx_endpoint * psmx_endpoint)
Expand Down

0 comments on commit 030802a

Please sign in to comment.