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:
parent
19202d9de8
commit
29f542b916
30 changed files with 221 additions and 213 deletions
|
@ -23,6 +23,8 @@ PREPEND(srcs_ddsi "${CMAKE_CURRENT_LIST_DIR}/src"
|
|||
ddsi_sertopic.c
|
||||
ddsi_sertopic_default.c
|
||||
ddsi_rhc_plugin.c
|
||||
ddsi_iid.c
|
||||
ddsi_tkmap.c
|
||||
q_addrset.c
|
||||
q_bitset_inlines.c
|
||||
q_bswap.c
|
||||
|
@ -74,6 +76,8 @@ PREPEND(hdrs_private_ddsi "${CMAKE_CURRENT_LIST_DIR}/include/ddsi"
|
|||
ddsi_sertopic.h
|
||||
ddsi_serdata_default.h
|
||||
ddsi_rhc_plugin.h
|
||||
ddsi_iid.h
|
||||
ddsi_tkmap.h
|
||||
probes-constants.h
|
||||
q_addrset.h
|
||||
q_align.h
|
||||
|
|
38
src/core/ddsi/include/ddsi/ddsi_iid.h
Normal file
38
src/core/ddsi/include/ddsi/ddsi_iid.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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 "os/os.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct ddsi_iid {
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
os_atomic_uint64_t counter;
|
||||
#else
|
||||
os_mutex lock;
|
||||
uint64_t counter;
|
||||
#endif
|
||||
uint32_t key[4];
|
||||
};
|
||||
|
||||
void ddsi_iid_init (void);
|
||||
void ddsi_iid_fini (void);
|
||||
uint64_t ddsi_iid_gen (void);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
struct rhc;
|
||||
struct nn_xqos;
|
||||
struct tkmap_instance;
|
||||
struct ddsi_tkmap_instance;
|
||||
struct ddsi_serdata;
|
||||
struct ddsi_sertopic;
|
||||
struct entity_common;
|
||||
|
@ -33,14 +33,12 @@ struct ddsi_rhc_plugin
|
|||
void (*rhc_fini_fn) (struct rhc *rhc);
|
||||
bool (*rhc_store_fn)
|
||||
(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 (*rhc_unregister_wr_fn)
|
||||
(struct rhc * __restrict rhc, const struct proxy_writer_info * __restrict pwr_info);
|
||||
void (*rhc_relinquish_ownership_fn)
|
||||
(struct rhc * __restrict rhc, const uint64_t wr_iid);
|
||||
void (*rhc_set_qos_fn) (struct rhc * rhc, const struct nn_xqos * qos);
|
||||
struct tkmap_instance * (*rhc_lookup_fn) (struct ddsi_serdata *serdata);
|
||||
void (*rhc_unref_fn) (struct tkmap_instance *tk);
|
||||
};
|
||||
|
||||
void make_proxy_writer_info(struct proxy_writer_info *pwr_info, const struct entity_common *e, const struct nn_xqos *xqos);
|
||||
|
|
52
src/core/ddsi/include/ddsi/ddsi_tkmap.h
Normal file
52
src/core/ddsi/include/ddsi/ddsi_tkmap.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 ddsi_tkmap;
|
||||
struct ddsi_serdata;
|
||||
struct dds_topic;
|
||||
|
||||
struct ddsi_tkmap_instance
|
||||
{
|
||||
struct ddsi_serdata * m_sample;
|
||||
struct ddsi_tkmap * m_map;
|
||||
uint64_t m_iid;
|
||||
os_atomic_uint32_t m_refc;
|
||||
};
|
||||
|
||||
|
||||
struct ddsi_tkmap * ddsi_tkmap_new (void);
|
||||
void ddsi_tkmap_free (_Inout_ _Post_invalid_ struct ddsi_tkmap *tkmap);
|
||||
void ddsi_tkmap_instance_ref (_In_ struct ddsi_tkmap_instance *tk);
|
||||
uint64_t ddsi_tkmap_lookup (_In_ struct ddsi_tkmap *tkmap, _In_ const struct ddsi_serdata *serdata);
|
||||
_Check_return_ bool ddsi_tkmap_get_key (_In_ struct ddsi_tkmap * map, const struct ddsi_sertopic *topic, _In_ uint64_t iid, _Out_ void * sample);
|
||||
_Check_return_ struct ddsi_tkmap_instance * ddsi_tkmap_find(
|
||||
_In_ struct ddsi_serdata * sd,
|
||||
_In_ const bool rd,
|
||||
_In_ const bool create);
|
||||
_Check_return_ struct ddsi_tkmap_instance * ddsi_tkmap_find_by_id (_In_ struct ddsi_tkmap * map, _In_ uint64_t iid);
|
||||
|
||||
DDS_EXPORT _Check_return_ struct ddsi_tkmap_instance * ddsi_tkmap_lookup_instance_ref (_In_ struct ddsi_serdata * sd);
|
||||
DDS_EXPORT void ddsi_tkmap_instance_unref (_In_ struct ddsi_tkmap_instance * tk);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -414,10 +414,6 @@ struct ddsi_plugin
|
|||
|
||||
/* Read cache */
|
||||
struct ddsi_rhc_plugin rhc_plugin;
|
||||
|
||||
/* IID generator */
|
||||
|
||||
uint64_t (*iidgen_fn) (void);
|
||||
};
|
||||
|
||||
extern struct config OSAPI_EXPORT config;
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
|
||||
#include "util/ut_fibheap.h"
|
||||
|
||||
|
||||
#include "ddsi/q_plist.h"
|
||||
#include "ddsi/q_protocol.h"
|
||||
#include "ddsi/q_nwif.h"
|
||||
#include "ddsi/q_sockwaitset.h"
|
||||
#include "ddsi/ddsi_iid.h"
|
||||
|
||||
#ifdef DDSI_INCLUDE_ENCRYPTION
|
||||
#include "ddsi/q_security.h" /* for q_securityDecoderSet */
|
||||
|
@ -47,7 +47,7 @@ struct ddsi_tran_listener;
|
|||
struct ddsi_tran_factory;
|
||||
struct ut_thread_pool_s;
|
||||
struct debug_monitor;
|
||||
struct tkmap;
|
||||
struct ddsi_tkmap;
|
||||
|
||||
typedef struct ospl_in_addr_node {
|
||||
nn_locator_t loc;
|
||||
|
@ -90,7 +90,8 @@ struct q_globals {
|
|||
volatile int deaf;
|
||||
volatile int mute;
|
||||
|
||||
struct tkmap * m_tkmap;
|
||||
struct ddsi_tkmap * m_tkmap;
|
||||
struct ddsi_iid dds_iid;
|
||||
|
||||
/* Hash tables for participants, readers, writers, proxy
|
||||
participants, proxy readers and proxy writers by GUID
|
||||
|
|
|
@ -25,7 +25,7 @@ struct writer;
|
|||
struct whc_state;
|
||||
struct proxy_reader;
|
||||
struct ddsi_serdata;
|
||||
struct tkmap_instance;
|
||||
struct ddsi_tkmap_instance;
|
||||
|
||||
/* Writing new data; serdata_twrite (serdata) is assumed to be really
|
||||
recentish; serdata is unref'd. If xp == NULL, data is queued, else
|
||||
|
@ -34,8 +34,8 @@ struct tkmap_instance;
|
|||
"nogc": no GC may occur, so it may not block to throttle the writer if the high water mark of the WHC is reached, which implies true KEEP_LAST behaviour. This is true for all the DDSI built-in writers.
|
||||
"gc": GC may occur, which means the writer history and watermarks can be anything. This must be used for all application data.
|
||||
*/
|
||||
int write_sample_gc (struct nn_xpack *xp, struct writer *wr, struct ddsi_serdata *serdata, struct tkmap_instance *tk);
|
||||
int write_sample_nogc (struct nn_xpack *xp, struct writer *wr, struct ddsi_serdata *serdata, struct tkmap_instance *tk);
|
||||
int write_sample_gc (struct nn_xpack *xp, struct writer *wr, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk);
|
||||
int write_sample_nogc (struct nn_xpack *xp, struct writer *wr, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk);
|
||||
int write_sample_gc_notk (struct nn_xpack *xp, struct writer *wr, struct ddsi_serdata *serdata);
|
||||
int write_sample_nogc_notk (struct nn_xpack *xp, struct writer *wr, struct ddsi_serdata *serdata);
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ extern "C" {
|
|||
|
||||
struct ddsi_serdata;
|
||||
struct nn_plist;
|
||||
struct tkmap_instance;
|
||||
struct ddsi_tkmap_instance;
|
||||
struct whc_node; /* opaque, but currently used for deferred free lists */
|
||||
struct whc;
|
||||
|
||||
|
@ -70,7 +70,7 @@ typedef void (*whc_free_t)(struct whc *whc);
|
|||
reliable readers that have not acknowledged all data */
|
||||
/* max_drop_seq must go soon, it's way too ugly. */
|
||||
/* plist may be NULL or os_malloc'd, WHC takes ownership of plist */
|
||||
typedef int (*whc_insert_t)(struct whc *whc, seqno_t max_drop_seq, seqno_t seq, struct nn_plist *plist, struct ddsi_serdata *serdata, struct tkmap_instance *tk);
|
||||
typedef int (*whc_insert_t)(struct whc *whc, seqno_t max_drop_seq, seqno_t seq, struct nn_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk);
|
||||
typedef unsigned (*whc_downgrade_to_volatile_t)(struct whc *whc, struct whc_state *st);
|
||||
typedef unsigned (*whc_remove_acked_messages_t)(struct whc *whc, seqno_t max_drop_seq, struct whc_state *whcst, struct whc_node **deferred_free_list);
|
||||
typedef void (*whc_free_deferred_free_list_t)(struct whc *whc, struct whc_node *deferred_free_list);
|
||||
|
@ -118,7 +118,7 @@ inline bool whc_sample_iter_borrow_next (struct whc_sample_iter *it, struct whc_
|
|||
inline void whc_free (struct whc *whc) {
|
||||
whc->ops->free (whc);
|
||||
}
|
||||
inline int whc_insert (struct whc *whc, seqno_t max_drop_seq, seqno_t seq, struct nn_plist *plist, struct ddsi_serdata *serdata, struct tkmap_instance *tk) {
|
||||
inline int whc_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) {
|
||||
return whc->ops->insert (whc, max_drop_seq, seq, plist, serdata, tk);
|
||||
}
|
||||
inline unsigned whc_downgrade_to_volatile (struct whc *whc, struct whc_state *st) {
|
||||
|
|
89
src/core/ddsi/src/ddsi_iid.c
Normal file
89
src/core/ddsi/src/ddsi_iid.c
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* 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 "ddsi/ddsi_iid.h"
|
||||
#include "ddsi/q_time.h"
|
||||
#include "ddsi/q_globals.h"
|
||||
|
||||
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 ddsi_iid_gen (void)
|
||||
{
|
||||
uint64_t iid;
|
||||
union { uint64_t u64; uint32_t u32[2]; } tmp;
|
||||
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
tmp.u64 = os_atomic_inc64_nv (&gv.dds_iid.counter);
|
||||
#else
|
||||
os_mutexLock (&gv.dds_iid.lock);
|
||||
tmp.u64 = ++gv.dds_iid.counter;
|
||||
os_mutexUnlock (&gv.dds_iid.lock);
|
||||
#endif
|
||||
|
||||
dds_tea_encrypt (tmp.u32, gv.dds_iid.key);
|
||||
iid = tmp.u64;
|
||||
return iid;
|
||||
}
|
||||
|
||||
void ddsi_iid_init (void)
|
||||
{
|
||||
union { uint64_t u64; uint32_t u32[2]; } tmp;
|
||||
nn_wctime_t tnow = now ();
|
||||
|
||||
#if ! OS_ATOMIC64_SUPPORT
|
||||
os_mutexInit (&gv.dds_iid.lock);
|
||||
#endif
|
||||
|
||||
gv.dds_iid.key[0] = (uint32_t) os_procIdSelf();
|
||||
gv.dds_iid.key[1] = (uint32_t) tnow.v;
|
||||
gv.dds_iid.key[2] = (uint32_t) (tnow.v >> 32);
|
||||
gv.dds_iid.key[3] = 0xdeadbeef;
|
||||
|
||||
tmp.u64 = 0;
|
||||
dds_tea_decrypt (tmp.u32, gv.dds_iid.key);
|
||||
#if OS_ATOMIC64_SUPPORT
|
||||
os_atomic_st64 (&gv.dds_iid.counter, tmp.u64);
|
||||
#else
|
||||
gv.dds_iid.counter = tmp.u64;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ddsi_iid_fini (void)
|
||||
{
|
||||
#if ! OS_ATOMIC64_SUPPORT
|
||||
os_mutexDestroy (&gv.dds_iid.lock);
|
||||
#endif
|
||||
}
|
|
@ -24,7 +24,7 @@
|
|||
#include <string.h>
|
||||
#include "os/os.h"
|
||||
#include "dds__key.h"
|
||||
#include "dds__tkmap.h"
|
||||
#include "ddsi/ddsi_tkmap.h"
|
||||
#include "dds__stream.h"
|
||||
#include "ddsi/q_radmin.h"
|
||||
#include "ddsi/ddsi_serdata_default.h"
|
||||
|
|
286
src/core/ddsi/src/ddsi_tkmap.c
Normal file
286
src/core/ddsi/src/ddsi_tkmap.c
Normal file
|
@ -0,0 +1,286 @@
|
|||
/*
|
||||
* 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 "ddsi/ddsi_iid.h"
|
||||
#include "ddsi/ddsi_tkmap.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 ddsi_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 ddsi_tkmap_instance *tk = gcreq->arg;
|
||||
ddsi_serdata_unref (tk->m_sample);
|
||||
dds_free (tk);
|
||||
gcreq_free (gcreq);
|
||||
}
|
||||
|
||||
static void gc_tkmap_instance (struct ddsi_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 ddsi_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 ddsi_tkmap_instance *a, const struct ddsi_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 ddsi_tkmap * ddsi_tkmap_new (void)
|
||||
{
|
||||
struct ddsi_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 ddsi_tkmap_instance *tk = vtk;
|
||||
ddsi_serdata_unref (tk->m_sample);
|
||||
os_free (tk);
|
||||
}
|
||||
|
||||
void ddsi_tkmap_free (_Inout_ _Post_invalid_ struct ddsi_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 ddsi_tkmap_lookup (_In_ struct ddsi_tkmap * map, _In_ const struct ddsi_serdata * sd)
|
||||
{
|
||||
struct ddsi_tkmap_instance dummy;
|
||||
struct ddsi_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 ddsi_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 ddsi_tkmap_get_key (_In_ struct ddsi_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 ddsi_tkmap_instance * m_inst;
|
||||
}
|
||||
tkmap_get_inst_arg;
|
||||
|
||||
static void dds_tkmap_get_inst_fn (void * vtk, void * varg)
|
||||
{
|
||||
struct ddsi_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 ddsi_tkmap_instance * ddsi_tkmap_find_by_id (_In_ struct ddsi_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 ddsi_tkmap_instance * ddsi_tkmap_find(
|
||||
_In_ struct ddsi_serdata * sd,
|
||||
_In_ const bool rd,
|
||||
_In_ const bool create)
|
||||
{
|
||||
struct ddsi_tkmap_instance dummy;
|
||||
struct ddsi_tkmap_instance * tk;
|
||||
struct ddsi_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 = ddsi_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 ddsi_tkmap_instance * ddsi_tkmap_lookup_instance_ref (_In_ struct ddsi_serdata * sd)
|
||||
{
|
||||
assert (vtime_awake_p (lookup_thread_state ()->vtime));
|
||||
return ddsi_tkmap_find (sd, true, true);
|
||||
}
|
||||
|
||||
void ddsi_tkmap_instance_ref (_In_ struct ddsi_tkmap_instance *tk)
|
||||
{
|
||||
os_atomic_inc32 (&tk->m_refc);
|
||||
}
|
||||
|
||||
void ddsi_tkmap_instance_unref (_In_ struct ddsi_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 ddsi_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);
|
||||
}
|
||||
}
|
|
@ -42,6 +42,8 @@
|
|||
|
||||
#include "ddsi/sysdeps.h"
|
||||
#include "dds__whc.h"
|
||||
#include "ddsi/ddsi_iid.h"
|
||||
#include "ddsi/ddsi_tkmap.h"
|
||||
|
||||
struct deleted_participant {
|
||||
ut_avlNode_t avlnode;
|
||||
|
@ -158,7 +160,7 @@ static void entity_common_init (struct entity_common *e, const struct nn_guid *g
|
|||
e->guid = *guid;
|
||||
e->kind = kind;
|
||||
e->name = os_strdup (name ? name : "");
|
||||
e->iid = (ddsi_plugin.iidgen_fn) ();
|
||||
e->iid = ddsi_iid_gen ();
|
||||
os_mutexInit (&e->lock);
|
||||
e->onlylocal = onlylocal;
|
||||
}
|
||||
|
@ -1613,7 +1615,7 @@ static void writer_add_local_connection (struct writer *wr, struct reader *rd)
|
|||
struct proxy_writer_info pwr_info;
|
||||
struct ddsi_serdata *payload = sample.serdata;
|
||||
/* FIXME: whc has tk reference in its index nodes, which is what we really should be iterating over anyway, and so we don't really have to look them up anymore */
|
||||
struct tkmap_instance *tk = (ddsi_plugin.rhc_plugin.rhc_lookup_fn) (payload);
|
||||
struct ddsi_tkmap_instance *tk = ddsi_tkmap_lookup_instance_ref(payload);
|
||||
make_proxy_writer_info(&pwr_info, &wr->e, wr->xqos);
|
||||
(void)(ddsi_plugin.rhc_plugin.rhc_store_fn) (rd->rhc, &pwr_info, payload, tk);
|
||||
}
|
||||
|
|
|
@ -57,8 +57,9 @@
|
|||
#include "ddsi/ddsi_mcgroup.h"
|
||||
#include "ddsi/ddsi_serdata_default.h"
|
||||
|
||||
#include "dds__tkmap.h"
|
||||
#include "ddsi/ddsi_tkmap.h"
|
||||
#include "dds__whc.h"
|
||||
#include "ddsi/ddsi_iid.h"
|
||||
|
||||
static void add_peer_addresses (struct addrset *as, const struct config_peer_listelem *list)
|
||||
{
|
||||
|
@ -772,7 +773,7 @@ static struct ddsi_sertopic *make_special_topic (uint16_t enc_id, const struct d
|
|||
st->c.ops = &ddsi_sertopic_ops_default;
|
||||
st->c.serdata_ops = ops;
|
||||
st->c.serdata_basehash = ddsi_sertopic_compute_serdata_basehash (st->c.serdata_ops);
|
||||
st->c.iid = ddsi_plugin.iidgen_fn();
|
||||
st->c.iid = ddsi_iid_gen ();
|
||||
st->native_encoding_identifier = enc_id;
|
||||
st->nkeys = 1;
|
||||
return (struct ddsi_sertopic *)st;
|
||||
|
@ -880,6 +881,7 @@ int rtps_init (void)
|
|||
/* Initialize implementation (Lite or OSPL) */
|
||||
|
||||
ddsi_plugin_init ();
|
||||
ddsi_iid_init ();
|
||||
|
||||
gv.tstart = now (); /* wall clock time, used in logs */
|
||||
|
||||
|
@ -1060,7 +1062,7 @@ int rtps_init (void)
|
|||
gv.spdp_defrag = nn_defrag_new (NN_DEFRAG_DROP_OLDEST, config.defrag_unreliable_maxsamples);
|
||||
gv.spdp_reorder = nn_reorder_new (NN_REORDER_MODE_ALWAYS_DELIVER, config.primary_reorder_maxsamples);
|
||||
|
||||
gv.m_tkmap = dds_tkmap_new ();
|
||||
gv.m_tkmap = ddsi_tkmap_new ();
|
||||
|
||||
if (gv.m_factory->m_connless)
|
||||
{
|
||||
|
@ -1339,7 +1341,7 @@ err_mc_conn:
|
|||
ddsi_conn_free (gv.data_conn_uc);
|
||||
free_group_membership(gv.mship);
|
||||
err_unicast_sockets:
|
||||
dds_tkmap_free (gv.m_tkmap);
|
||||
ddsi_tkmap_free (gv.m_tkmap);
|
||||
nn_reorder_free (gv.spdp_reorder);
|
||||
nn_defrag_free (gv.spdp_defrag);
|
||||
os_mutexDestroy (&gv.spdp_lock);
|
||||
|
@ -1368,6 +1370,7 @@ err_unicast_sockets:
|
|||
nn_plist_fini (&gv.default_plist_pp);
|
||||
ddsi_serdatapool_free (gv.serpool);
|
||||
nn_xmsgpool_free (gv.xmsgpool);
|
||||
ddsi_iid_fini ();
|
||||
(ddsi_plugin.fini_fn) ();
|
||||
#ifdef DDSI_INCLUDE_NETWORK_PARTITIONS
|
||||
err_network_partition_addrset:
|
||||
|
@ -1621,7 +1624,7 @@ void rtps_term (void)
|
|||
}
|
||||
}
|
||||
|
||||
dds_tkmap_free (gv.m_tkmap);
|
||||
ddsi_tkmap_free (gv.m_tkmap);
|
||||
|
||||
ephash_free (gv.guid_hash);
|
||||
gv.guid_hash = NULL;
|
||||
|
@ -1663,6 +1666,7 @@ OS_WARNING_MSVC_ON(6001);
|
|||
|
||||
ddsi_serdatapool_free (gv.serpool);
|
||||
nn_xmsgpool_free (gv.xmsgpool);
|
||||
ddsi_iid_fini ();
|
||||
(ddsi_plugin.fini_fn) ();
|
||||
DDS_LOG(DDS_LC_CONFIG, "Finis.\n");
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include "ddsi/q_globals.h"
|
||||
#include "ddsi/q_static_assert.h"
|
||||
#include "ddsi/q_init.h"
|
||||
#include "ddsi/ddsi_tkmap.h"
|
||||
#include "ddsi/ddsi_mcgroup.h"
|
||||
#include "ddsi/ddsi_serdata.h"
|
||||
#include "ddsi/ddsi_serdata_default.h" /* FIXME: get rid of this */
|
||||
|
@ -1995,8 +1996,8 @@ static int deliver_user_data (const struct nn_rsample_info *sampleinfo, const st
|
|||
the PRISMTECH_WRITER_INFO thing is completely meaningless to
|
||||
us */
|
||||
{
|
||||
struct tkmap_instance * tk;
|
||||
tk = (ddsi_plugin.rhc_plugin.rhc_lookup_fn) (payload);
|
||||
struct ddsi_tkmap_instance * tk;
|
||||
tk = ddsi_tkmap_lookup_instance_ref(payload);
|
||||
if (tk)
|
||||
{
|
||||
struct proxy_writer_info pwr_info;
|
||||
|
@ -2075,7 +2076,7 @@ retry:
|
|||
if (pwr_locked) os_mutexLock (&pwr->e.lock);
|
||||
}
|
||||
}
|
||||
(ddsi_plugin.rhc_plugin.rhc_unref_fn) (tk);
|
||||
ddsi_tkmap_instance_unref (tk);
|
||||
}
|
||||
}
|
||||
ddsi_serdata_unref (payload);
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include "ddsi/q_unused.h"
|
||||
#include "ddsi/q_hbcontrol.h"
|
||||
#include "ddsi/q_static_assert.h"
|
||||
|
||||
#include "ddsi/ddsi_tkmap.h"
|
||||
#include "ddsi/ddsi_serdata.h"
|
||||
#include "ddsi/ddsi_sertopic.h"
|
||||
|
||||
|
@ -851,7 +851,7 @@ int enqueue_sample_wrlock_held (struct writer *wr, seqno_t seq, const struct nn_
|
|||
return enqueued ? 0 : -1;
|
||||
}
|
||||
|
||||
static int insert_sample_in_whc (struct writer *wr, seqno_t seq, struct nn_plist *plist, struct ddsi_serdata *serdata, struct tkmap_instance *tk)
|
||||
static int insert_sample_in_whc (struct writer *wr, seqno_t seq, struct nn_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk)
|
||||
{
|
||||
/* returns: < 0 on error, 0 if no need to insert in whc, > 0 if inserted */
|
||||
int do_insert, insres, res;
|
||||
|
@ -1027,7 +1027,7 @@ static int maybe_grow_whc (struct writer *wr)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int write_sample_eot (struct nn_xpack *xp, struct writer *wr, struct nn_plist *plist, struct ddsi_serdata *serdata, struct tkmap_instance *tk, int end_of_txn, int gc_allowed)
|
||||
static int write_sample_eot (struct nn_xpack *xp, struct writer *wr, struct nn_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk, int end_of_txn, int gc_allowed)
|
||||
{
|
||||
int r;
|
||||
seqno_t seq;
|
||||
|
@ -1163,33 +1163,33 @@ drop:
|
|||
return r;
|
||||
}
|
||||
|
||||
int write_sample_gc (struct nn_xpack *xp, struct writer *wr, struct ddsi_serdata *serdata, struct tkmap_instance *tk)
|
||||
int write_sample_gc (struct nn_xpack *xp, struct writer *wr, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk)
|
||||
{
|
||||
return write_sample_eot (xp, wr, NULL, serdata, tk, 0, 1);
|
||||
}
|
||||
|
||||
int write_sample_nogc (struct nn_xpack *xp, struct writer *wr, struct ddsi_serdata *serdata, struct tkmap_instance *tk)
|
||||
int write_sample_nogc (struct nn_xpack *xp, struct writer *wr, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk)
|
||||
{
|
||||
return write_sample_eot (xp, wr, NULL, serdata, tk, 0, 0);
|
||||
}
|
||||
|
||||
int write_sample_gc_notk (struct nn_xpack *xp, struct writer *wr, struct ddsi_serdata *serdata)
|
||||
{
|
||||
struct tkmap_instance *tk;
|
||||
struct ddsi_tkmap_instance *tk;
|
||||
int res;
|
||||
tk = (ddsi_plugin.rhc_plugin.rhc_lookup_fn) (serdata);
|
||||
tk = ddsi_tkmap_lookup_instance_ref (serdata);
|
||||
res = write_sample_eot (xp, wr, NULL, serdata, tk, 0, 1);
|
||||
(ddsi_plugin.rhc_plugin.rhc_unref_fn) (tk);
|
||||
ddsi_tkmap_instance_unref (tk);
|
||||
return res;
|
||||
}
|
||||
|
||||
int write_sample_nogc_notk (struct nn_xpack *xp, struct writer *wr, struct ddsi_serdata *serdata)
|
||||
{
|
||||
struct tkmap_instance *tk;
|
||||
struct ddsi_tkmap_instance *tk;
|
||||
int res;
|
||||
tk = (ddsi_plugin.rhc_plugin.rhc_lookup_fn) (serdata);
|
||||
tk = ddsi_tkmap_lookup_instance_ref (serdata);
|
||||
res = write_sample_eot (xp, wr, NULL, serdata, tk, 0, 0);
|
||||
(ddsi_plugin.rhc_plugin.rhc_unref_fn) (tk);
|
||||
ddsi_tkmap_instance_unref (tk);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ extern inline void whc_return_sample (struct whc *whc, struct whc_borrowed_sampl
|
|||
extern inline void whc_sample_iter_init (const struct whc *whc, struct whc_sample_iter *it);
|
||||
extern inline bool whc_sample_iter_borrow_next (struct whc_sample_iter *it, struct whc_borrowed_sample *sample);
|
||||
extern inline void whc_free (struct whc *whc);
|
||||
extern int whc_insert (struct whc *whc, seqno_t max_drop_seq, seqno_t seq, struct nn_plist *plist, struct ddsi_serdata *serdata, struct tkmap_instance *tk);
|
||||
extern int whc_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);
|
||||
extern unsigned whc_downgrade_to_volatile (struct whc *whc, struct whc_state *st);
|
||||
extern unsigned whc_remove_acked_messages (struct whc *whc, seqno_t max_drop_seq, struct whc_state *whcst, struct whc_node **deferred_free_list);
|
||||
extern void whc_free_deferred_free_list (struct whc *whc, struct whc_node *deferred_free_list);
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "ddsi/q_xmsg.h"
|
||||
#include "ddsi/ddsi_serdata.h"
|
||||
#include "ddsi/ddsi_serdata_default.h"
|
||||
#include "ddsi/ddsi_tkmap.h"
|
||||
#include "dds__whc.h"
|
||||
|
||||
#include "ddsi/sysdeps.h"
|
||||
|
@ -1128,7 +1129,7 @@ static void write_pmd_message (struct nn_xpack *xp, struct participant *pp, unsi
|
|||
char pad[offsetof (ParticipantMessageData_t, value) + PMD_DATA_LENGTH];
|
||||
} u;
|
||||
struct ddsi_serdata *serdata;
|
||||
struct tkmap_instance *tk;
|
||||
struct ddsi_tkmap_instance *tk;
|
||||
|
||||
if ((wr = get_builtin_writer (pp, NN_ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_WRITER)) == NULL)
|
||||
{
|
||||
|
@ -1150,9 +1151,9 @@ static void write_pmd_message (struct nn_xpack *xp, struct participant *pp, unsi
|
|||
serdata = ddsi_serdata_from_sample (gv.rawcdr_topic, SDK_DATA, &raw);
|
||||
serdata->timestamp = now ();
|
||||
|
||||
tk = (ddsi_plugin.rhc_plugin.rhc_lookup_fn) (serdata);
|
||||
tk = ddsi_tkmap_lookup_instance_ref(serdata);
|
||||
write_sample_nogc (xp, wr, serdata, tk);
|
||||
(ddsi_plugin.rhc_plugin.rhc_unref_fn) (tk);
|
||||
ddsi_tkmap_instance_unref(tk);
|
||||
#undef PMD_DATA_LENGTH
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue