iid and tkmap are integral to this DDSI stack and should be part of it

They were made available from the DCPS layer to DDSI using some function pointers, but it makes more sense to have them as part of the DDSI core.

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2018-11-09 15:28:21 +01:00
parent 19202d9de8
commit 29f542b916
30 changed files with 221 additions and 213 deletions

View file

@ -13,7 +13,6 @@ PREPEND(srcs_ddsc "${CMAKE_CURRENT_LIST_DIR}/src"
dds_alloc.c
dds_builtin.c
dds_coherent.c
dds_iid.c
dds_participant.c
dds_reader.c
dds_writer.c
@ -24,7 +23,6 @@ PREPEND(srcs_ddsc "${CMAKE_CURRENT_LIST_DIR}/src"
dds_domain.c
dds_instance.c
dds_qos.c
dds_tkmap.c
dds_entity.c
dds_key.c
dds_querycond.c
@ -57,7 +55,6 @@ PREPEND(hdrs_private_ddsc "${CMAKE_CURRENT_LIST_DIR}/src"
dds__builtin.h
dds__domain.h
dds__entity.h
dds__iid.h
dds__init.h
dds__key.h
dds__listener.h
@ -71,7 +68,6 @@ PREPEND(hdrs_private_ddsc "${CMAKE_CURRENT_LIST_DIR}/src"
dds__rhc.h
dds__stream.h
dds__subscriber.h
dds__tkmap.h
dds__topic.h
dds__types.h
dds__write.h

View file

@ -1,28 +0,0 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef _DDS_IID_H_
#define _DDS_IID_H_
#include "dds__types.h"
#if defined (__cplusplus)
extern "C" {
#endif
void dds_iid_init (void);
void dds_iid_fini (void);
uint64_t dds_iid_gen (void);
#if defined (__cplusplus)
}
#endif
#endif

View file

@ -24,7 +24,7 @@ extern "C" {
struct rhc;
struct nn_xqos;
struct ddsi_serdata;
struct tkmap_instance;
struct ddsi_tkmap_instance;
struct proxy_writer_info;
struct rhc * dds_rhc_new (dds_reader * reader, const struct ddsi_sertopic * topic);
@ -36,7 +36,7 @@ uint32_t dds_rhc_lock_samples (struct rhc * rhc);
DDS_EXPORT bool dds_rhc_store
(
struct rhc * __restrict rhc, const struct proxy_writer_info * __restrict pwr_info,
struct ddsi_serdata * __restrict sample, struct tkmap_instance * __restrict tk
struct ddsi_serdata * __restrict sample, struct ddsi_tkmap_instance * __restrict tk
);
void dds_rhc_unregister_wr (struct rhc * __restrict rhc, const struct proxy_writer_info * __restrict pwr_info);
void dds_rhc_relinquish_ownership (struct rhc * __restrict rhc, const uint64_t wr_iid);

View file

@ -1,52 +0,0 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef _DDS_TKMAP_H_
#define _DDS_TKMAP_H_
#include "dds__types.h"
#include "os/os_atomics.h"
#if defined (__cplusplus)
extern "C" {
#endif
struct tkmap;
struct ddsi_serdata;
struct dds_topic;
struct tkmap_instance
{
struct ddsi_serdata * m_sample;
struct tkmap * m_map;
uint64_t m_iid;
os_atomic_uint32_t m_refc;
};
struct tkmap * dds_tkmap_new (void);
void dds_tkmap_free (_Inout_ _Post_invalid_ struct tkmap *tkmap);
void dds_tkmap_instance_ref (_In_ struct tkmap_instance *tk);
uint64_t dds_tkmap_lookup (_In_ struct tkmap *tkmap, _In_ const struct ddsi_serdata *serdata);
_Check_return_ bool dds_tkmap_get_key (_In_ struct tkmap * map, const struct ddsi_sertopic *topic, _In_ uint64_t iid, _Out_ void * sample);
_Check_return_ struct tkmap_instance * dds_tkmap_find(
_In_ struct ddsi_serdata * sd,
_In_ const bool rd,
_In_ const bool create);
_Check_return_ struct tkmap_instance * dds_tkmap_find_by_id (_In_ struct tkmap * map, _In_ uint64_t iid);
DDS_EXPORT _Check_return_ struct tkmap_instance * dds_tkmap_lookup_instance_ref (_In_ struct ddsi_serdata * sd);
DDS_EXPORT void dds_tkmap_instance_unref (_In_ struct tkmap_instance * tk);
#if defined (__cplusplus)
}
#endif
#endif

View file

@ -259,13 +259,6 @@ typedef struct dds_waitset
}
dds_waitset;
typedef struct dds_iid
{
uint64_t counter;
uint32_t key[4];
}
dds_iid;
/* Globals */
typedef struct dds_globals

View file

@ -10,7 +10,7 @@
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#include "dds__domain.h"
#include "dds__tkmap.h"
#include "ddsi/ddsi_tkmap.h"
static int dds_domain_compare (const int32_t * a, const int32_t * b)
{

View file

@ -1,79 +0,0 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#include "dds__iid.h"
#include "ddsi/q_time.h"
#include "ddsi/q_globals.h"
static os_mutex dds_iid_lock_g;
static dds_iid dds_iid_g;
static void dds_tea_encrypt (uint32_t v[2], const uint32_t k[4])
{
/* TEA encryption straight from Wikipedia */
uint32_t v0=v[0], v1=v[1], sum=0, i; /* set up */
uint32_t delta=0x9e3779b9; /* a key schedule constant */
uint32_t k0=k[0], k1=k[1], k2=k[2], k3=k[3]; /* cache key */
for (i=0; i < 32; i++) { /* basic cycle start */
sum += delta;
v0 += ((v1<<4) + k0) ^ (v1 + sum) ^ ((v1>>5) + k1);
v1 += ((v0<<4) + k2) ^ (v0 + sum) ^ ((v0>>5) + k3);
} /* end cycle */
v[0]=v0; v[1]=v1;
}
static void dds_tea_decrypt (uint32_t v[2], const uint32_t k[4])
{
uint32_t v0=v[0], v1=v[1], sum=0xC6EF3720, i; /* set up */
uint32_t delta=0x9e3779b9; /* a key schedule constant */
uint32_t k0=k[0], k1=k[1], k2=k[2], k3=k[3]; /* cache key */
for (i=0; i<32; i++) { /* basic cycle start */
v1 -= ((v0<<4) + k2) ^ (v0 + sum) ^ ((v0>>5) + k3);
v0 -= ((v1<<4) + k0) ^ (v1 + sum) ^ ((v1>>5) + k1);
sum -= delta;
} /* end cycle */
v[0]=v0; v[1]=v1;
}
uint64_t dds_iid_gen (void)
{
uint64_t iid;
union { uint64_t u64; uint32_t u32[2]; } tmp;
os_mutexLock (&dds_iid_lock_g);
tmp.u64 = ++dds_iid_g.counter;
dds_tea_encrypt (tmp.u32, dds_iid_g.key);
iid = tmp.u64;
os_mutexUnlock (&dds_iid_lock_g);
return iid;
}
void dds_iid_init (void)
{
union { uint64_t u64; uint32_t u32[2]; } tmp;
nn_wctime_t tnow = now ();
os_mutexInit (&dds_iid_lock_g);
dds_iid_g.key[0] = (uint32_t) ((uintptr_t) &dds_iid_g);
dds_iid_g.key[1] = (uint32_t) tnow.v;
dds_iid_g.key[2] = (uint32_t) (tnow.v >> 32);
dds_iid_g.key[3] = 0xdeadbeef;
tmp.u64 = 0;
dds_tea_decrypt (tmp.u32, dds_iid_g.key);
dds_iid_g.counter = tmp.u64;
}
void dds_iid_fini (void)
{
os_mutexDestroy (&dds_iid_lock_g);
}

View file

@ -15,11 +15,11 @@
#include "os/os.h"
#include "dds__init.h"
#include "dds__rhc.h"
#include "dds__tkmap.h"
#include "dds__iid.h"
#include "dds__domain.h"
#include "dds__err.h"
#include "dds__builtin.h"
#include "ddsi/ddsi_iid.h"
#include "ddsi/ddsi_tkmap.h"
#include "ddsi/ddsi_serdata.h"
#include "ddsi/q_servicelease.h"
#include "ddsi/q_entity.h"
@ -239,7 +239,6 @@ extern void dds_fini (void)
static int dds__init_plugin (void)
{
dds_iid_init ();
if (dds_global.m_dur_init) (dds_global.m_dur_init) ();
return 0;
}
@ -247,7 +246,6 @@ static int dds__init_plugin (void)
static void dds__fini_plugin (void)
{
if (dds_global.m_dur_fini) (dds_global.m_dur_fini) ();
dds_iid_fini ();
}
void ddsi_plugin_init (void)
@ -265,12 +263,6 @@ void ddsi_plugin_init (void)
ddsi_plugin.rhc_plugin.rhc_unregister_wr_fn = dds_rhc_unregister_wr;
ddsi_plugin.rhc_plugin.rhc_relinquish_ownership_fn = dds_rhc_relinquish_ownership;
ddsi_plugin.rhc_plugin.rhc_set_qos_fn = dds_rhc_set_qos;
ddsi_plugin.rhc_plugin.rhc_lookup_fn = dds_tkmap_lookup_instance_ref;
ddsi_plugin.rhc_plugin.rhc_unref_fn = dds_tkmap_instance_unref;
/* Register iid generator */
ddsi_plugin.iidgen_fn = dds_iid_gen;
}

View file

@ -16,8 +16,8 @@
#include "dds__write.h"
#include "dds__writer.h"
#include "dds__rhc.h"
#include "dds__tkmap.h"
#include "dds__err.h"
#include "ddsi/ddsi_tkmap.h"
#include "ddsi/ddsi_serdata.h"
#include "ddsi/q_entity.h"
#include "ddsi/q_thread.h"
@ -50,14 +50,14 @@ dds_dispose_ih(
return dds_dispose_ih_ts(writer, handle, dds_time());
}
static struct tkmap_instance*
static struct ddsi_tkmap_instance*
dds_instance_find(
_In_ const dds_topic *topic,
_In_ const void *data,
_In_ const bool create)
{
struct ddsi_serdata *sd = ddsi_serdata_from_sample (topic->m_stopic, SDK_KEY, data);
struct tkmap_instance * inst = dds_tkmap_find (sd, false, create);
struct ddsi_tkmap_instance * inst = ddsi_tkmap_find (sd, false, create);
ddsi_serdata_unref (sd);
return inst;
}
@ -68,10 +68,10 @@ dds_instance_remove(
_In_opt_ const void *data,
_In_ dds_instance_handle_t handle)
{
struct tkmap_instance * inst;
struct ddsi_tkmap_instance * inst;
if (handle != DDS_HANDLE_NIL) {
inst = dds_tkmap_find_by_id (gv.m_tkmap, handle);
inst = ddsi_tkmap_find_by_id (gv.m_tkmap, handle);
} else {
assert (data);
inst = dds_instance_find (topic, data, false);
@ -83,7 +83,7 @@ dds_instance_remove(
if (asleep) {
thread_state_awake(thr);
}
dds_tkmap_instance_unref (inst);
ddsi_tkmap_instance_unref (inst);
if (asleep) {
thread_state_asleep(thr);
}
@ -133,7 +133,7 @@ dds_register_instance(
_Out_ dds_instance_handle_t *handle,
_In_ const void *data)
{
struct tkmap_instance * inst;
struct ddsi_tkmap_instance * inst;
dds_entity *wr;
dds_return_t ret;
dds__retcode_t rc;
@ -241,7 +241,7 @@ dds_unregister_instance_ih_ts(
bool autodispose = true;
dds_write_action action = DDS_WR_ACTION_UNREGISTER;
dds_entity *wr;
struct tkmap *map;
struct ddsi_tkmap *map;
const dds_topic *topic;
void *sample;
@ -263,7 +263,7 @@ dds_unregister_instance_ih_ts(
map = gv.m_tkmap;
topic = dds_instance_info((dds_entity*)wr);
sample = dds_alloc (topic->m_descriptor->m_size);
if (dds_tkmap_get_key (map, topic->m_stopic, handle, sample)) {
if (ddsi_tkmap_get_key (map, topic->m_stopic, handle, sample)) {
ret = dds_write_impl ((dds_writer*)wr, sample, timestamp, action);
} else{
DDS_ERROR("No instance related with the provided handle is found\n");
@ -354,10 +354,10 @@ dds_dispose_ih_ts(
rc = dds_writer_lock(writer, &wr);
if (rc == DDS_RETCODE_OK) {
struct tkmap *map = gv.m_tkmap;
struct ddsi_tkmap *map = gv.m_tkmap;
const dds_topic *topic = dds_instance_info((dds_entity*)wr);
void *sample = dds_alloc (topic->m_descriptor->m_size);
if (dds_tkmap_get_key (map, topic->m_stopic, handle, sample)) {
if (ddsi_tkmap_get_key (map, topic->m_stopic, handle, sample)) {
ret = dds_dispose_impl(wr, sample, handle, timestamp);
} else {
DDS_ERROR("No instance related with the provided handle is found\n");
@ -381,7 +381,7 @@ dds_instance_lookup(
{
dds_instance_handle_t ih = DDS_HANDLE_NIL;
const dds_topic * topic;
struct tkmap * map = gv.m_tkmap;
struct ddsi_tkmap * map = gv.m_tkmap;
struct ddsi_serdata *sd;
if(data == NULL){
@ -392,7 +392,7 @@ dds_instance_lookup(
topic = dds_instance_info_by_hdl (entity);
if (topic) {
sd = ddsi_serdata_from_sample (topic->m_stopic, SDK_KEY, data);
ih = dds_tkmap_lookup (map, sd);
ih = ddsi_tkmap_lookup (map, sd);
ddsi_serdata_unref (sd);
} else {
DDS_ERROR("Acquired topic is NULL\n");
@ -410,7 +410,7 @@ dds_instance_get_key(
{
dds_return_t ret;
const dds_topic * topic;
struct tkmap * map = gv.m_tkmap;
struct ddsi_tkmap * map = gv.m_tkmap;
if(data == NULL){
DDS_ERROR("Argument data is NULL\n");
@ -426,7 +426,7 @@ dds_instance_get_key(
}
memset (data, 0, topic->m_descriptor->m_size);
if (dds_tkmap_get_key (map, topic->m_stopic, inst, data)) {
if (ddsi_tkmap_get_key (map, topic->m_stopic, inst, data)) {
ret = DDS_RETCODE_OK;
} else{
DDS_ERROR("No instance related with the provided entity is found\n");

View file

@ -13,7 +13,7 @@
#include <string.h>
#include "dds__entity.h"
#include "dds__reader.h"
#include "dds__tkmap.h"
#include "ddsi/ddsi_tkmap.h"
#include "dds__rhc.h"
#include "dds__err.h"
#include "ddsi/q_thread.h"
@ -137,7 +137,7 @@ dds_read_impl(
goto fail;
}
if (hand != DDS_HANDLE_NIL) {
if (dds_tkmap_find_by_id(gv.m_tkmap, hand) == NULL) {
if (ddsi_tkmap_find_by_id(gv.m_tkmap, hand) == NULL) {
DDS_ERROR("Could not find instance\n");
ret = DDS_ERRNO(DDS_RETCODE_PRECONDITION_NOT_MET);
dds_read_unlock(rd, cond);

View file

@ -24,7 +24,7 @@
#include "dds__entity.h"
#include "dds__reader.h"
#include "dds__rhc.h"
#include "dds__tkmap.h"
#include "ddsi/ddsi_tkmap.h"
#include "util/ut_hopscotch.h"
#include "util/ut_avl.h"
@ -253,7 +253,7 @@ struct rhc_instance
nn_wctime_t tstamp; /* source time stamp of last update */
struct rhc_instance *next; /* next non-empty instance in arbitrary ordering */
struct rhc_instance *prev;
struct tkmap_instance *tk; /* backref into TK for unref'ing */
struct ddsi_tkmap_instance *tk; /* backref into TK for unref'ing */
struct rhc_sample a_sample; /* pre-allocated storage for 1 sample */
};
@ -504,7 +504,7 @@ static void free_instance (void *vnode, void *varg)
{
remove_inst_from_nonempty_list (rhc, inst);
}
dds_tkmap_instance_unref (inst->tk);
ddsi_tkmap_instance_unref (inst->tk);
dds_free (inst);
}
@ -1023,12 +1023,12 @@ static struct rhc_instance * alloc_new_instance
(
const struct proxy_writer_info *pwr_info,
struct ddsi_serdata *serdata,
struct tkmap_instance *tk
struct ddsi_tkmap_instance *tk
)
{
struct rhc_instance *inst;
dds_tkmap_instance_ref (tk);
ddsi_tkmap_instance_ref (tk);
inst = dds_alloc (sizeof (*inst));
inst->iid = tk->m_iid;
inst->tk = tk;
@ -1052,7 +1052,7 @@ static rhc_store_result_t rhc_store_new_instance
struct rhc *rhc,
const struct proxy_writer_info *pwr_info,
struct ddsi_serdata *sample,
struct tkmap_instance *tk,
struct ddsi_tkmap_instance *tk,
const bool has_data,
status_cb_data_t * cb_data
)
@ -1124,7 +1124,7 @@ static rhc_store_result_t rhc_store_new_instance
bool dds_rhc_store
(
struct rhc * __restrict rhc, const struct proxy_writer_info * __restrict pwr_info,
struct ddsi_serdata * __restrict sample, struct tkmap_instance * __restrict tk
struct ddsi_serdata * __restrict sample, struct ddsi_tkmap_instance * __restrict tk
)
{
const uint64_t wr_iid = pwr_info->iid;

View file

@ -1,286 +0,0 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#include <assert.h>
#include <string.h>
#include "ddsi/q_thread.h"
#include "ddsi/q_unused.h"
#include "ddsi/q_gc.h"
#include "ddsi/q_globals.h"
#include "ddsi/q_config.h"
#include "ddsi/sysdeps.h"
#include "dds__tkmap.h"
#include "dds__iid.h"
#include "util/ut_hopscotch.h"
#include "dds__stream.h"
#include "os/os.h"
#include "ddsi/ddsi_serdata.h"
#define REFC_DELETE 0x80000000
#define REFC_MASK 0x0fffffff
struct tkmap
{
struct ut_chh * m_hh;
os_mutex m_lock;
os_cond m_cond;
};
static void gc_buckets_impl (struct gcreq *gcreq)
{
os_free (gcreq->arg);
gcreq_free (gcreq);
}
static void gc_buckets (void *a)
{
struct gcreq *gcreq = gcreq_new (gv.gcreq_queue, gc_buckets_impl);
gcreq->arg = a;
gcreq_enqueue (gcreq);
}
static void gc_tkmap_instance_impl (struct gcreq *gcreq)
{
struct tkmap_instance *tk = gcreq->arg;
ddsi_serdata_unref (tk->m_sample);
dds_free (tk);
gcreq_free (gcreq);
}
static void gc_tkmap_instance (struct tkmap_instance *tk)
{
struct gcreq *gcreq = gcreq_new (gv.gcreq_queue, gc_tkmap_instance_impl);
gcreq->arg = tk;
gcreq_enqueue (gcreq);
}
static uint32_t dds_tk_hash (const struct tkmap_instance * inst)
{
return inst->m_sample->hash;
}
static uint32_t dds_tk_hash_void (const void * inst)
{
return dds_tk_hash (inst);
}
static int dds_tk_equals (const struct tkmap_instance *a, const struct tkmap_instance *b)
{
return (a->m_sample->ops == b->m_sample->ops) ? ddsi_serdata_eqkey (a->m_sample, b->m_sample) : 0;
}
static int dds_tk_equals_void (const void *a, const void *b)
{
return dds_tk_equals (a, b);
}
struct tkmap * dds_tkmap_new (void)
{
struct tkmap *tkmap = dds_alloc (sizeof (*tkmap));
tkmap->m_hh = ut_chhNew (1, dds_tk_hash_void, dds_tk_equals_void, gc_buckets);
os_mutexInit (&tkmap->m_lock);
os_condInit (&tkmap->m_cond, &tkmap->m_lock);
return tkmap;
}
static void free_tkmap_instance (void *vtk, UNUSED_ARG(void *f_arg))
{
struct tkmap_instance *tk = vtk;
ddsi_serdata_unref (tk->m_sample);
os_free (tk);
}
void dds_tkmap_free (_Inout_ _Post_invalid_ struct tkmap * map)
{
ut_chhEnumUnsafe (map->m_hh, free_tkmap_instance, NULL);
ut_chhFree (map->m_hh);
os_condDestroy (&map->m_cond);
os_mutexDestroy (&map->m_lock);
dds_free (map);
}
uint64_t dds_tkmap_lookup (_In_ struct tkmap * map, _In_ const struct ddsi_serdata * sd)
{
struct tkmap_instance dummy;
struct tkmap_instance * tk;
dummy.m_sample = (struct ddsi_serdata *) sd;
tk = ut_chhLookup (map->m_hh, &dummy);
return (tk) ? tk->m_iid : DDS_HANDLE_NIL;
}
typedef struct
{
const struct ddsi_sertopic *topic;
uint64_t m_iid;
void * m_sample;
bool m_ret;
}
tkmap_get_key_arg;
static void dds_tkmap_get_key_fn (void * vtk, void * varg)
{
struct tkmap_instance * tk = vtk;
tkmap_get_key_arg * arg = (tkmap_get_key_arg*) varg;
if (tk->m_iid == arg->m_iid)
{
ddsi_serdata_topicless_to_sample (arg->topic, tk->m_sample, arg->m_sample, 0, 0);
arg->m_ret = true;
}
}
_Check_return_
bool dds_tkmap_get_key (_In_ struct tkmap * map, const struct ddsi_sertopic *topic, _In_ uint64_t iid, _Out_ void * sample)
{
tkmap_get_key_arg arg = { topic, iid, sample, false };
os_mutexLock (&map->m_lock);
ut_chhEnumUnsafe (map->m_hh, dds_tkmap_get_key_fn, &arg);
os_mutexUnlock (&map->m_lock);
return arg.m_ret;
}
typedef struct
{
uint64_t m_iid;
struct tkmap_instance * m_inst;
}
tkmap_get_inst_arg;
static void dds_tkmap_get_inst_fn (void * vtk, void * varg)
{
struct tkmap_instance * tk = vtk;
tkmap_get_inst_arg * arg = (tkmap_get_inst_arg*) varg;
if (tk->m_iid == arg->m_iid)
{
arg->m_inst = tk;
}
}
_Check_return_
struct tkmap_instance * dds_tkmap_find_by_id (_In_ struct tkmap * map, _In_ uint64_t iid)
{
tkmap_get_inst_arg arg = { iid, NULL };
ut_chhEnumUnsafe (map->m_hh, dds_tkmap_get_inst_fn, &arg);
return arg.m_inst;
}
/* Debug keyhash generation for debug and coverage builds */
#ifdef NDEBUG
#if VL_BUILD_LCOV
#define DDS_DEBUG_KEYHASH 1
#else
#define DDS_DEBUG_KEYHASH 0
#endif
#else
#define DDS_DEBUG_KEYHASH 1
#endif
_Check_return_
struct tkmap_instance * dds_tkmap_find(
_In_ struct ddsi_serdata * sd,
_In_ const bool rd,
_In_ const bool create)
{
struct tkmap_instance dummy;
struct tkmap_instance * tk;
struct tkmap * map = gv.m_tkmap;
dummy.m_sample = sd;
retry:
if ((tk = ut_chhLookup(map->m_hh, &dummy)) != NULL)
{
uint32_t new;
new = os_atomic_inc32_nv(&tk->m_refc);
if (new & REFC_DELETE)
{
/* for the unlikely case of spinning 2^31 times across all threads ... */
os_atomic_dec32(&tk->m_refc);
/* simplest action would be to just spin, but that can potentially take a long time;
we can block until someone signals some entry is removed from the map if we take
some lock & wait for some condition */
os_mutexLock(&map->m_lock);
while ((tk = ut_chhLookup(map->m_hh, &dummy)) != NULL && (os_atomic_ld32(&tk->m_refc) & REFC_DELETE))
os_condWait(&map->m_cond, &map->m_lock);
os_mutexUnlock(&map->m_lock);
goto retry;
}
}
else if (create)
{
if ((tk = dds_alloc (sizeof (*tk))) == NULL)
return NULL;
tk->m_sample = ddsi_serdata_to_topicless (sd);
tk->m_map = map;
os_atomic_st32 (&tk->m_refc, 1);
tk->m_iid = dds_iid_gen ();
if (!ut_chhAdd (map->m_hh, tk))
{
/* Lost a race from another thread, retry */
ddsi_serdata_unref (tk->m_sample);
dds_free (tk);
goto retry;
}
}
if (tk && rd)
{
DDS_TRACE("tk=%p iid=%"PRIx64" ", &tk, tk->m_iid);
}
return tk;
}
_Check_return_
struct tkmap_instance * dds_tkmap_lookup_instance_ref (_In_ struct ddsi_serdata * sd)
{
assert (vtime_awake_p (lookup_thread_state ()->vtime));
return dds_tkmap_find (sd, true, true);
}
void dds_tkmap_instance_ref (_In_ struct tkmap_instance *tk)
{
os_atomic_inc32 (&tk->m_refc);
}
void dds_tkmap_instance_unref (_In_ struct tkmap_instance * tk)
{
uint32_t old, new;
assert (vtime_awake_p(lookup_thread_state()->vtime));
do {
old = os_atomic_ld32(&tk->m_refc);
if (old == 1)
new = REFC_DELETE;
else
{
assert(!(old & REFC_DELETE));
new = old - 1;
}
} while (!os_atomic_cas32(&tk->m_refc, old, new));
if (new == REFC_DELETE)
{
struct tkmap *map = tk->m_map;
/* Remove from hash table */
int removed = ut_chhRemove(map->m_hh, tk);
assert (removed);
(void)removed;
/* Signal any threads blocked in their retry loops in lookup */
os_mutexLock(&map->m_lock);
os_condBroadcast(&map->m_cond);
os_mutexUnlock(&map->m_lock);
/* Schedule freeing of memory until after all those who may have found a pointer have
progressed to where they no longer hold that pointer */
gc_tkmap_instance(tk);
}
}

View file

@ -24,7 +24,7 @@
#include "ddsi/ddsi_sertopic.h"
#include "ddsi/q_ddsi_discovery.h"
#include "os/os_atomics.h"
#include "dds__iid.h"
#include "ddsi/ddsi_iid.h"
#define DDS_TOPIC_STATUS_MASK \
DDS_INCONSISTENT_TOPIC_STATUS
@ -423,7 +423,7 @@ dds_create_topic(
st = dds_alloc (sizeof (*st));
os_atomic_st32 (&st->c.refc, 1);
st->c.iid = dds_iid_gen ();
st->c.iid = ddsi_iid_gen ();
st->c.status_cb = dds_topic_status_cb;
st->c.status_cb_entity = top;
st->c.name_typename = key;

View file

@ -18,7 +18,7 @@
#include "ddsi/q_unused.h"
#include "ddsi/q_config.h"
#include "dds__whc.h"
#include "dds__tkmap.h"
#include "ddsi/ddsi_tkmap.h"
#include "util/ut_avl.h"
#include "util/ut_hopscotch.h"
@ -55,7 +55,7 @@ struct whc_intvnode {
struct whc_idxnode {
uint64_t iid;
seqno_t prune_seq;
struct tkmap_instance *tk;
struct ddsi_tkmap_instance *tk;
unsigned headidx;
#if __STDC_VERSION__ >= 199901L
struct whc_node *hist[];
@ -128,7 +128,7 @@ static unsigned whc_default_remove_acked_messages_full (struct whc_impl *whc, se
static unsigned whc_default_remove_acked_messages (struct whc *whc, seqno_t max_drop_seq, struct whc_state *whcst, struct whc_node **deferred_free_list);
static void whc_default_free_deferred_free_list (struct whc *whc, struct whc_node *deferred_free_list);
static void whc_default_get_state(const struct whc *whc, struct whc_state *st);
static int whc_default_insert (struct whc *whc, seqno_t max_drop_seq, seqno_t seq, struct nn_plist *plist, struct ddsi_serdata *serdata, struct tkmap_instance *tk);
static int whc_default_insert (struct whc *whc, seqno_t max_drop_seq, seqno_t seq, struct nn_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk);
static seqno_t whc_default_next_seq (const struct whc *whc, seqno_t seq);
static bool whc_default_borrow_sample (const struct whc *whc, seqno_t seq, struct whc_borrowed_sample *sample);
static bool whc_default_borrow_sample_key (const struct whc *whc, const struct ddsi_serdata *serdata_key, struct whc_borrowed_sample *sample);
@ -324,7 +324,7 @@ static struct whc_node *whc_findkey (const struct whc_impl *whc, const struct dd
} template;
struct whc_idxnode *n;
check_whc (whc);
template.idxn.iid = dds_tkmap_lookup(gv.m_tkmap, serdata_key);
template.idxn.iid = ddsi_tkmap_lookup(gv.m_tkmap, serdata_key);
n = ut_hhLookup (whc->idx_hash, &template.idxn);
if (n == NULL)
return NULL;
@ -537,7 +537,7 @@ static void delete_one_sample_from_idx (struct whc_impl *whc, struct whc_node *w
#endif
if (!ut_hhRemove (whc->idx_hash, idxn))
assert (0);
dds_tkmap_instance_unref(idxn->tk);
ddsi_tkmap_instance_unref(idxn->tk);
os_free (idxn);
}
whcn->idxnode = NULL;
@ -1081,7 +1081,7 @@ static struct whc_node *whc_default_insert_seq (struct whc_impl *whc, seqno_t ma
return newn;
}
static int whc_default_insert (struct whc *whc_generic, seqno_t max_drop_seq, seqno_t seq, struct nn_plist *plist, struct ddsi_serdata *serdata, struct tkmap_instance *tk)
static int whc_default_insert (struct whc *whc_generic, seqno_t max_drop_seq, seqno_t seq, struct nn_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk)
{
struct whc_impl * const whc = (struct whc_impl *)whc_generic;
struct whc_node *newn = NULL;
@ -1190,7 +1190,7 @@ static int whc_default_insert (struct whc *whc_generic, seqno_t max_drop_seq, se
unsigned i;
idxn = os_malloc (sizeof (*idxn) + whc->idxdepth * sizeof (idxn->hist[0]));
DDS_LOG(DDS_LC_WHC, " idxn %p", (void *)idxn);
dds_tkmap_instance_ref(tk);
ddsi_tkmap_instance_ref(tk);
idxn->iid = tk->m_iid;
idxn->tk = tk;
idxn->prune_seq = 0;

View file

@ -13,7 +13,7 @@
#include <string.h>
#include "dds__writer.h"
#include "dds__write.h"
#include "dds__tkmap.h"
#include "ddsi/ddsi_tkmap.h"
#include "ddsi/q_error.h"
#include "ddsi/q_thread.h"
#include "ddsi/q_xmsg.h"
@ -115,7 +115,7 @@ static int
deliver_locally(
_In_ struct writer *wr,
_In_ struct ddsi_serdata *payload,
_In_ struct tkmap_instance *tk)
_In_ struct ddsi_tkmap_instance *tk)
{
dds_return_t ret = DDS_RETCODE_OK;
os_mutexLock (&wr->rdary.rdary_lock);
@ -193,7 +193,7 @@ dds_write_impl(
const bool writekey = action & DDS_WR_KEY_BIT;
dds_writer * writer = (dds_writer*) wr;
struct writer * ddsi_wr = writer->m_wr;
struct tkmap_instance * tk;
struct ddsi_tkmap_instance * tk;
struct ddsi_serdata *d;
if (data == NULL) {
@ -220,7 +220,7 @@ dds_write_impl(
((action & DDS_WR_UNREGISTER_BIT) ? NN_STATUSINFO_UNREGISTER : 0) ;
d->timestamp.v = tstamp;
ddsi_serdata_ref(d);
tk = (ddsi_plugin.rhc_plugin.rhc_lookup_fn) (d);
tk = ddsi_tkmap_lookup_instance_ref(d);
w_rc = write_sample_gc (writer->m_xp, ddsi_wr, d, tk);
if (w_rc >= 0) {
@ -243,7 +243,7 @@ dds_write_impl(
ret = deliver_locally (ddsi_wr, d, tk);
}
ddsi_serdata_unref(d);
(ddsi_plugin.rhc_plugin.rhc_unref_fn) (tk);
ddsi_tkmap_instance_unref(tk);
if (asleep) {
thread_state_asleep (thr);
@ -267,7 +267,7 @@ dds_writecdr_impl(
struct thread_state1 * const thr = lookup_thread_state ();
const bool asleep = !vtime_awake_p (thr->vtime);
struct writer * ddsi_wr = wr->m_wr;
struct tkmap_instance * tk;
struct ddsi_tkmap_instance * tk;
if (wr->m_topic->filter_fn) {
abort();
@ -283,7 +283,7 @@ dds_writecdr_impl(
((action & DDS_WR_UNREGISTER_BIT) ? NN_STATUSINFO_UNREGISTER : 0) ;
d->timestamp.v = tstamp;
ddsi_serdata_ref(d);
tk = (ddsi_plugin.rhc_plugin.rhc_lookup_fn) (d);
tk = ddsi_tkmap_lookup_instance_ref(d);
w_rc = write_sample_gc (wr->m_xp, ddsi_wr, d, tk);
if (w_rc >= 0) {
/* Flush out write unless configured to batch */
@ -306,7 +306,7 @@ dds_writecdr_impl(
ret = deliver_locally (ddsi_wr, d, tk);
}
ddsi_serdata_unref(d);
(ddsi_plugin.rhc_plugin.rhc_unref_fn) (tk);
ddsi_tkmap_instance_unref(tk);
if (asleep) {
thread_state_asleep (thr);

View file

@ -20,7 +20,7 @@
#include "dds__qos.h"
#include "dds__err.h"
#include "dds__init.h"
#include "dds__tkmap.h"
#include "ddsi/ddsi_tkmap.h"
#include "dds__whc.h"
#include "ddsc/ddsc_project.h"