diff --git a/src/core/ddsc/src/dds__builtin.h b/src/core/ddsc/src/dds__builtin.h index 1c1f80c..5aed56f 100644 --- a/src/core/ddsc/src/dds__builtin.h +++ b/src/core/ddsc/src/dds__builtin.h @@ -32,7 +32,7 @@ void dds__builtin_init (struct dds_domain *dom); void dds__builtin_fini (struct dds_domain *dom); struct entity_common; -struct ddsi_serdata *dds__builtin_make_sample (const struct entity_common *e, nn_wctime_t timestamp, bool alive); +struct ddsi_serdata *dds__builtin_make_sample (const struct entity_common *e, ddsrt_wctime_t timestamp, bool alive); #if defined (__cplusplus) } diff --git a/src/core/ddsc/src/dds__rhc_default.h b/src/core/ddsc/src/dds__rhc_default.h index cf8fab3..9e3f65a 100644 --- a/src/core/ddsc/src/dds__rhc_default.h +++ b/src/core/ddsc/src/dds__rhc_default.h @@ -26,10 +26,10 @@ struct rhc_sample; DDS_EXPORT struct dds_rhc *dds_rhc_default_new_xchecks (dds_reader *reader, struct ddsi_domaingv *gv, const struct ddsi_sertopic *topic, bool xchecks); DDS_EXPORT struct dds_rhc *dds_rhc_default_new (struct dds_reader *reader, const struct ddsi_sertopic *topic); #ifdef DDSI_INCLUDE_LIFESPAN -DDS_EXPORT nn_mtime_t dds_rhc_default_sample_expired_cb(void *hc, nn_mtime_t tnow); +DDS_EXPORT ddsrt_mtime_t dds_rhc_default_sample_expired_cb(void *hc, ddsrt_mtime_t tnow); #endif #ifdef DDSI_INCLUDE_DEADLINE_MISSED -DDS_EXPORT nn_mtime_t dds_rhc_default_deadline_missed_cb(void *hc, nn_mtime_t tnow); +DDS_EXPORT ddsrt_mtime_t dds_rhc_default_deadline_missed_cb(void *hc, ddsrt_mtime_t tnow); #endif #if defined (__cplusplus) diff --git a/src/core/ddsc/src/dds_builtin.c b/src/core/ddsc/src/dds_builtin.c index ec94bef..22a76a5 100644 --- a/src/core/ddsc/src/dds_builtin.c +++ b/src/core/ddsc/src/dds_builtin.c @@ -189,7 +189,7 @@ static struct ddsi_tkmap_instance *dds__builtin_get_tkmap_entry (const struct dd return tk; } -struct ddsi_serdata *dds__builtin_make_sample (const struct entity_common *e, nn_wctime_t timestamp, bool alive) +struct ddsi_serdata *dds__builtin_make_sample (const struct entity_common *e, ddsrt_wctime_t timestamp, bool alive) { /* initialize to avoid gcc warning ultimately caused by C's horrible type system */ struct dds_domain *dom = e->gv->builtin_topic_interface->arg; @@ -219,7 +219,7 @@ struct ddsi_serdata *dds__builtin_make_sample (const struct entity_common *e, nn return serdata; } -static void dds__builtin_write (const struct entity_common *e, nn_wctime_t timestamp, bool alive, void *vdomain) +static void dds__builtin_write (const struct entity_common *e, ddsrt_wctime_t timestamp, bool alive, void *vdomain) { struct dds_domain *dom = vdomain; if (dds__builtin_is_visible (&e->guid, get_entity_vendorid (e), dom)) diff --git a/src/core/ddsc/src/dds_domain.c b/src/core/ddsc/src/dds_domain.c index dcc25a3..eca5fdc 100644 --- a/src/core/ddsc/src/dds_domain.c +++ b/src/core/ddsc/src/dds_domain.c @@ -59,7 +59,7 @@ static dds_entity_t dds_domain_init (dds_domain *domain, dds_domainid_t domain_i domain->m_entity.m_domain = domain; domain->m_entity.m_iid = ddsi_iid_gen (); - domain->gv.tstart = now (); + domain->gv.tstart = ddsrt_time_wallclock (); /* | domain_id | domain id in config | result +-----------+---------------------+---------- diff --git a/src/core/ddsc/src/dds_rhc_default.c b/src/core/ddsc/src/dds_rhc_default.c index 7c68b68..50313ed 100644 --- a/src/core/ddsc/src/dds_rhc_default.c +++ b/src/core/ddsc/src/dds_rhc_default.c @@ -274,7 +274,7 @@ struct rhc_instance { uint32_t no_writers_gen; /* __/ */ int32_t strength; /* "current" ownership strength */ ddsi_guid_t wr_guid; /* guid of last writer (if wr_iid != 0 then wr_guid is the corresponding guid, else undef) */ - nn_wctime_t tstamp; /* source time stamp of last update */ + ddsrt_wctime_t tstamp; /* source time stamp of last update */ struct ddsrt_circlist_elem nonempty_list; /* links non-empty instances in arbitrary ordering */ #ifdef DDSI_INCLUDE_DEADLINE_MISSED struct deadline_elem deadline; /* element in deadline missed administration */ @@ -594,11 +594,11 @@ static void drop_expired_samples (struct dds_rhc_default *rhc, struct rhc_sample TRACE (")\n"); } -nn_mtime_t dds_rhc_default_sample_expired_cb(void *hc, nn_mtime_t tnow) +ddsrt_mtime_t dds_rhc_default_sample_expired_cb(void *hc, ddsrt_mtime_t tnow) { struct dds_rhc_default *rhc = hc; struct rhc_sample *sample; - nn_mtime_t tnext; + ddsrt_mtime_t tnext; ddsrt_mutex_lock (&rhc->lock); while ((tnext = lifespan_next_expired_locked (&rhc->lifespan, tnow, (void **)&sample)).v == 0) drop_expired_samples (rhc, sample); @@ -608,11 +608,11 @@ nn_mtime_t dds_rhc_default_sample_expired_cb(void *hc, nn_mtime_t tnow) #endif /* DDSI_INCLUDE_LIFESPAN */ #ifdef DDSI_INCLUDE_DEADLINE_MISSED -nn_mtime_t dds_rhc_default_deadline_missed_cb(void *hc, nn_mtime_t tnow) +ddsrt_mtime_t dds_rhc_default_deadline_missed_cb(void *hc, ddsrt_mtime_t tnow) { struct dds_rhc_default *rhc = hc; void *vinst; - nn_mtime_t tnext; + ddsrt_mtime_t tnext; ddsrt_mutex_lock (&rhc->lock); while ((tnext = deadline_next_missed_locked (&rhc->deadline, tnow, &vinst)).v == 0) { @@ -630,7 +630,7 @@ nn_mtime_t dds_rhc_default_deadline_missed_cb(void *hc, nn_mtime_t tnow) dds_reader_status_cb (&rhc->reader->m_entity, &cb_data); ddsrt_mutex_lock (&rhc->lock); - tnow = now_mt (); + tnow = ddsrt_time_monotonic (); } ddsrt_mutex_unlock (&rhc->lock); return tnext; @@ -837,7 +837,7 @@ static void free_instance_rhc_free_wrap (void *vnode, void *varg) static void dds_rhc_default_free (struct dds_rhc_default *rhc) { #ifdef DDSI_INCLUDE_LIFESPAN - dds_rhc_default_sample_expired_cb (rhc, NN_MTIME_NEVER); + dds_rhc_default_sample_expired_cb (rhc, DDSRT_MTIME_NEVER); lifespan_fini (&rhc->lifespan); #endif #ifdef DDSI_INCLUDE_DEADLINE_MISSED @@ -1067,7 +1067,7 @@ static int inst_accepts_sample (const struct dds_rhc_default *rhc, const struct return 1; } -static void update_inst (struct rhc_instance *inst, const struct ddsi_writer_info * __restrict wrinfo, bool wr_iid_valid, nn_wctime_t tstamp) +static void update_inst (struct rhc_instance *inst, const struct ddsi_writer_info * __restrict wrinfo, bool wr_iid_valid, ddsrt_wctime_t tstamp) { inst->tstamp = tstamp; inst->wr_iid_islive = wr_iid_valid; @@ -1264,7 +1264,7 @@ static int rhc_unregister_isreg_w_sideeffects (struct dds_rhc_default *rhc, cons } } -static int rhc_unregister_updateinst (struct dds_rhc_default *rhc, struct rhc_instance *inst, const struct ddsi_writer_info * __restrict wrinfo, nn_wctime_t tstamp, struct trigger_info_qcond *trig_qc, bool *nda) +static int rhc_unregister_updateinst (struct dds_rhc_default *rhc, struct rhc_instance *inst, const struct ddsi_writer_info * __restrict wrinfo, ddsrt_wctime_t tstamp, struct trigger_info_qcond *trig_qc, bool *nda) { assert (inst->wrcount > 0); @@ -1327,7 +1327,7 @@ static int rhc_unregister_updateinst (struct dds_rhc_default *rhc, struct rhc_in } } -static bool dds_rhc_unregister (struct dds_rhc_default *rhc, struct rhc_instance *inst, const struct ddsi_writer_info * __restrict wrinfo, nn_wctime_t tstamp, struct trigger_info_post *post, struct trigger_info_qcond *trig_qc) +static bool dds_rhc_unregister (struct dds_rhc_default *rhc, struct rhc_instance *inst, const struct ddsi_writer_info * __restrict wrinfo, ddsrt_wctime_t tstamp, struct trigger_info_post *post, struct trigger_info_qcond *trig_qc) { bool notify_data_available = false; @@ -1384,7 +1384,7 @@ static struct rhc_instance *alloc_new_instance (struct dds_rhc_default *rhc, con #ifdef DDSI_INCLUDE_DEADLINE_MISSED if (!inst->isdisposed) - deadline_register_instance_locked (&rhc->deadline, &inst->deadline, now_mt ()); + deadline_register_instance_locked (&rhc->deadline, &inst->deadline, ddsrt_time_monotonic ()); #endif return inst; @@ -1598,7 +1598,7 @@ static bool dds_rhc_default_store (struct dds_rhc_default * __restrict rhc, cons inst->disposed_gen++; #ifdef DDSI_INCLUDE_DEADLINE_MISSED if (!is_dispose) - deadline_register_instance_locked (&rhc->deadline, &inst->deadline, now_mt ()); + deadline_register_instance_locked (&rhc->deadline, &inst->deadline, ddsrt_time_monotonic ()); #endif } if (is_dispose) @@ -1639,7 +1639,7 @@ static bool dds_rhc_default_store (struct dds_rhc_default * __restrict rhc, cons { inst->isdisposed = 0; #ifdef DDSI_INCLUDE_DEADLINE_MISSED - deadline_register_instance_locked (&rhc->deadline, &inst->deadline, now_mt ()); + deadline_register_instance_locked (&rhc->deadline, &inst->deadline, ddsrt_time_monotonic ()); #endif } goto error_or_nochange; diff --git a/src/core/ddsc/src/dds_whc.c b/src/core/ddsc/src/dds_whc.c index d9b46e7..440746b 100644 --- a/src/core/ddsc/src/dds_whc.c +++ b/src/core/ddsc/src/dds_whc.c @@ -28,7 +28,6 @@ #include "dds/ddsi/q_unused.h" #include "dds/ddsi/q_config.h" #include "dds/ddsi/ddsi_tkmap.h" -#include "dds/ddsi/q_time.h" #include "dds/ddsi/q_rtps.h" #include "dds/ddsi/q_freelist.h" #include "dds/ddsi/ddsi_domaingv.h" @@ -51,7 +50,7 @@ struct whc_node { struct ddsi_plist *plist; /* 0 if nothing special */ unsigned unacked: 1; /* counted in whc::unacked_bytes iff 1 */ unsigned borrowed: 1; /* at most one can borrow it at any time */ - nn_mtime_t last_rexmit_ts; + ddsrt_mtime_t last_rexmit_ts; uint32_t rexmit_count; #ifdef DDSI_INCLUDE_LIFESPAN struct lifespan_fhnode lifespan; /* fibheap node for lifespan */ @@ -155,7 +154,7 @@ static uint32_t whc_default_remove_acked_messages_full (struct whc_impl *whc, se static uint32_t 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, nn_mtime_t exp, struct ddsi_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk); +static int whc_default_insert (struct whc *whc, seqno_t max_drop_seq, seqno_t seq, ddsrt_mtime_t exp, struct ddsi_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); @@ -377,11 +376,11 @@ static struct whc_node *whc_findkey (const struct whc_impl *whc, const struct dd } #ifdef DDSI_INCLUDE_LIFESPAN -static nn_mtime_t whc_sample_expired_cb(void *hc, nn_mtime_t tnow) +static ddsrt_mtime_t whc_sample_expired_cb(void *hc, ddsrt_mtime_t tnow) { struct whc_impl *whc = hc; void *sample; - nn_mtime_t tnext; + ddsrt_mtime_t tnext; ddsrt_mutex_lock (&whc->lock); while ((tnext = lifespan_next_expired_locked (&whc->lifespan, tnow, &sample)).v == 0) whc_delete_one (whc, sample); @@ -392,11 +391,11 @@ static nn_mtime_t whc_sample_expired_cb(void *hc, nn_mtime_t tnow) #endif #ifdef DDSI_INCLUDE_DEADLINE_MISSED -static nn_mtime_t whc_deadline_missed_cb(void *hc, nn_mtime_t tnow) +static ddsrt_mtime_t whc_deadline_missed_cb(void *hc, ddsrt_mtime_t tnow) { struct whc_impl *whc = hc; void *vidxnode; - nn_mtime_t tnext; + ddsrt_mtime_t tnext; ddsrt_mutex_lock (&whc->lock); while ((tnext = deadline_next_missed_locked (&whc->deadline, tnow, &vidxnode)).v == 0) { @@ -412,7 +411,7 @@ static nn_mtime_t whc_deadline_missed_cb(void *hc, nn_mtime_t tnow) dds_writer_status_cb (&whc->wrinfo.writer->m_entity, &cb_data); ddsrt_mutex_lock (&whc->lock); - tnow = now_mt (); + tnow = ddsrt_time_monotonic (); } ddsrt_mutex_unlock (&whc->lock); return tnext; @@ -510,7 +509,7 @@ void whc_default_free (struct whc *whc_generic) check_whc (whc); #ifdef DDSI_INCLUDE_LIFESPAN - whc_sample_expired_cb (whc, NN_MTIME_NEVER); + whc_sample_expired_cb (whc, DDSRT_MTIME_NEVER); lifespan_fini (&whc->lifespan); #endif @@ -1156,7 +1155,7 @@ static uint32_t whc_default_remove_acked_messages (struct whc *whc_generic, seqn return cnt; } -static struct whc_node *whc_default_insert_seq (struct whc_impl *whc, seqno_t max_drop_seq, seqno_t seq, nn_mtime_t exp, struct ddsi_plist *plist, struct ddsi_serdata *serdata) +static struct whc_node *whc_default_insert_seq (struct whc_impl *whc, seqno_t max_drop_seq, seqno_t seq, ddsrt_mtime_t exp, struct ddsi_plist *plist, struct ddsi_serdata *serdata) { struct whc_node *newn = NULL; @@ -1228,7 +1227,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, nn_mtime_t exp, struct ddsi_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk) +static int whc_default_insert (struct whc *whc_generic, seqno_t max_drop_seq, seqno_t seq, ddsrt_mtime_t exp, struct ddsi_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; @@ -1364,7 +1363,7 @@ static int whc_default_insert (struct whc *whc_generic, seqno_t max_drop_seq, se if (!ddsrt_hh_add (whc->idx_hash, idxn)) assert (0); #ifdef DDSI_INCLUDE_DEADLINE_MISSED - deadline_register_instance_locked (&whc->deadline, &idxn->deadline, now_mt ()); + deadline_register_instance_locked (&whc->deadline, &idxn->deadline, ddsrt_time_monotonic ()); #endif } else diff --git a/src/core/ddsc/src/dds_whc_builtintopic.c b/src/core/ddsc/src/dds_whc_builtintopic.c index 361f515..a96d74d 100644 --- a/src/core/ddsc/src/dds_whc_builtintopic.c +++ b/src/core/ddsc/src/dds_whc_builtintopic.c @@ -143,7 +143,7 @@ static void bwhc_get_state (const struct whc *whc, struct whc_state *st) st->unacked_bytes = 0; } -static int bwhc_insert (struct whc *whc, seqno_t max_drop_seq, seqno_t seq, nn_mtime_t exp, struct ddsi_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk) +static int bwhc_insert (struct whc *whc, seqno_t max_drop_seq, seqno_t seq, ddsrt_mtime_t exp, struct ddsi_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk) { (void)whc; (void)max_drop_seq; diff --git a/src/core/ddsc/src/dds_write.c b/src/core/ddsc/src/dds_write.c index 7519548..a2b978b 100644 --- a/src/core/ddsc/src/dds_write.c +++ b/src/core/ddsc/src/dds_write.c @@ -90,7 +90,7 @@ struct local_sourceinfo { const struct ddsi_sertopic *src_topic; struct ddsi_serdata *src_payload; struct ddsi_tkmap_instance *src_tk; - nn_mtime_t timeout; + ddsrt_mtime_t timeout; }; static struct ddsi_serdata *local_make_sample (struct ddsi_tkmap_instance **tk, struct ddsi_domaingv *gv, struct ddsi_sertopic const * const topic, void *vsourceinfo) @@ -136,9 +136,9 @@ static dds_return_t local_on_delivery_failure_fastpath (struct entity_common *so assert (source_entity->kind == EK_WRITER); struct writer *wr = (struct writer *) source_entity; struct local_sourceinfo *si = vsourceinfo; - nn_mtime_t tnow = now_mt (); + ddsrt_mtime_t tnow = ddsrt_time_monotonic (); if (si->timeout.v == 0) - si->timeout = add_duration_to_mtime (tnow, wr->xqos->reliability.max_blocking_time); + si->timeout = ddsrt_mtime_add_duration (tnow, wr->xqos->reliability.max_blocking_time); if (tnow.v >= si->timeout.v) return DDS_RETCODE_TIMEOUT; else diff --git a/src/core/ddsi/CMakeLists.txt b/src/core/ddsi/CMakeLists.txt index 87b9c47..af84a9b 100644 --- a/src/core/ddsi/CMakeLists.txt +++ b/src/core/ddsi/CMakeLists.txt @@ -34,6 +34,7 @@ PREPEND(srcs_ddsi "${CMAKE_CURRENT_LIST_DIR}/src" ddsi_deliver_locally.c ddsi_plist.c ddsi_cdrstream.c + ddsi_time.c q_addrset.c q_bitset_inlines.c q_bswap.c @@ -53,7 +54,6 @@ PREPEND(srcs_ddsi "${CMAKE_CURRENT_LIST_DIR}/src" q_receive.c q_sockwaitset.c q_thread.c - q_time.c q_transmit.c q_inverse_uint32_set.c q_whc.c @@ -99,6 +99,7 @@ PREPEND(hdrs_private_ddsi "${CMAKE_CURRENT_LIST_DIR}/include/dds/ddsi" ddsi_plist.h ddsi_xqos.h ddsi_cdrstream.h + ddsi_time.h q_addrset.h q_bitset.h q_bswap.h @@ -123,7 +124,6 @@ PREPEND(hdrs_private_ddsi "${CMAKE_CURRENT_LIST_DIR}/include/dds/ddsi" q_rtps.h q_sockwaitset.h q_thread.h - q_time.h q_transmit.h q_inverse_uint32_set.h q_unused.h diff --git a/src/core/ddsi/include/dds/ddsi/ddsi_builtin_topic_if.h b/src/core/ddsi/include/dds/ddsi/ddsi_builtin_topic_if.h index fdfac07..a841e12 100644 --- a/src/core/ddsi/include/dds/ddsi/ddsi_builtin_topic_if.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_builtin_topic_if.h @@ -13,7 +13,6 @@ #define _DDSI_BUILTIN_TOPIC_IF_H_ #include "dds/ddsi/ddsi_vendor.h" -#include "dds/ddsi/q_time.h" #if defined (__cplusplus) extern "C" { @@ -30,7 +29,7 @@ struct ddsi_builtin_topic_interface { bool (*builtintopic_is_builtintopic) (const struct ddsi_sertopic *topic, void *arg); bool (*builtintopic_is_visible) (const struct ddsi_guid *guid, nn_vendorid_t vendorid, void *arg); struct ddsi_tkmap_instance * (*builtintopic_get_tkmap_entry) (const struct ddsi_guid *guid, void *arg); - void (*builtintopic_write) (const struct entity_common *e, nn_wctime_t timestamp, bool alive, void *arg); + void (*builtintopic_write) (const struct entity_common *e, ddsrt_wctime_t timestamp, bool alive, void *arg); }; inline bool builtintopic_is_visible (const struct ddsi_builtin_topic_interface *btif, const struct ddsi_guid *guid, nn_vendorid_t vendorid) { @@ -42,7 +41,7 @@ inline bool builtintopic_is_builtintopic (const struct ddsi_builtin_topic_interf inline struct ddsi_tkmap_instance *builtintopic_get_tkmap_entry (const struct ddsi_builtin_topic_interface *btif, const struct ddsi_guid *guid) { return btif ? btif->builtintopic_get_tkmap_entry (guid, btif->arg) : NULL; } -inline void builtintopic_write (const struct ddsi_builtin_topic_interface *btif, const struct entity_common *e, nn_wctime_t timestamp, bool alive) { +inline void builtintopic_write (const struct ddsi_builtin_topic_interface *btif, const struct entity_common *e, ddsrt_wctime_t timestamp, bool alive) { if (btif) btif->builtintopic_write (e, timestamp, alive, btif->arg); } diff --git a/src/core/ddsi/include/dds/ddsi/ddsi_deadline.h b/src/core/ddsi/include/dds/ddsi/ddsi_deadline.h index 7bb1044..917352e 100644 --- a/src/core/ddsi/include/dds/ddsi/ddsi_deadline.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_deadline.h @@ -13,7 +13,7 @@ #define DDSI_DEADLINE_H #include "dds/ddsrt/circlist.h" -#include "dds/ddsi/q_time.h" +#include "dds/ddsrt/time.h" #include "dds/ddsi/ddsi_domaingv.h" #include "dds/ddsi/q_xevent.h" @@ -21,7 +21,7 @@ extern "C" { #endif -typedef nn_mtime_t (*deadline_missed_cb_t)(void *hc, nn_mtime_t tnow); +typedef ddsrt_mtime_t (*deadline_missed_cb_t)(void *hc, ddsrt_mtime_t tnow); struct deadline_adm { struct ddsrt_circlist list; /* linked list for deadline missed */ @@ -34,25 +34,25 @@ struct deadline_adm { struct deadline_elem { struct ddsrt_circlist_elem e; - nn_mtime_t t_deadline; + ddsrt_mtime_t t_deadline; }; DDS_EXPORT void deadline_init (const struct ddsi_domaingv *gv, struct deadline_adm *deadline_adm, size_t list_offset, size_t elem_offset, deadline_missed_cb_t deadline_missed_cb); DDS_EXPORT void deadline_stop (const struct deadline_adm *deadline_adm); DDS_EXPORT void deadline_clear (struct deadline_adm *deadline_adm); DDS_EXPORT void deadline_fini (const struct deadline_adm *deadline_adm); -DDS_EXPORT nn_mtime_t deadline_next_missed_locked (struct deadline_adm *deadline_adm, nn_mtime_t tnow, void **instance); -DDS_EXPORT void deadline_register_instance_real (struct deadline_adm *deadline_adm, struct deadline_elem *elem, nn_mtime_t tprev, nn_mtime_t tnow); +DDS_EXPORT ddsrt_mtime_t deadline_next_missed_locked (struct deadline_adm *deadline_adm, ddsrt_mtime_t tnow, void **instance); +DDS_EXPORT void deadline_register_instance_real (struct deadline_adm *deadline_adm, struct deadline_elem *elem, ddsrt_mtime_t tprev, ddsrt_mtime_t tnow); DDS_EXPORT void deadline_unregister_instance_real (struct deadline_adm *deadline_adm, struct deadline_elem *elem); DDS_EXPORT void deadline_renew_instance_real (struct deadline_adm *deadline_adm, struct deadline_elem *elem); -inline void deadline_register_instance_locked (struct deadline_adm *deadline_adm, struct deadline_elem *elem, nn_mtime_t tnow) +inline void deadline_register_instance_locked (struct deadline_adm *deadline_adm, struct deadline_elem *elem, ddsrt_mtime_t tnow) { if (deadline_adm->dur != DDS_INFINITY) deadline_register_instance_real (deadline_adm, elem, tnow, tnow); } -inline void deadline_reregister_instance_locked (struct deadline_adm *deadline_adm, struct deadline_elem *elem, nn_mtime_t tnow) +inline void deadline_reregister_instance_locked (struct deadline_adm *deadline_adm, struct deadline_elem *elem, ddsrt_mtime_t tnow) { if (deadline_adm->dur != DDS_INFINITY) deadline_register_instance_real (deadline_adm, elem, elem->t_deadline, tnow); diff --git a/src/core/ddsi/include/dds/ddsi/ddsi_domaingv.h b/src/core/ddsi/include/dds/ddsi/ddsi_domaingv.h index b5747a7..27c9d3a 100644 --- a/src/core/ddsi/include/dds/ddsi/ddsi_domaingv.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_domaingv.h @@ -240,7 +240,7 @@ struct ddsi_domaingv { /* Start time of the DDSI2 service, for logging relative time stamps, should I ever so desire. */ - nn_wctime_t tstart; + ddsrt_wctime_t tstart; /* Default QoSs for participant, readers and writers (needed for eliminating default values in outgoing discovery packets, and for diff --git a/src/core/ddsi/include/dds/ddsi/ddsi_lifespan.h b/src/core/ddsi/include/dds/ddsi/ddsi_lifespan.h index e8202ee..b5e3e66 100644 --- a/src/core/ddsi/include/dds/ddsi/ddsi_lifespan.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_lifespan.h @@ -13,14 +13,14 @@ #define DDSI_LIFESPAN_H #include "dds/ddsrt/fibheap.h" -#include "dds/ddsi/q_time.h" +#include "dds/ddsrt/time.h" #include "dds/ddsi/ddsi_domaingv.h" #if defined (__cplusplus) extern "C" { #endif -typedef nn_mtime_t (*sample_expired_cb_t)(void *hc, nn_mtime_t tnow); +typedef ddsrt_mtime_t (*sample_expired_cb_t)(void *hc, ddsrt_mtime_t tnow); struct lifespan_adm { ddsrt_fibheap_t ls_exp_heap; /* heap for sample expiration (lifespan) */ @@ -32,12 +32,12 @@ struct lifespan_adm { struct lifespan_fhnode { ddsrt_fibheap_node_t heapnode; - nn_mtime_t t_expire; + ddsrt_mtime_t t_expire; }; DDS_EXPORT void lifespan_init (const struct ddsi_domaingv *gv, struct lifespan_adm *lifespan_adm, size_t fh_offset, size_t fh_node_offset, sample_expired_cb_t sample_expired_cb); DDS_EXPORT void lifespan_fini (const struct lifespan_adm *lifespan_adm); -DDS_EXPORT nn_mtime_t lifespan_next_expired_locked (const struct lifespan_adm *lifespan_adm, nn_mtime_t tnow, void **sample); +DDS_EXPORT ddsrt_mtime_t lifespan_next_expired_locked (const struct lifespan_adm *lifespan_adm, ddsrt_mtime_t tnow, void **sample); DDS_EXPORT void lifespan_register_sample_real (struct lifespan_adm *lifespan_adm, struct lifespan_fhnode *node); DDS_EXPORT void lifespan_unregister_sample_real (struct lifespan_adm *lifespan_adm, struct lifespan_fhnode *node); diff --git a/src/core/ddsi/include/dds/ddsi/ddsi_pmd.h b/src/core/ddsi/include/dds/ddsi/ddsi_pmd.h index a2b1daf..0948247 100644 --- a/src/core/ddsi/include/dds/ddsi/ddsi_pmd.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_pmd.h @@ -12,7 +12,7 @@ #ifndef DDSI_PMD_H #define DDSI_PMD_H -#include "dds/ddsi/q_time.h" +#include "dds/ddsrt/time.h" #if defined (__cplusplus) extern "C" { @@ -27,7 +27,7 @@ struct receiver_state; void write_pmd_message_guid (struct ddsi_domaingv * const gv, struct ddsi_guid *pp_guid, unsigned pmd_kind); void write_pmd_message (struct thread_state1 * const ts1, struct nn_xpack *xp, struct participant *pp, unsigned pmd_kind); -void handle_pmd_message (const struct receiver_state *rst, nn_wctime_t timestamp, uint32_t statusinfo, const void *vdata, uint32_t len); +void handle_pmd_message (const struct receiver_state *rst, ddsrt_wctime_t timestamp, uint32_t statusinfo, const void *vdata, uint32_t len); #if defined (__cplusplus) } diff --git a/src/core/ddsi/include/dds/ddsi/ddsi_rhc.h b/src/core/ddsi/include/dds/ddsi/ddsi_rhc.h index 506e407..92c560f 100644 --- a/src/core/ddsi/include/dds/ddsi/ddsi_rhc.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_rhc.h @@ -20,8 +20,8 @@ /* DDS_EXPORT inline i.c.w. __attributes__((visibility...)) and some compilers: */ #include "dds/ddsrt/attributes.h" +#include "dds/ddsrt/time.h" #include "dds/ddsi/ddsi_guid.h" -#include "dds/ddsi/q_time.h" #if defined (__cplusplus) extern "C" { @@ -40,7 +40,7 @@ struct ddsi_writer_info int32_t ownership_strength; uint64_t iid; #ifdef DDSI_INCLUDE_LIFESPAN - nn_mtime_t lifespan_exp; + ddsrt_mtime_t lifespan_exp; #endif }; diff --git a/src/core/ddsi/include/dds/ddsi/ddsi_serdata.h b/src/core/ddsi/include/dds/ddsi/ddsi_serdata.h index ceb5112..7b9559b 100644 --- a/src/core/ddsi/include/dds/ddsi/ddsi_serdata.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_serdata.h @@ -13,7 +13,6 @@ #define DDSI_SERDATA_H #include "dds/ddsrt/sockets.h" -#include "dds/ddsi/q_time.h" #include "dds/ddsi/ddsi_sertopic.h" #if defined (__cplusplus) @@ -37,11 +36,11 @@ struct ddsi_serdata { const struct ddsi_sertopic *topic; /* these get set by generic code after creating the serdata */ - nn_wctime_t timestamp; + ddsrt_wctime_t timestamp; uint32_t statusinfo; /* FIXME: can I get rid of this one? */ - nn_mtime_t twrite; /* write time, not source timestamp, set post-throttling */ + ddsrt_mtime_t twrite; /* write time, not source timestamp, set post-throttling */ }; /* Serialised size of sample inclusive of DDSI encoding header diff --git a/src/core/ddsi/include/dds/ddsi/ddsi_time.h b/src/core/ddsi/include/dds/ddsi/ddsi_time.h new file mode 100644 index 0000000..baac1f5 --- /dev/null +++ b/src/core/ddsi/include/dds/ddsi/ddsi_time.h @@ -0,0 +1,44 @@ +/* + * 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 DDSI_TIME_H +#define DDSI_TIME_H + +#include + +#include "dds/export.h" +#include "dds/ddsrt/time.h" + +#if defined (__cplusplus) +extern "C" { +#endif + +typedef struct { + int32_t seconds; + uint32_t fraction; +} ddsi_time_t; +#define DDSI_TIME_INFINITE ((ddsi_time_t) { INT32_MAX, UINT32_MAX }) +#define DDSI_TIME_INVALID ((ddsi_time_t) { -1, UINT32_MAX }) + +typedef ddsi_time_t ddsi_duration_t; + +bool ddsi_is_valid_timestamp (ddsi_time_t t); + +DDS_EXPORT ddsi_time_t ddsi_wctime_to_ddsi_time (ddsrt_wctime_t t); +DDS_EXPORT ddsrt_wctime_t ddsi_wctime_from_ddsi_time (ddsi_time_t x); +DDS_EXPORT ddsi_duration_t ddsi_to_ddsi_duration (dds_duration_t t); +DDS_EXPORT dds_duration_t ddsi_from_ddsi_duration (ddsi_duration_t x); + +#if defined (__cplusplus) +} +#endif + +#endif /* DDSI_TIME_H */ diff --git a/src/core/ddsi/include/dds/ddsi/q_entity.h b/src/core/ddsi/include/dds/ddsi/q_entity.h index c90e2bc..ab017c3 100644 --- a/src/core/ddsi/include/dds/ddsi/q_entity.h +++ b/src/core/ddsi/include/dds/ddsi/q_entity.h @@ -119,9 +119,9 @@ struct wr_prd_match { ddsi_guid_t arbitrary_unacked_reader; nn_count_t next_acknack; /* next acceptable acknack sequence number */ nn_count_t next_nackfrag; /* next acceptable nackfrag sequence number */ - nn_etime_t t_acknack_accepted; /* (local) time an acknack was last accepted */ + ddsrt_etime_t t_acknack_accepted; /* (local) time an acknack was last accepted */ struct nn_lat_estim hb_to_ack_latency; - nn_wctime_t hb_to_ack_latency_tlastlog; + ddsrt_wctime_t hb_to_ack_latency_tlastlog; uint32_t non_responsive_count; uint32_t rexmit_requests; }; @@ -135,12 +135,12 @@ enum pwr_rd_match_syncstate { struct pwr_rd_match { ddsrt_avl_node_t avlnode; ddsi_guid_t rd_guid; - nn_mtime_t tcreate; + ddsrt_mtime_t tcreate; nn_count_t count; /* most recent acknack sequence number */ nn_count_t next_heartbeat; /* next acceptable heartbeat (see also add_proxy_writer_to_reader) */ - nn_wctime_t hb_timestamp; /* time of most recent heartbeat that rescheduled the ack event */ - nn_etime_t t_heartbeat_accepted; /* (local) time a heartbeat was last accepted */ - nn_mtime_t t_last_nack; /* (local) time we last sent a NACK */ /* FIXME: probably elapsed time is better */ + ddsrt_wctime_t hb_timestamp; /* time of most recent heartbeat that rescheduled the ack event */ + ddsrt_etime_t t_heartbeat_accepted; /* (local) time a heartbeat was last accepted */ + ddsrt_mtime_t t_last_nack; /* (local) time we last sent a NACK */ /* FIXME: probably elapsed time is better */ seqno_t seq_last_nack; /* last seq for which we requested a retransmit */ struct xevent *acknack_xevent; /* entry in xevent queue for sending acknacks */ enum pwr_rd_match_syncstate in_sync; /* whether in sync with the proxy writer */ @@ -159,7 +159,7 @@ struct ddsi_tkmap_instance; struct entity_common { enum entity_kind kind; ddsi_guid_t guid; - nn_wctime_t tupdate; /* timestamp of last update */ + ddsrt_wctime_t tupdate; /* timestamp of last update */ char *name; uint64_t iid; struct ddsi_tkmap_instance *tk; @@ -271,8 +271,8 @@ struct writer struct ldur_fhnode *lease_duration; /* fibheap node to keep lease duration for this writer, NULL in case of automatic liveliness with inifite duration */ struct whc *whc; /* WHC tracking history, T-L durability service history + samples by sequence number for retransmit */ uint32_t whc_low, whc_high; /* watermarks for WHC in bytes (counting only unack'd data) */ - nn_etime_t t_rexmit_end; /* time of last 1->0 transition of "retransmitting" */ - nn_etime_t t_whc_high_upd; /* time "whc_high" was last updated for controlled ramp-up of throughput */ + ddsrt_etime_t t_rexmit_end; /* time of last 1->0 transition of "retransmitting" */ + ddsrt_etime_t t_whc_high_upd; /* time "whc_high" was last updated for controlled ramp-up of throughput */ int32_t num_reliable_readers; /* number of matching reliable PROXY readers */ ddsrt_avl_tree_t readers; /* all matching PROXY readers, see struct wr_prd_match */ ddsrt_avl_tree_t local_readers; /* all matching LOCAL readers, see struct wr_rd_match */ @@ -653,11 +653,11 @@ int writer_set_notalive (struct writer *wr, bool notify); /* Set when this proxy participant is not to be announced on the built-in topics yet */ #define CF_PROXYPP_NO_SPDP (1 << 3) -void new_proxy_participant (struct ddsi_domaingv *gv, const struct ddsi_guid *guid, uint32_t bes, const struct ddsi_guid *privileged_pp_guid, struct addrset *as_default, struct addrset *as_meta, const struct ddsi_plist *plist, dds_duration_t tlease_dur, nn_vendorid_t vendor, unsigned custom_flags, nn_wctime_t timestamp, seqno_t seq); -int delete_proxy_participant_by_guid (struct ddsi_domaingv *gv, const struct ddsi_guid *guid, nn_wctime_t timestamp, int isimplicit); +void new_proxy_participant (struct ddsi_domaingv *gv, const struct ddsi_guid *guid, uint32_t bes, const struct ddsi_guid *privileged_pp_guid, struct addrset *as_default, struct addrset *as_meta, const struct ddsi_plist *plist, dds_duration_t tlease_dur, nn_vendorid_t vendor, unsigned custom_flags, ddsrt_wctime_t timestamp, seqno_t seq); +int delete_proxy_participant_by_guid (struct ddsi_domaingv *gv, const struct ddsi_guid *guid, ddsrt_wctime_t timestamp, int isimplicit); -int update_proxy_participant_plist_locked (struct proxy_participant *proxypp, seqno_t seq, const struct ddsi_plist *datap, nn_wctime_t timestamp); -int update_proxy_participant_plist (struct proxy_participant *proxypp, seqno_t seq, const struct ddsi_plist *datap, nn_wctime_t timestamp); +int update_proxy_participant_plist_locked (struct proxy_participant *proxypp, seqno_t seq, const struct ddsi_plist *datap, ddsrt_wctime_t timestamp); +int update_proxy_participant_plist (struct proxy_participant *proxypp, seqno_t seq, const struct ddsi_plist *datap, ddsrt_wctime_t timestamp); void proxy_participant_reassign_lease (struct proxy_participant *proxypp, struct lease *newlease); void purge_proxy_participants (struct ddsi_domaingv *gv, const nn_locator_t *loc, bool delete_from_as_disc); @@ -665,8 +665,8 @@ void purge_proxy_participants (struct ddsi_domaingv *gv, const nn_locator_t *loc /* To create a new proxy writer or reader; the proxy participant is determined from the GUID and must exist. */ - int new_proxy_writer (struct ddsi_domaingv *gv, const struct ddsi_guid *ppguid, const struct ddsi_guid *guid, struct addrset *as, const struct ddsi_plist *plist, struct nn_dqueue *dqueue, struct xeventq *evq, nn_wctime_t timestamp, seqno_t seq); -int new_proxy_reader (struct ddsi_domaingv *gv, const struct ddsi_guid *ppguid, const struct ddsi_guid *guid, struct addrset *as, const struct ddsi_plist *plist, nn_wctime_t timestamp, seqno_t seq + int new_proxy_writer (struct ddsi_domaingv *gv, const struct ddsi_guid *ppguid, const struct ddsi_guid *guid, struct addrset *as, const struct ddsi_plist *plist, struct nn_dqueue *dqueue, struct xeventq *evq, ddsrt_wctime_t timestamp, seqno_t seq); +int new_proxy_reader (struct ddsi_domaingv *gv, const struct ddsi_guid *ppguid, const struct ddsi_guid *guid, struct addrset *as, const struct ddsi_plist *plist, ddsrt_wctime_t timestamp, seqno_t seq #ifdef DDSI_INCLUDE_SSM , int favours_ssm #endif @@ -677,19 +677,19 @@ int new_proxy_reader (struct ddsi_domaingv *gv, const struct ddsi_guid *ppguid, reader or writer. Actual deletion is scheduled in the future, when no outstanding references may still exist (determined by checking thread progress, &c.). */ -int delete_proxy_writer (struct ddsi_domaingv *gv, const struct ddsi_guid *guid, nn_wctime_t timestamp, int isimplicit); -int delete_proxy_reader (struct ddsi_domaingv *gv, const struct ddsi_guid *guid, nn_wctime_t timestamp, int isimplicit); +int delete_proxy_writer (struct ddsi_domaingv *gv, const struct ddsi_guid *guid, ddsrt_wctime_t timestamp, int isimplicit); +int delete_proxy_reader (struct ddsi_domaingv *gv, const struct ddsi_guid *guid, ddsrt_wctime_t timestamp, int isimplicit); -void update_proxy_reader (struct proxy_reader *prd, seqno_t seq, struct addrset *as, const struct dds_qos *xqos, nn_wctime_t timestamp); -void update_proxy_writer (struct proxy_writer *pwr, seqno_t seq, struct addrset *as, const struct dds_qos *xqos, nn_wctime_t timestamp); +void update_proxy_reader (struct proxy_reader *prd, seqno_t seq, struct addrset *as, const struct dds_qos *xqos, ddsrt_wctime_t timestamp); +void update_proxy_writer (struct proxy_writer *pwr, seqno_t seq, struct addrset *as, const struct dds_qos *xqos, ddsrt_wctime_t timestamp); void proxy_writer_set_alive_may_unlock (struct proxy_writer *pwr, bool notify); int proxy_writer_set_notalive (struct proxy_writer *pwr, bool notify); -int new_proxy_group (const struct ddsi_guid *guid, const char *name, const struct dds_qos *xqos, nn_wctime_t timestamp); +int new_proxy_group (const struct ddsi_guid *guid, const char *name, const struct dds_qos *xqos, ddsrt_wctime_t timestamp); struct entity_index; -void delete_proxy_group (struct entity_index *entidx, const struct ddsi_guid *guid, nn_wctime_t timestamp, int isimplicit); +void delete_proxy_group (struct entity_index *entidx, const struct ddsi_guid *guid, ddsrt_wctime_t timestamp, int isimplicit); /* Call this to empty all address sets of all writers to stop all outgoing traffic, or to rebuild them all (which only makes sense after previously having emptied them all). */ diff --git a/src/core/ddsi/include/dds/ddsi/q_hbcontrol.h b/src/core/ddsi/include/dds/ddsi/q_hbcontrol.h index ca6a56f..389e29a 100644 --- a/src/core/ddsi/include/dds/ddsi/q_hbcontrol.h +++ b/src/core/ddsi/include/dds/ddsi/q_hbcontrol.h @@ -20,21 +20,21 @@ struct writer; struct whc_state; struct hbcontrol { - nn_mtime_t t_of_last_write; - nn_mtime_t t_of_last_hb; - nn_mtime_t t_of_last_ackhb; - nn_mtime_t tsched; + ddsrt_mtime_t t_of_last_write; + ddsrt_mtime_t t_of_last_hb; + ddsrt_mtime_t t_of_last_ackhb; + ddsrt_mtime_t tsched; uint32_t hbs_since_last_write; uint32_t last_packetid; }; void writer_hbcontrol_init (struct hbcontrol *hbc); -int64_t writer_hbcontrol_intv (const struct writer *wr, const struct whc_state *whcst, nn_mtime_t tnow); -void writer_hbcontrol_note_asyncwrite (struct writer *wr, nn_mtime_t tnow); -int writer_hbcontrol_ack_required (const struct writer *wr, const struct whc_state *whcst, nn_mtime_t tnow); -struct nn_xmsg *writer_hbcontrol_piggyback (struct writer *wr, const struct whc_state *whcst, nn_mtime_t tnow, uint32_t packetid, int *hbansreq); -int writer_hbcontrol_must_send (const struct writer *wr, const struct whc_state *whcst, nn_mtime_t tnow); -struct nn_xmsg *writer_hbcontrol_create_heartbeat (struct writer *wr, const struct whc_state *whcst, nn_mtime_t tnow, int hbansreq, int issync); +int64_t writer_hbcontrol_intv (const struct writer *wr, const struct whc_state *whcst, ddsrt_mtime_t tnow); +void writer_hbcontrol_note_asyncwrite (struct writer *wr, ddsrt_mtime_t tnow); +int writer_hbcontrol_ack_required (const struct writer *wr, const struct whc_state *whcst, ddsrt_mtime_t tnow); +struct nn_xmsg *writer_hbcontrol_piggyback (struct writer *wr, const struct whc_state *whcst, ddsrt_mtime_t tnow, uint32_t packetid, int *hbansreq); +int writer_hbcontrol_must_send (const struct writer *wr, const struct whc_state *whcst, ddsrt_mtime_t tnow); +struct nn_xmsg *writer_hbcontrol_create_heartbeat (struct writer *wr, const struct whc_state *whcst, ddsrt_mtime_t tnow, int hbansreq, int issync); #if defined (__cplusplus) } diff --git a/src/core/ddsi/include/dds/ddsi/q_lease.h b/src/core/ddsi/include/dds/ddsi/q_lease.h index b6c5f5c..e427cc0 100644 --- a/src/core/ddsi/include/dds/ddsi/q_lease.h +++ b/src/core/ddsi/include/dds/ddsi/q_lease.h @@ -15,7 +15,6 @@ #include "dds/ddsrt/atomics.h" #include "dds/ddsrt/fibheap.h" #include "dds/ddsrt/time.h" -#include "dds/ddsi/q_time.h" #if defined (__cplusplus) extern "C" { @@ -29,7 +28,7 @@ struct ddsi_domaingv; /* FIXME: make a special for the lease admin */ struct lease { ddsrt_fibheap_node_t heapnode; ddsrt_fibheap_node_t pp_heapnode; - nn_etime_t tsched; /* access guarded by leaseheap_lock */ + ddsrt_etime_t tsched; /* access guarded by leaseheap_lock */ ddsrt_atomic_uint64_t tend; /* really an nn_etime_t */ dds_duration_t tdur; /* constant (renew depends on it) */ struct entity_common *entity; /* constant */ @@ -39,14 +38,14 @@ int compare_lease_tsched (const void *va, const void *vb); int compare_lease_tdur (const void *va, const void *vb); void lease_management_init (struct ddsi_domaingv *gv); void lease_management_term (struct ddsi_domaingv *gv); -struct lease *lease_new (nn_etime_t texpire, int64_t tdur, struct entity_common *e); +struct lease *lease_new (ddsrt_etime_t texpire, int64_t tdur, struct entity_common *e); struct lease *lease_clone (const struct lease *l); void lease_register (struct lease *l); void lease_unregister (struct lease *l); void lease_free (struct lease *l); -void lease_renew (struct lease *l, nn_etime_t tnow); -void lease_set_expiry (struct lease *l, nn_etime_t when); -int64_t check_and_handle_lease_expiration (struct ddsi_domaingv *gv, nn_etime_t tnow); +void lease_renew (struct lease *l, ddsrt_etime_t tnow); +void lease_set_expiry (struct lease *l, ddsrt_etime_t when); +int64_t check_and_handle_lease_expiration (struct ddsi_domaingv *gv, ddsrt_etime_t tnow); #if defined (__cplusplus) } diff --git a/src/core/ddsi/include/dds/ddsi/q_log.h b/src/core/ddsi/include/dds/ddsi/q_log.h index fb7c5b7..64d3c0f 100644 --- a/src/core/ddsi/include/dds/ddsi/q_log.h +++ b/src/core/ddsi/include/dds/ddsi/q_log.h @@ -15,7 +15,7 @@ #include #include "dds/ddsrt/log.h" -#include "dds/ddsi/q_time.h" +#include "dds/ddsi/ddsi_time.h" #include "dds/ddsrt/rusage.h" #if defined (__cplusplus) @@ -45,7 +45,7 @@ extern "C" { #define LOG_THREAD_CPUTIME(logcfg, guard) \ do { \ if ((logcfg)->c.mask & DDS_LC_TIMING) { \ - nn_mtime_t tnowlt = now_mt(); \ + ddsrt_mtime_t tnowlt = ddsrt_time_monotonic (); \ if (tnowlt.v >= (guard).v) { \ ddsrt_rusage_t usage; \ if (ddsrt_getrusage(DDSRT_RUSAGE_THREAD, &usage) == 0) { \ diff --git a/src/core/ddsi/include/dds/ddsi/q_pcap.h b/src/core/ddsi/include/dds/ddsi/q_pcap.h index 94f7d22..6ae6d66 100644 --- a/src/core/ddsi/include/dds/ddsi/q_pcap.h +++ b/src/core/ddsi/include/dds/ddsi/q_pcap.h @@ -13,7 +13,7 @@ #define Q_PCAP_H #include -#include "dds/ddsi/q_time.h" +#include "dds/ddsrt/time.h" #if defined (__cplusplus) extern "C" { @@ -23,8 +23,8 @@ struct msghdr; FILE * new_pcap_file (const struct ddsrt_log_cfg *logcfg, const char *name); -void write_pcap_received (struct ddsi_domaingv *gv, nn_wctime_t tstamp, const struct sockaddr_storage *src, const struct sockaddr_storage *dst, unsigned char *buf, size_t sz); -void write_pcap_sent (struct ddsi_domaingv *gv, nn_wctime_t tstamp, const struct sockaddr_storage *src, +void write_pcap_received (struct ddsi_domaingv *gv, ddsrt_wctime_t tstamp, const struct sockaddr_storage *src, const struct sockaddr_storage *dst, unsigned char *buf, size_t sz); +void write_pcap_sent (struct ddsi_domaingv *gv, ddsrt_wctime_t tstamp, const struct sockaddr_storage *src, const ddsrt_msghdr_t *hdr, size_t sz); #if defined (__cplusplus) diff --git a/src/core/ddsi/include/dds/ddsi/q_protocol.h b/src/core/ddsi/include/dds/ddsi/q_protocol.h index e158df9..1bae50a 100644 --- a/src/core/ddsi/include/dds/ddsi/q_protocol.h +++ b/src/core/ddsi/include/dds/ddsi/q_protocol.h @@ -17,7 +17,7 @@ #include "dds/ddsi/q_feature_check.h" #include "dds/ddsi/q_rtps.h" -#include "dds/ddsi/q_time.h" +#include "dds/ddsi/ddsi_time.h" #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsi/include/dds/ddsi/q_radmin.h b/src/core/ddsi/include/dds/ddsi/q_radmin.h index 9ded3d4..af5e3d0 100644 --- a/src/core/ddsi/include/dds/ddsi/q_radmin.h +++ b/src/core/ddsi/include/dds/ddsi/q_radmin.h @@ -120,8 +120,8 @@ struct nn_rsample_info { struct proxy_writer *pwr; uint32_t size; uint32_t fragsize; - nn_wctime_t timestamp; - nn_wctime_t reception_timestamp; /* OpenSplice extension -- but we get it essentially for free, so why not? */ + ddsrt_wctime_t timestamp; + ddsrt_wctime_t reception_timestamp; /* OpenSplice extension -- but we get it essentially for free, so why not? */ unsigned statusinfo: 2; /* just the two defined bits from the status info */ unsigned pt_wr_info_zoff: 16; /* PrismTech writer info offset */ unsigned bswap: 1; /* so we can extract well formatted writer info quicker */ diff --git a/src/core/ddsi/include/dds/ddsi/q_time.h b/src/core/ddsi/include/dds/ddsi/q_time.h deleted file mode 100644 index 03b5b5e..0000000 --- a/src/core/ddsi/include/dds/ddsi/q_time.h +++ /dev/null @@ -1,71 +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 NN_TIME_H -#define NN_TIME_H - -#include - -#include "dds/export.h" - -#if defined (__cplusplus) -extern "C" { -#endif - -typedef struct { - int32_t seconds; - uint32_t fraction; -} ddsi_time_t; -#define DDSI_TIME_INFINITE ((ddsi_time_t) { INT32_MAX, UINT32_MAX }) -#define DDSI_TIME_INVALID ((ddsi_time_t) { -1, UINT32_MAX }) - -typedef ddsi_time_t ddsi_duration_t; - -typedef struct { - int64_t v; -} nn_mtime_t; - -typedef struct { - int64_t v; -} nn_wctime_t; - -typedef struct { - int64_t v; -} nn_etime_t; - -#define NN_MTIME_NEVER ((nn_mtime_t) { DDS_NEVER }) -#define NN_WCTIME_NEVER ((nn_wctime_t) { DDS_NEVER }) -#define NN_ETIME_NEVER ((nn_etime_t) { DDS_NEVER }) -#define NN_WCTIME_INVALID ((nn_wctime_t) { INT64_MIN }) - -int valid_ddsi_timestamp (ddsi_time_t t); - -DDS_EXPORT nn_wctime_t now (void); /* wall clock time */ -DDS_EXPORT nn_mtime_t now_mt (void); /* monotonic time */ -DDS_EXPORT nn_etime_t now_et (void); /* elapsed time */ -DDS_EXPORT void mtime_to_sec_usec (int32_t * __restrict sec, int32_t * __restrict usec, nn_mtime_t t); -DDS_EXPORT void wctime_to_sec_usec (int32_t * __restrict sec, int32_t * __restrict usec, nn_wctime_t t); -DDS_EXPORT void etime_to_sec_usec (int32_t * __restrict sec, int32_t * __restrict usec, nn_etime_t t); -DDS_EXPORT nn_mtime_t mtime_round_up (nn_mtime_t t, int64_t round); -DDS_EXPORT nn_mtime_t add_duration_to_mtime (nn_mtime_t t, int64_t d); -DDS_EXPORT nn_wctime_t add_duration_to_wctime (nn_wctime_t t, int64_t d); -DDS_EXPORT nn_etime_t add_duration_to_etime (nn_etime_t t, int64_t d); - -DDS_EXPORT ddsi_time_t nn_wctime_to_ddsi_time (nn_wctime_t t); -DDS_EXPORT nn_wctime_t nn_wctime_from_ddsi_time (ddsi_time_t x); -DDS_EXPORT ddsi_duration_t nn_to_ddsi_duration (int64_t t); -DDS_EXPORT int64_t nn_from_ddsi_duration (ddsi_duration_t x); - -#if defined (__cplusplus) -} -#endif - -#endif /* NN_TIME_H */ diff --git a/src/core/ddsi/include/dds/ddsi/q_whc.h b/src/core/ddsi/include/dds/ddsi/q_whc.h index 40622a8..d654755 100644 --- a/src/core/ddsi/include/dds/ddsi/q_whc.h +++ b/src/core/ddsi/include/dds/ddsi/q_whc.h @@ -13,7 +13,7 @@ #define Q_WHC_H #include -#include "dds/ddsi/q_time.h" +#include "dds/ddsrt/time.h" #if defined (__cplusplus) extern "C" { @@ -30,7 +30,7 @@ struct whc_borrowed_sample { struct ddsi_serdata *serdata; struct ddsi_plist *plist; bool unacked; - nn_mtime_t last_rexmit_ts; + ddsrt_mtime_t last_rexmit_ts; unsigned rexmit_count; }; @@ -73,7 +73,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 ddsrt_malloc'd, WHC takes ownership of plist */ -typedef int (*whc_insert_t)(struct whc *whc, seqno_t max_drop_seq, seqno_t seq, nn_mtime_t exp, struct ddsi_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk); +typedef int (*whc_insert_t)(struct whc *whc, seqno_t max_drop_seq, seqno_t seq, ddsrt_mtime_t exp, struct ddsi_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk); typedef uint32_t (*whc_downgrade_to_volatile_t)(struct whc *whc, struct whc_state *st); typedef uint32_t (*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); @@ -121,7 +121,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, nn_mtime_t exp, struct ddsi_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk) { +inline int whc_insert (struct whc *whc, seqno_t max_drop_seq, seqno_t seq, ddsrt_mtime_t exp, struct ddsi_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk) { return whc->ops->insert (whc, max_drop_seq, seq, exp, plist, serdata, tk); } inline unsigned whc_downgrade_to_volatile (struct whc *whc, struct whc_state *st) { diff --git a/src/core/ddsi/include/dds/ddsi/q_xevent.h b/src/core/ddsi/include/dds/ddsi/q_xevent.h index 3925ba6..41bd5b1 100644 --- a/src/core/ddsi/include/dds/ddsi/q_xevent.h +++ b/src/core/ddsi/include/dds/ddsi/q_xevent.h @@ -60,16 +60,16 @@ DDS_EXPORT int qxev_msg_rexmit_wrlock_held (struct xeventq *evq, struct nn_xmsg /* All of the following lock EVQ for the duration of the operation */ DDS_EXPORT void delete_xevent (struct xevent *ev); DDS_EXPORT void delete_xevent_callback (struct xevent *ev); -DDS_EXPORT int resched_xevent_if_earlier (struct xevent *ev, nn_mtime_t tsched); +DDS_EXPORT int resched_xevent_if_earlier (struct xevent *ev, ddsrt_mtime_t tsched); -DDS_EXPORT struct xevent *qxev_heartbeat (struct xeventq *evq, nn_mtime_t tsched, const ddsi_guid_t *wr_guid); -DDS_EXPORT struct xevent *qxev_acknack (struct xeventq *evq, nn_mtime_t tsched, const ddsi_guid_t *pwr_guid, const ddsi_guid_t *rd_guid); -DDS_EXPORT struct xevent *qxev_spdp (struct xeventq *evq, nn_mtime_t tsched, const ddsi_guid_t *pp_guid, const ddsi_guid_t *proxypp_guid); -DDS_EXPORT struct xevent *qxev_pmd_update (struct xeventq *evq, nn_mtime_t tsched, const ddsi_guid_t *pp_guid); -DDS_EXPORT struct xevent *qxev_delete_writer (struct xeventq *evq, nn_mtime_t tsched, const ddsi_guid_t *guid); +DDS_EXPORT struct xevent *qxev_heartbeat (struct xeventq *evq, ddsrt_mtime_t tsched, const ddsi_guid_t *wr_guid); +DDS_EXPORT struct xevent *qxev_acknack (struct xeventq *evq, ddsrt_mtime_t tsched, const ddsi_guid_t *pwr_guid, const ddsi_guid_t *rd_guid); +DDS_EXPORT struct xevent *qxev_spdp (struct xeventq *evq, ddsrt_mtime_t tsched, const ddsi_guid_t *pp_guid, const ddsi_guid_t *proxypp_guid); +DDS_EXPORT struct xevent *qxev_pmd_update (struct xeventq *evq, ddsrt_mtime_t tsched, const ddsi_guid_t *pp_guid); +DDS_EXPORT struct xevent *qxev_delete_writer (struct xeventq *evq, ddsrt_mtime_t tsched, const ddsi_guid_t *guid); /* cb will be called with now = NEVER if the event is still enqueued when when xeventq_free starts cleaning up */ -DDS_EXPORT struct xevent *qxev_callback (struct xeventq *evq, nn_mtime_t tsched, void (*cb) (struct xevent *xev, void *arg, nn_mtime_t now), void *arg); +DDS_EXPORT struct xevent *qxev_callback (struct xeventq *evq, ddsrt_mtime_t tsched, void (*cb) (struct xevent *xev, void *arg, ddsrt_mtime_t now), void *arg); #if defined (__cplusplus) } diff --git a/src/core/ddsi/include/dds/ddsi/q_xmsg.h b/src/core/ddsi/include/dds/ddsi/q_xmsg.h index ed717b7..b002e67 100644 --- a/src/core/ddsi/include/dds/ddsi/q_xmsg.h +++ b/src/core/ddsi/include/dds/ddsi/q_xmsg.h @@ -117,7 +117,7 @@ void nn_xmsg_shrink (struct nn_xmsg *m, struct nn_xmsg_marker marker, size_t sz) void nn_xmsg_serdata (struct nn_xmsg *m, struct ddsi_serdata *serdata, size_t off, size_t len); void nn_xmsg_submsg_setnext (struct nn_xmsg *msg, struct nn_xmsg_marker marker); void nn_xmsg_submsg_init (struct nn_xmsg *msg, struct nn_xmsg_marker marker, SubmessageKind_t smkind); -void nn_xmsg_add_timestamp (struct nn_xmsg *m, nn_wctime_t t); +void nn_xmsg_add_timestamp (struct nn_xmsg *m, ddsrt_wctime_t t); void nn_xmsg_add_entityid (struct nn_xmsg * m); void *nn_xmsg_addpar (struct nn_xmsg *m, nn_parameterid_t pid, size_t len); void nn_xmsg_addpar_keyhash (struct nn_xmsg *m, const struct ddsi_serdata *serdata); diff --git a/src/core/ddsi/src/ddsi_deadline.c b/src/core/ddsi/src/ddsi_deadline.c index 56ab8e4..3c07034 100644 --- a/src/core/ddsi/src/ddsi_deadline.c +++ b/src/core/ddsi/src/ddsi_deadline.c @@ -12,22 +12,22 @@ #include #include #include "dds/ddsrt/circlist.h" +#include "dds/ddsrt/time.h" #include "dds/ddsi/ddsi_deadline.h" -#include "dds/ddsi/q_time.h" #include "dds/ddsi/q_xevent.h" -static void instance_deadline_missed_cb (struct xevent *xev, void *varg, nn_mtime_t tnow) +static void instance_deadline_missed_cb (struct xevent *xev, void *varg, ddsrt_mtime_t tnow) { struct deadline_adm * const deadline_adm = varg; - nn_mtime_t next_valid = deadline_adm->deadline_missed_cb((char *)deadline_adm - deadline_adm->list_offset, tnow); + ddsrt_mtime_t next_valid = deadline_adm->deadline_missed_cb((char *)deadline_adm - deadline_adm->list_offset, tnow); resched_xevent_if_earlier (xev, next_valid); } /* Gets the instance from the list in deadline admin that has the earliest missed deadline and * removes the instance element from the list. If no more instances with missed deadline exist * in the list, the deadline (nn_mtime_t) for the first instance to 'expire' is returned. If the - * list is empty, NN_MTIME_NEVER is returned */ -nn_mtime_t deadline_next_missed_locked (struct deadline_adm *deadline_adm, nn_mtime_t tnow, void **instance) + * list is empty, DDSRT_MTIME_NEVER is returned */ +ddsrt_mtime_t deadline_next_missed_locked (struct deadline_adm *deadline_adm, ddsrt_mtime_t tnow, void **instance) { struct deadline_elem *elem = NULL; if (!ddsrt_circlist_isempty (&deadline_adm->list)) @@ -39,18 +39,18 @@ nn_mtime_t deadline_next_missed_locked (struct deadline_adm *deadline_adm, nn_mt ddsrt_circlist_remove (&deadline_adm->list, &elem->e); if (instance != NULL) *instance = (char *)elem - deadline_adm->elem_offset; - return (nn_mtime_t) { 0 }; + return (ddsrt_mtime_t) { 0 }; } } if (instance != NULL) *instance = NULL; - return (elem != NULL) ? elem->t_deadline : NN_MTIME_NEVER; + return (elem != NULL) ? elem->t_deadline : DDSRT_MTIME_NEVER; } void deadline_init (const struct ddsi_domaingv *gv, struct deadline_adm *deadline_adm, size_t list_offset, size_t elem_offset, deadline_missed_cb_t deadline_missed_cb) { ddsrt_circlist_init (&deadline_adm->list); - deadline_adm->evt = qxev_callback (gv->xevents, NN_MTIME_NEVER, instance_deadline_missed_cb, deadline_adm); + deadline_adm->evt = qxev_callback (gv->xevents, DDSRT_MTIME_NEVER, instance_deadline_missed_cb, deadline_adm); deadline_adm->deadline_missed_cb = deadline_missed_cb; deadline_adm->list_offset = list_offset; deadline_adm->elem_offset = elem_offset; @@ -63,7 +63,7 @@ void deadline_stop (const struct deadline_adm *deadline_adm) void deadline_clear (struct deadline_adm *deadline_adm) { - while ((deadline_next_missed_locked (deadline_adm, NN_MTIME_NEVER, NULL)).v == 0); + while ((deadline_next_missed_locked (deadline_adm, DDSRT_MTIME_NEVER, NULL)).v == 0); } void deadline_fini (const struct deadline_adm *deadline_adm) @@ -72,10 +72,10 @@ void deadline_fini (const struct deadline_adm *deadline_adm) (void) deadline_adm; } -extern inline void deadline_register_instance_locked (struct deadline_adm *deadline_adm, struct deadline_elem *elem, nn_mtime_t tnow); -extern inline void deadline_reregister_instance_locked (struct deadline_adm *deadline_adm, struct deadline_elem *elem, nn_mtime_t tnow); +extern inline void deadline_register_instance_locked (struct deadline_adm *deadline_adm, struct deadline_elem *elem, ddsrt_mtime_t tnow); +extern inline void deadline_reregister_instance_locked (struct deadline_adm *deadline_adm, struct deadline_elem *elem, ddsrt_mtime_t tnow); -void deadline_register_instance_real (struct deadline_adm *deadline_adm, struct deadline_elem *elem, nn_mtime_t tprev, nn_mtime_t tnow) +void deadline_register_instance_real (struct deadline_adm *deadline_adm, struct deadline_elem *elem, ddsrt_mtime_t tprev, ddsrt_mtime_t tnow) { ddsrt_circlist_append(&deadline_adm->list, &elem->e); elem->t_deadline = (tprev.v + deadline_adm->dur >= tnow.v) ? tprev : tnow; @@ -92,7 +92,7 @@ void deadline_unregister_instance_real (struct deadline_adm *deadline_adm, struc * this removed element expires. Only remove the element from the * deadline list */ - elem->t_deadline = NN_MTIME_NEVER; + elem->t_deadline = DDSRT_MTIME_NEVER; ddsrt_circlist_remove(&deadline_adm->list, &elem->e); } @@ -106,7 +106,7 @@ void deadline_renew_instance_real (struct deadline_adm *deadline_adm, struct dea the callback the deadline (which will be the updated value) will be checked for expiry */ ddsrt_circlist_remove(&deadline_adm->list, &elem->e); - elem->t_deadline = now_mt(); + elem->t_deadline = ddsrt_time_monotonic(); elem->t_deadline.v += deadline_adm->dur; ddsrt_circlist_append(&deadline_adm->list, &elem->e); } diff --git a/src/core/ddsi/src/ddsi_lifespan.c b/src/core/ddsi/src/ddsi_lifespan.c index 3ad8737..ddd0224 100644 --- a/src/core/ddsi/src/ddsi_lifespan.c +++ b/src/core/ddsi/src/ddsi_lifespan.c @@ -14,7 +14,6 @@ #include "dds/ddsrt/heap.h" #include "dds/ddsrt/fibheap.h" #include "dds/ddsi/ddsi_lifespan.h" -#include "dds/ddsi/q_time.h" #include "dds/ddsi/q_xevent.h" static int compare_lifespan_texp (const void *va, const void *vb) @@ -26,33 +25,33 @@ static int compare_lifespan_texp (const void *va, const void *vb) const ddsrt_fibheap_def_t lifespan_fhdef = DDSRT_FIBHEAPDEF_INITIALIZER(offsetof (struct lifespan_fhnode, heapnode), compare_lifespan_texp); -static void lifespan_rhc_node_exp (struct xevent *xev, void *varg, nn_mtime_t tnow) +static void lifespan_rhc_node_exp (struct xevent *xev, void *varg, ddsrt_mtime_t tnow) { struct lifespan_adm * const lifespan_adm = varg; - nn_mtime_t next_valid = lifespan_adm->sample_expired_cb((char *)lifespan_adm - lifespan_adm->fh_offset, tnow); + ddsrt_mtime_t next_valid = lifespan_adm->sample_expired_cb((char *)lifespan_adm - lifespan_adm->fh_offset, tnow); resched_xevent_if_earlier (xev, next_valid); } /* Gets the sample from the fibheap in lifespan admin that was expired first. If no more * expired samples exist in the fibheap, the expiry time (nn_mtime_t) for the next sample to - * expire is returned. If the fibheap contains no more samples, NN_MTIME_NEVER is returned */ -nn_mtime_t lifespan_next_expired_locked (const struct lifespan_adm *lifespan_adm, nn_mtime_t tnow, void **sample) + * expire is returned. If the fibheap contains no more samples, DDSRT_MTIME_NEVER is returned */ +ddsrt_mtime_t lifespan_next_expired_locked (const struct lifespan_adm *lifespan_adm, ddsrt_mtime_t tnow, void **sample) { struct lifespan_fhnode *node; if ((node = ddsrt_fibheap_min(&lifespan_fhdef, &lifespan_adm->ls_exp_heap)) != NULL && node->t_expire.v <= tnow.v) { *sample = (char *)node - lifespan_adm->fhn_offset; - return (nn_mtime_t) { 0 }; + return (ddsrt_mtime_t) { 0 }; } *sample = NULL; - return (node != NULL) ? node->t_expire : NN_MTIME_NEVER; + return (node != NULL) ? node->t_expire : DDSRT_MTIME_NEVER; } void lifespan_init (const struct ddsi_domaingv *gv, struct lifespan_adm *lifespan_adm, size_t fh_offset, size_t fh_node_offset, sample_expired_cb_t sample_expired_cb) { ddsrt_fibheap_init (&lifespan_fhdef, &lifespan_adm->ls_exp_heap); - lifespan_adm->evt = qxev_callback (gv->xevents, NN_MTIME_NEVER, lifespan_rhc_node_exp, lifespan_adm); + lifespan_adm->evt = qxev_callback (gv->xevents, DDSRT_MTIME_NEVER, lifespan_rhc_node_exp, lifespan_adm); lifespan_adm->sample_expired_cb = sample_expired_cb; lifespan_adm->fh_offset = fh_offset; lifespan_adm->fhn_offset = fh_node_offset; diff --git a/src/core/ddsi/src/ddsi_plist.c b/src/core/ddsi/src/ddsi_plist.c index 0707f2f..ffa7f44 100644 --- a/src/core/ddsi/src/ddsi_plist.c +++ b/src/core/ddsi/src/ddsi_plist.c @@ -25,7 +25,7 @@ #include "dds/ddsi/q_bswap.h" #include "dds/ddsi/q_unused.h" #include "dds/ddsi/ddsi_plist.h" -#include "dds/ddsi/q_time.h" +#include "dds/ddsi/ddsi_time.h" #include "dds/ddsi/q_xmsg.h" #include "dds/ddsi/ddsi_vendor.h" #include "dds/ddsi/ddsi_udp.h" /* nn_mc4gen_address_t */ @@ -215,7 +215,7 @@ static dds_return_t deser_reliability (void * __restrict dst, size_t * __restric if (validate_external_duration (&mbt) < 0) return DDS_RETCODE_BAD_PARAMETER; x->kind = (enum dds_reliability_kind) (kind - 1); - x->max_blocking_time = nn_from_ddsi_duration (mbt); + x->max_blocking_time = ddsi_from_ddsi_duration (mbt); *dstoff += sizeof (*x); *flagset->present |= flag; return 0; @@ -226,7 +226,7 @@ static dds_return_t ser_reliability (struct nn_xmsg *xmsg, nn_parameterid_t pid, DDSRT_STATIC_ASSERT (DDS_EXTERNAL_RELIABILITY_BEST_EFFORT == 1 && DDS_EXTERNAL_RELIABILITY_RELIABLE == 2 && DDS_RELIABILITY_BEST_EFFORT == 0 && DDS_RELIABILITY_RELIABLE == 1); dds_reliability_qospolicy_t const * const x = deser_generic_src (src, &srcoff, alignof (dds_reliability_qospolicy_t)); - ddsi_duration_t mbt = nn_to_ddsi_duration (x->max_blocking_time); + ddsi_duration_t mbt = ddsi_to_ddsi_duration (x->max_blocking_time); uint32_t * const p = nn_xmsg_addpar (xmsg, pid, 3 * sizeof (uint32_t)); p[0] = 1 + (uint32_t) x->kind; p[1] = (uint32_t) mbt.seconds; @@ -551,7 +551,7 @@ static dds_return_t deser_generic (void * __restrict dst, size_t * __restrict ds goto fail; if (validate_external_duration (&tmp)) goto fail; - x[i] = nn_from_ddsi_duration (tmp); + x[i] = ddsi_from_ddsi_duration (tmp); } *dstoff += cnt * sizeof (*x); break; @@ -796,7 +796,7 @@ static dds_return_t ser_generic_embeddable (char * const data, size_t *dstoff, c uint32_t * const p = ser_generic_align4 (data, dstoff); for (uint32_t i = 0; i < cnt; i++) { - ddsi_duration_t tmp = nn_to_ddsi_duration (x[i]); + ddsi_duration_t tmp = ddsi_to_ddsi_duration (x[i]); p[2 * i + 0] = (uint32_t) tmp.seconds; p[2 * i + 1] = tmp.fraction; } diff --git a/src/core/ddsi/src/ddsi_pmd.c b/src/core/ddsi/src/ddsi_pmd.c index 9a6df62..9e7db55 100644 --- a/src/core/ddsi/src/ddsi_pmd.c +++ b/src/core/ddsi/src/ddsi_pmd.c @@ -25,7 +25,6 @@ #include "dds/ddsi/q_protocol.h" #include "dds/ddsi/q_radmin.h" #include "dds/ddsi/q_rtps.h" -#include "dds/ddsi/q_time.h" #include "dds/ddsi/q_transmit.h" #include "dds/ddsi/q_xmsg.h" @@ -57,7 +56,7 @@ void write_pmd_message_guid (struct ddsi_domaingv * const gv, struct ddsi_guid * else { if ((lease = ddsrt_atomic_ldvoidp (&pp->minl_man)) != NULL) - lease_renew (lease, now_et()); + lease_renew (lease, ddsrt_time_elapsed()); write_pmd_message (ts1, NULL, pp, pmd_kind); } thread_state_asleep (ts1); @@ -93,7 +92,7 @@ void write_pmd_message (struct thread_state1 * const ts1, struct nn_xpack *xp, s .keysize = 16 }; serdata = ddsi_serdata_from_sample (gv->rawcdr_topic, SDK_DATA, &raw); - serdata->timestamp = now (); + serdata->timestamp = ddsrt_time_wallclock (); tk = ddsi_tkmap_lookup_instance_ref (gv->m_tkmap, serdata); write_sample_nogc (ts1, xp, wr, serdata, tk); @@ -101,7 +100,7 @@ void write_pmd_message (struct thread_state1 * const ts1, struct nn_xpack *xp, s #undef PMD_DATA_LENGTH } -void handle_pmd_message (const struct receiver_state *rst, nn_wctime_t timestamp, uint32_t statusinfo, const void *vdata, uint32_t len) +void handle_pmd_message (const struct receiver_state *rst, ddsrt_wctime_t timestamp, uint32_t statusinfo, const void *vdata, uint32_t len) { const struct CDRHeader *data = vdata; /* built-ins not deserialized (yet) */ const int bswap = (data->identifier == CDR_LE) ^ (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN); @@ -139,7 +138,7 @@ void handle_pmd_message (const struct receiver_state *rst, nn_wctime_t timestamp (l = ddsrt_atomic_ldvoidp (&proxypp->minl_man)) != NULL) { /* Renew lease for entity with shortest manual-by-participant lease */ - lease_renew (l, now_et ()); + lease_renew (l, ddsrt_time_elapsed ()); } } break; diff --git a/src/core/ddsi/src/ddsi_threadmon.c b/src/core/ddsi/src/ddsi_threadmon.c index 2d1a453..b92e2d1 100644 --- a/src/core/ddsi/src/ddsi_threadmon.c +++ b/src/core/ddsi/src/ddsi_threadmon.c @@ -13,6 +13,7 @@ #include "dds/ddsrt/heap.h" #include "dds/ddsrt/sync.h" +#include "dds/ddsrt/time.h" #include "dds/ddsrt/threads.h" #include "dds/ddsrt/hopscotch.h" @@ -20,7 +21,6 @@ #include "dds/ddsi/q_config.h" #include "dds/ddsi/q_log.h" #include "dds/ddsi/q_thread.h" -#include "dds/ddsi/q_time.h" #include "dds/ddsi/q_unused.h" #include "dds/ddsi/ddsi_domaingv.h" /* for mattr, cattr */ #include "dds/ddsi/q_receive.h" @@ -64,7 +64,7 @@ static uint32_t threadmon_thread (struct ddsi_threadmon *sl) reason why it has to be 100ms), regardless of the lease settings. Note: can't trust sl->self, may have been scheduled before the assignment. */ - nn_mtime_t tlast = { 0 }; + ddsrt_mtime_t tlast = { 0 }; bool was_alive = true; for (uint32_t i = 0; i < thread_states.nthreads; i++) { @@ -80,7 +80,7 @@ static uint32_t threadmon_thread (struct ddsi_threadmon *sl) /* Check progress only if enough time has passed: there is no guarantee that os_cond_timedwait wont ever return early, and we do want to avoid spurious warnings. */ - nn_mtime_t tnow = now_mt (); + ddsrt_mtime_t tnow = ddsrt_time_monotonic (); if (tnow.v < tlast.v) continue; diff --git a/src/core/ddsi/src/ddsi_time.c b/src/core/ddsi/src/ddsi_time.c new file mode 100644 index 0000000..d387034 --- /dev/null +++ b/src/core/ddsi/src/ddsi_time.c @@ -0,0 +1,70 @@ +/* + * 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 + +#include "dds/ddsrt/time.h" +#include "dds/ddsi/ddsi_time.h" + +bool ddsi_is_valid_timestamp (ddsi_time_t t) +{ + return t.seconds != DDSI_TIME_INVALID.seconds && t.fraction != DDSI_TIME_INVALID.fraction; +} + +static ddsi_time_t to_ddsi_time (int64_t t) +{ + if (t == DDS_NEVER) + return DDSI_TIME_INFINITE; + else + { + /* ceiling(ns * 2^32/10^9) -- can't change the ceiling to round-to-nearest + because that would break backwards compatibility, but round-to-nearest + of the inverse is correctly rounded anyway, so it shouldn't ever matter. */ + ddsi_time_t x; + int ns = (int) (t % DDS_NSECS_IN_SEC); + x.seconds = (int) (t / DDS_NSECS_IN_SEC); + x.fraction = (unsigned) (((DDS_NSECS_IN_SEC-1) + ((int64_t) ns << 32)) / DDS_NSECS_IN_SEC); + return x; + } +} + +ddsi_time_t ddsi_wctime_to_ddsi_time (ddsrt_wctime_t t) +{ + return to_ddsi_time (t.v); +} + +static int64_t from_ddsi_time (ddsi_time_t x) +{ + if (x.seconds == DDSI_TIME_INFINITE.seconds && x.fraction == DDSI_TIME_INFINITE.fraction) + return DDS_NEVER; + else + { + /* Round-to-nearest conversion of DDSI time fraction to nanoseconds */ + int ns = (int) (((int64_t) 2147483648u + (int64_t) x.fraction * DDS_NSECS_IN_SEC) >> 32); + return x.seconds * DDS_NSECS_IN_SEC + ns; + } +} + +ddsrt_wctime_t ddsi_wctime_from_ddsi_time (ddsi_time_t x) +{ + return (ddsrt_wctime_t) { from_ddsi_time (x) }; +} + +ddsi_duration_t ddsi_to_ddsi_duration (dds_duration_t x) +{ + return to_ddsi_time (x); +} + +dds_duration_t ddsi_from_ddsi_duration (ddsi_duration_t x) +{ + return from_ddsi_time (x); +} + diff --git a/src/core/ddsi/src/ddsi_udp.c b/src/core/ddsi/src/ddsi_udp.c index ede09e7..d30d319 100644 --- a/src/core/ddsi/src/ddsi_udp.c +++ b/src/core/ddsi/src/ddsi_udp.c @@ -76,7 +76,7 @@ static ssize_t ddsi_udp_conn_read (ddsi_tran_conn_t conn, unsigned char * buf, s socklen_t dest_len = sizeof (dest); if (ddsrt_getsockname (((ddsi_udp_conn_t) conn)->m_sock, (struct sockaddr *) &dest, &dest_len) != DDS_RETCODE_OK) memset(&dest, 0, sizeof(dest)); - write_pcap_received(conn->m_base.gv, now(), &src, &dest, buf, (size_t) ret); + write_pcap_received(conn->m_base.gv, ddsrt_time_wallclock(), &src, &dest, buf, (size_t) ret); } /* Check for udp packet truncation */ @@ -155,7 +155,7 @@ static ssize_t ddsi_udp_conn_write (ddsi_tran_conn_t conn, const nn_locator_t *d socklen_t alen = sizeof (sa); if (ddsrt_getsockname (((ddsi_udp_conn_t) conn)->m_sock, (struct sockaddr *) &sa, &alen) != DDS_RETCODE_OK) memset(&sa, 0, sizeof(sa)); - write_pcap_sent (conn->m_base.gv, now (), &sa, &msg, (size_t) ret); + write_pcap_sent (conn->m_base.gv, ddsrt_time_wallclock (), &sa, &msg, (size_t) ret); } else if (rc != DDS_RETCODE_OK && rc != DDS_RETCODE_NOT_ALLOWED && diff --git a/src/core/ddsi/src/q_ddsi_discovery.c b/src/core/ddsi/src/q_ddsi_discovery.c index f758125..8c6f331 100644 --- a/src/core/ddsi/src/q_ddsi_discovery.c +++ b/src/core/ddsi/src/q_ddsi_discovery.c @@ -179,7 +179,7 @@ static int write_mpayload (struct writer *wr, int alive, nn_parameterid_t keypar nn_xmsg_payload_to_plistsample (&plist_sample, keyparam, mpayload); serdata = ddsi_serdata_from_sample (wr->e.gv->plist_topic, alive ? SDK_DATA : SDK_KEY, &plist_sample); serdata->statusinfo = alive ? 0 : NN_STATUSINFO_DISPOSE | NN_STATUSINFO_UNREGISTER; - serdata->timestamp = now (); + serdata->timestamp = ddsrt_time_wallclock (); return write_sample_nogc_notk (ts1, NULL, wr, serdata); } @@ -362,7 +362,7 @@ int spdp_dispose_unregister (struct participant *pp) return ret; } -static unsigned pseudo_random_delay (const ddsi_guid_t *x, const ddsi_guid_t *y, nn_mtime_t tnow) +static unsigned pseudo_random_delay (const ddsi_guid_t *x, const ddsi_guid_t *y, ddsrt_mtime_t tnow) { /* You know, an ordinary random generator would be even better, but the C library doesn't have a reentrant one and I don't feel like @@ -395,7 +395,7 @@ static void respond_to_spdp (const struct ddsi_domaingv *gv, const ddsi_guid_t * { struct entidx_enum_participant est; struct participant *pp; - nn_mtime_t tnow = now_mt (); + ddsrt_mtime_t tnow = ddsrt_time_monotonic (); entidx_enum_participant_init (&est, gv->entity_index); while ((pp = entidx_enum_participant_next (&est)) != NULL) { @@ -405,7 +405,7 @@ static void respond_to_spdp (const struct ddsi_domaingv *gv, const ddsi_guid_t * unsigned delay_norm = delay_base >> 2; int64_t delay_max_ms = gv->config.spdp_response_delay_max / 1000000; int64_t delay = (int64_t) delay_norm * delay_max_ms / 1000; - nn_mtime_t tsched = add_duration_to_mtime (tnow, delay); + ddsrt_mtime_t tsched = ddsrt_mtime_add_duration (tnow, delay); GVTRACE (" %"PRId64, delay); if (!pp->e.gv->config.unicast_response_to_spdp_messages) /* pp can't reach gc_delete_participant => can safely reschedule */ @@ -416,7 +416,7 @@ static void respond_to_spdp (const struct ddsi_domaingv *gv, const ddsi_guid_t * entidx_enum_participant_fini (&est); } -static int handle_SPDP_dead (const struct receiver_state *rst, nn_wctime_t timestamp, const ddsi_plist_t *datap, unsigned statusinfo) +static int handle_SPDP_dead (const struct receiver_state *rst, ddsrt_wctime_t timestamp, const ddsi_plist_t *datap, unsigned statusinfo) { struct ddsi_domaingv * const gv = rst->gv; ddsi_guid_t guid; @@ -478,7 +478,7 @@ static struct proxy_participant *find_ddsi2_proxy_participant (const struct enti return pp; } -static void make_participants_dependent_on_ddsi2 (struct ddsi_domaingv *gv, const ddsi_guid_t *ddsi2guid, nn_wctime_t timestamp) +static void make_participants_dependent_on_ddsi2 (struct ddsi_domaingv *gv, const ddsi_guid_t *ddsi2guid, ddsrt_wctime_t timestamp) { struct entidx_enum_proxy_participant it; struct proxy_participant *pp, *d2pp; @@ -514,7 +514,7 @@ static void make_participants_dependent_on_ddsi2 (struct ddsi_domaingv *gv, cons } } -static int handle_SPDP_alive (const struct receiver_state *rst, seqno_t seq, nn_wctime_t timestamp, const ddsi_plist_t *datap) +static int handle_SPDP_alive (const struct receiver_state *rst, seqno_t seq, ddsrt_wctime_t timestamp, const ddsi_plist_t *datap) { struct ddsi_domaingv * const gv = rst->gv; const unsigned bes_sedp_announcer_mask = @@ -596,7 +596,7 @@ static int handle_SPDP_alive (const struct receiver_state *rst, seqno_t seq, nn_ that are not alive are not set alive here. This is done only when data is received from a particular pwr (in handle_regular) */ if ((lease = ddsrt_atomic_ldvoidp (&proxypp->minl_auto)) != NULL) - lease_renew (lease, now_et ()); + lease_renew (lease, ddsrt_time_elapsed ()); ddsrt_mutex_lock (&proxypp->e.lock); if (proxypp->implicitly_created || seq > proxypp->seq) { @@ -797,7 +797,7 @@ static int handle_SPDP_alive (const struct receiver_state *rst, seqno_t seq, nn_ return 1; } -static void handle_SPDP (const struct receiver_state *rst, seqno_t seq, nn_wctime_t timestamp, unsigned statusinfo, const void *vdata, uint32_t len) +static void handle_SPDP (const struct receiver_state *rst, seqno_t seq, ddsrt_wctime_t timestamp, unsigned statusinfo, const void *vdata, uint32_t len) { struct ddsi_domaingv * const gv = rst->gv; const struct CDRHeader *data = vdata; /* built-ins not deserialized (yet) */ @@ -1049,7 +1049,7 @@ static const char *durability_to_string (dds_durability_kind_t k) return "undefined-durability"; } -static struct proxy_participant *implicitly_create_proxypp (struct ddsi_domaingv *gv, const ddsi_guid_t *ppguid, ddsi_plist_t *datap /* note: potentially modifies datap */, const ddsi_guid_prefix_t *src_guid_prefix, nn_vendorid_t vendorid, nn_wctime_t timestamp, seqno_t seq) +static struct proxy_participant *implicitly_create_proxypp (struct ddsi_domaingv *gv, const ddsi_guid_t *ppguid, ddsi_plist_t *datap /* note: potentially modifies datap */, const ddsi_guid_prefix_t *src_guid_prefix, nn_vendorid_t vendorid, ddsrt_wctime_t timestamp, seqno_t seq) { ddsi_guid_t privguid; ddsi_plist_t pp_plist; @@ -1129,7 +1129,7 @@ static struct proxy_participant *implicitly_create_proxypp (struct ddsi_domaingv return entidx_lookup_proxy_participant_guid (gv->entity_index, ppguid); } -static void handle_SEDP_alive (const struct receiver_state *rst, seqno_t seq, ddsi_plist_t *datap /* note: potentially modifies datap */, const ddsi_guid_prefix_t *src_guid_prefix, nn_vendorid_t vendorid, nn_wctime_t timestamp) +static void handle_SEDP_alive (const struct receiver_state *rst, seqno_t seq, ddsi_plist_t *datap /* note: potentially modifies datap */, const ddsi_guid_prefix_t *src_guid_prefix, nn_vendorid_t vendorid, ddsrt_wctime_t timestamp) { #define E(msg, lbl) do { GVLOGDISC (msg); goto lbl; } while (0) struct ddsi_domaingv * const gv = rst->gv; @@ -1225,7 +1225,7 @@ static void handle_SEDP_alive (const struct receiver_state *rst, seqno_t seq, dd GVLOGDISC (" "PGUIDFMT" attach-to-DS "PGUIDFMT, PGUID(pp->e.guid), PGUIDPREFIX(*src_guid_prefix), pp->privileged_pp_guid.entityid.u); ddsrt_mutex_lock (&pp->e.lock); pp->privileged_pp_guid.prefix = *src_guid_prefix; - lease_set_expiry(pp->lease, NN_ETIME_NEVER); + lease_set_expiry(pp->lease, DDSRT_ETIME_NEVER); ddsrt_mutex_unlock (&pp->e.lock); } GVLOGDISC ("\n"); @@ -1324,7 +1324,7 @@ err: #undef E } -static void handle_SEDP_dead (const struct receiver_state *rst, ddsi_plist_t *datap, nn_wctime_t timestamp) +static void handle_SEDP_dead (const struct receiver_state *rst, ddsi_plist_t *datap, ddsrt_wctime_t timestamp) { struct ddsi_domaingv * const gv = rst->gv; int res; @@ -1341,7 +1341,7 @@ static void handle_SEDP_dead (const struct receiver_state *rst, ddsi_plist_t *da GVLOGDISC (" %s\n", (res < 0) ? " unknown" : " delete"); } -static void handle_SEDP (const struct receiver_state *rst, seqno_t seq, nn_wctime_t timestamp, unsigned statusinfo, const void *vdata, uint32_t len) +static void handle_SEDP (const struct receiver_state *rst, seqno_t seq, ddsrt_wctime_t timestamp, unsigned statusinfo, const void *vdata, uint32_t len) { struct ddsi_domaingv * const gv = rst->gv; const struct CDRHeader *data = vdata; /* built-ins not deserialized (yet) */ @@ -1477,7 +1477,7 @@ int builtins_dqueue_handler (const struct nn_rsample_info *sampleinfo, const str unsigned char *datap; int needs_free; uint32_t datasz = sampleinfo->size; - nn_wctime_t timestamp; + ddsrt_wctime_t timestamp; needs_free = defragment (&datap, fragchain, sampleinfo->size); @@ -1625,10 +1625,10 @@ int builtins_dqueue_handler (const struct nn_rsample_info *sampleinfo, const str goto done_upd_deliv; } - if (sampleinfo->timestamp.v != NN_WCTIME_INVALID.v) + if (sampleinfo->timestamp.v != DDSRT_WCTIME_INVALID.v) timestamp = sampleinfo->timestamp; else - timestamp = now (); + timestamp = ddsrt_time_wallclock (); switch (srcguid.entityid.u) { case NN_ENTITYID_SPDP_BUILTIN_PARTICIPANT_WRITER: diff --git a/src/core/ddsi/src/q_debmon.c b/src/core/ddsi/src/q_debmon.c index fbf33a0..68f72af 100644 --- a/src/core/ddsi/src/q_debmon.c +++ b/src/core/ddsi/src/q_debmon.c @@ -22,7 +22,6 @@ #include "dds/ddsi/q_entity.h" #include "dds/ddsi/q_config.h" -#include "dds/ddsi/q_time.h" #include "dds/ddsi/q_misc.h" #include "dds/ddsi/q_log.h" #include "dds/ddsi/ddsi_plist.h" diff --git a/src/core/ddsi/src/q_entity.c b/src/core/ddsi/src/q_entity.c index 6a34aaf..3cb3ee7 100644 --- a/src/core/ddsi/src/q_entity.c +++ b/src/core/ddsi/src/q_entity.c @@ -23,7 +23,6 @@ #include "dds/ddsi/q_entity.h" #include "dds/ddsi/q_config.h" -#include "dds/ddsi/q_time.h" #include "dds/ddsi/q_misc.h" #include "dds/ddsi/q_log.h" #include "dds/ddsrt/avl.h" @@ -54,7 +53,7 @@ struct deleted_participant { ddsrt_avl_node_t avlnode; ddsi_guid_t guid; unsigned for_what; - nn_mtime_t t_prune; + ddsrt_mtime_t t_prune; }; struct deleted_participants_admin { @@ -110,7 +109,7 @@ static int gcreq_proxy_reader (struct proxy_reader *prd); extern inline bool builtintopic_is_visible (const struct ddsi_builtin_topic_interface *btif, const struct ddsi_guid *guid, nn_vendorid_t vendorid); extern inline bool builtintopic_is_builtintopic (const struct ddsi_builtin_topic_interface *btif, const struct ddsi_sertopic *topic); extern inline struct ddsi_tkmap_instance *builtintopic_get_tkmap_entry (const struct ddsi_builtin_topic_interface *btif, const struct ddsi_guid *guid); -extern inline void builtintopic_write (const struct ddsi_builtin_topic_interface *btif, const struct entity_common *e, nn_wctime_t timestamp, bool alive); +extern inline void builtintopic_write (const struct ddsi_builtin_topic_interface *btif, const struct entity_common *e, ddsrt_wctime_t timestamp, bool alive); extern inline seqno_t writer_read_seq_xmit (const struct writer *wr); extern inline void writer_update_seq_xmit (struct writer *wr, seqno_t nv); @@ -209,7 +208,7 @@ const ddsrt_fibheap_def_t ldur_fhdef = DDSRT_FIBHEAPDEF_INITIALIZER(offsetof (st /* used in (proxy)participant for writer liveliness monitoring */ const ddsrt_fibheap_def_t lease_fhdef_pp = DDSRT_FIBHEAPDEF_INITIALIZER(offsetof (struct lease, pp_heapnode), compare_lease_tdur); -static void entity_common_init (struct entity_common *e, struct ddsi_domaingv *gv, const struct ddsi_guid *guid, const char *name, enum entity_kind kind, nn_wctime_t tcreate, nn_vendorid_t vendorid, bool onlylocal) +static void entity_common_init (struct entity_common *e, struct ddsi_domaingv *gv, const struct ddsi_guid *guid, const char *name, enum entity_kind kind, ddsrt_wctime_t tcreate, nn_vendorid_t vendorid, bool onlylocal) { e->guid = *guid; e->kind = kind; @@ -355,9 +354,9 @@ void ddsi_make_writer_info(struct ddsi_writer_info *wrinfo, const struct entity_ wrinfo->iid = e->iid; #ifdef DDSI_INCLUDE_LIFESPAN if (xqos->lifespan.duration != DDS_INFINITY && (statusinfo & (NN_STATUSINFO_UNREGISTER | NN_STATUSINFO_DISPOSE)) == 0) - wrinfo->lifespan_exp = add_duration_to_mtime(now_mt(), xqos->lifespan.duration); + wrinfo->lifespan_exp = ddsrt_mtime_add_duration(ddsrt_time_monotonic(), xqos->lifespan.duration); else - wrinfo->lifespan_exp = NN_MTIME_NEVER; + wrinfo->lifespan_exp = DDSRT_MTIME_NEVER; #endif } @@ -380,7 +379,7 @@ void deleted_participants_admin_free (struct deleted_participants_admin *admin) ddsrt_free (admin); } -static void prune_deleted_participant_guids_unlocked (struct deleted_participants_admin *admin, nn_mtime_t tnow) +static void prune_deleted_participant_guids_unlocked (struct deleted_participants_admin *admin, ddsrt_mtime_t tnow) { /* Could do a better job of finding prunable ones efficiently under all circumstances, but I expect the tree to be very small at all @@ -400,7 +399,7 @@ static void prune_deleted_participant_guids_unlocked (struct deleted_participant } } -static void prune_deleted_participant_guids (struct deleted_participants_admin *admin, nn_mtime_t tnow) +static void prune_deleted_participant_guids (struct deleted_participants_admin *admin, ddsrt_mtime_t tnow) { ddsrt_mutex_lock (&admin->deleted_participants_lock); prune_deleted_participant_guids_unlocked (admin, tnow); @@ -417,7 +416,7 @@ static void remember_deleted_participant_guid (struct deleted_participants_admin if ((n = ddsrt_malloc (sizeof (*n))) != NULL) { n->guid = *guid; - n->t_prune = NN_MTIME_NEVER; + n->t_prune = DDSRT_MTIME_NEVER; n->for_what = DPG_LOCAL | DPG_REMOTE; ddsrt_avl_insert_ipath (&deleted_participants_treedef, &admin->deleted_participants, n, &path); } @@ -430,7 +429,7 @@ int is_deleted_participant_guid (struct deleted_participants_admin *admin, const struct deleted_participant *n; int known; ddsrt_mutex_lock (&admin->deleted_participants_lock); - prune_deleted_participant_guids_unlocked (admin, now_mt ()); + prune_deleted_participant_guids_unlocked (admin, ddsrt_time_monotonic ()); if ((n = ddsrt_avl_lookup (&deleted_participants_treedef, &admin->deleted_participants, guid)) == NULL) known = 0; else @@ -445,12 +444,12 @@ static void remove_deleted_participant_guid (struct deleted_participants_admin * DDS_CLOG (DDS_LC_DISCOVERY, admin->logcfg, "remove_deleted_participant_guid("PGUIDFMT" for_what=%x)\n", PGUID (*guid), for_what); ddsrt_mutex_lock (&admin->deleted_participants_lock); if ((n = ddsrt_avl_lookup (&deleted_participants_treedef, &admin->deleted_participants, guid)) != NULL) - n->t_prune = add_duration_to_mtime (now_mt (), admin->delay); + n->t_prune = ddsrt_mtime_add_duration (ddsrt_time_monotonic (), admin->delay); ddsrt_mutex_unlock (&admin->deleted_participants_lock); } /* PARTICIPANT ------------------------------------------------------ */ -static bool update_qos_locked (struct entity_common *e, dds_qos_t *ent_qos, const dds_qos_t *xqos, nn_wctime_t timestamp) +static bool update_qos_locked (struct entity_common *e, dds_qos_t *ent_qos, const dds_qos_t *xqos, ddsrt_wctime_t timestamp) { uint64_t mask; @@ -541,7 +540,7 @@ static void participant_add_wr_lease_locked (struct participant * pp, const stru /* if inserted lease is new shortest lease */ if (minl_prev != minl_new) { - nn_etime_t texp = add_duration_to_etime (now_et (), minl_new->tdur); + ddsrt_etime_t texp = ddsrt_etime_add_duration (ddsrt_time_elapsed (), minl_new->tdur); struct lease *lnew = lease_new (texp, minl_new->tdur, minl_new->entity); if (minl_prev == NULL) { @@ -571,7 +570,7 @@ static void participant_remove_wr_lease_locked (struct participant * pp, struct { dds_duration_t trem = minl->tdur - wr->lease->tdur; assert (trem >= 0); - nn_etime_t texp = add_duration_to_etime (now_et(), trem); + ddsrt_etime_t texp = ddsrt_etime_add_duration (ddsrt_time_elapsed(), trem); struct lease *lnew = lease_new (texp, minl->tdur, minl->entity); participant_replace_minl (pp, lnew); lease_register (lnew); @@ -594,7 +593,7 @@ dds_return_t new_participant_guid (const ddsi_guid_t *ppguid, struct ddsi_domain /* privileged participant MUST have builtin readers and writers */ assert (!(flags & RTPS_PF_PRIVILEGED_PP) || (flags & (RTPS_PF_NO_BUILTIN_READERS | RTPS_PF_NO_BUILTIN_WRITERS)) == 0); - prune_deleted_participant_guids (gv->deleted_participants, now_mt ()); + prune_deleted_participant_guids (gv->deleted_participants, ddsrt_time_monotonic ()); /* FIXME: FULL LOCKING AROUND NEW_XXX FUNCTIONS, JUST SO EXISTENCE TESTS ARE PRECISE */ @@ -630,7 +629,7 @@ dds_return_t new_participant_guid (const ddsi_guid_t *ppguid, struct ddsi_domain pp = ddsrt_malloc (sizeof (*pp)); - entity_common_init (&pp->e, gv, ppguid, "", EK_PARTICIPANT, now (), NN_VENDORID_ECLIPSE, ((flags & RTPS_PF_ONLY_LOCAL) != 0)); + entity_common_init (&pp->e, gv, ppguid, "", EK_PARTICIPANT, ddsrt_time_wallclock (), NN_VENDORID_ECLIPSE, ((flags & RTPS_PF_ONLY_LOCAL) != 0)); pp->user_refc = 1; pp->builtin_refc = 0; pp->builtins_deleted = 0; @@ -790,7 +789,7 @@ dds_return_t new_participant_guid (const ddsi_guid_t *ppguid, struct ddsi_domain trigger_recv_threads (gv); } - builtintopic_write (gv->builtin_topic_interface, &pp->e, now(), true); + builtintopic_write (gv->builtin_topic_interface, &pp->e, ddsrt_time_wallclock(), true); /* SPDP periodic broadcast uses the retransmit path, so the initial publication must be done differently. Must be later than making @@ -806,12 +805,12 @@ dds_return_t new_participant_guid (const ddsi_guid_t *ppguid, struct ddsi_domain fire before the calls return. If the initial sample wasn't accepted, all is lost, but we continue nonetheless, even though the participant won't be able to discover or be discovered. */ - pp->spdp_xevent = qxev_spdp (gv->xevents, add_duration_to_mtime (now_mt (), DDS_MSECS (100)), &pp->e.guid, NULL); + pp->spdp_xevent = qxev_spdp (gv->xevents, ddsrt_mtime_add_duration (ddsrt_time_monotonic (), DDS_MSECS (100)), &pp->e.guid, NULL); } { - nn_mtime_t tsched; - tsched = (pp->lease_duration == DDS_INFINITY) ? NN_MTIME_NEVER : (nn_mtime_t){0}; + ddsrt_mtime_t tsched; + tsched = (pp->lease_duration == DDS_INFINITY) ? DDSRT_MTIME_NEVER : (ddsrt_mtime_t){0}; pp->pmd_update_xevent = qxev_pmd_update (gv->xevents, tsched, &pp->e.guid); } return 0; @@ -833,7 +832,7 @@ dds_return_t new_participant (ddsi_guid_t *p_ppguid, struct ddsi_domaingv *gv, u void update_participant_plist (struct participant *pp, const ddsi_plist_t *plist) { ddsrt_mutex_lock (&pp->e.lock); - if (update_qos_locked (&pp->e, &pp->plist->qos, &plist->qos, now ())) + if (update_qos_locked (&pp->e, &pp->plist->qos, &plist->qos, ddsrt_time_wallclock ())) spdp_write (pp); ddsrt_mutex_unlock (&pp->e.lock); } @@ -1016,7 +1015,7 @@ dds_return_t delete_participant (struct ddsi_domaingv *gv, const struct ddsi_gui GVLOGDISC ("delete_participant("PGUIDFMT")\n", PGUID (*ppguid)); if ((pp = entidx_lookup_participant_guid (gv->entity_index, ppguid)) == NULL) return DDS_RETCODE_BAD_PARAMETER; - builtintopic_write (gv->builtin_topic_interface, &pp->e, now(), false); + builtintopic_write (gv->builtin_topic_interface, &pp->e, ddsrt_time_wallclock(), false); remember_deleted_participant_guid (gv->deleted_participants, &pp->e.guid); entidx_remove_participant_guid (gv->entity_index, pp); gcreq_participant (pp); @@ -1864,7 +1863,7 @@ static void writer_add_connection (struct writer *wr, struct proxy_reader *prd) m->next_acknack = DDSI_COUNT_MIN; m->next_nackfrag = DDSI_COUNT_MIN; nn_lat_estim_init (&m->hb_to_ack_latency); - m->hb_to_ack_latency_tlastlog = now (); + m->hb_to_ack_latency_tlastlog = ddsrt_time_wallclock (); m->t_acknack_accepted.v = 0; ddsrt_mutex_lock (&wr->e.lock); @@ -1909,7 +1908,7 @@ static void writer_add_connection (struct writer *wr, struct proxy_reader *prd) if (wr->heartbeat_xevent) { const int64_t delta = DDS_MSECS (1); - const nn_mtime_t tnext = add_duration_to_mtime (now_mt (), delta); + const ddsrt_mtime_t tnext = ddsrt_mtime_add_duration (ddsrt_time_monotonic (), delta); ddsrt_mutex_lock (&wr->e.lock); /* To make sure that we keep sending heartbeats at a higher rate at the start of this discovery, reset the hbs_since_last_write @@ -2097,7 +2096,7 @@ static void reader_add_local_connection (struct reader *rd, struct writer *wr, c } } -static void proxy_writer_add_connection (struct proxy_writer *pwr, struct reader *rd, nn_mtime_t tnow, nn_count_t init_count) +static void proxy_writer_add_connection (struct proxy_writer *pwr, struct reader *rd, ddsrt_mtime_t tnow, nn_count_t init_count) { struct pwr_rd_match *m = ddsrt_malloc (sizeof (*m)); ddsrt_avl_ipath_t path; @@ -2116,7 +2115,7 @@ static void proxy_writer_add_connection (struct proxy_writer *pwr, struct reader ELOGDISC (pwr, " proxy_writer_add_connection(pwr "PGUIDFMT" rd "PGUIDFMT")", PGUID (pwr->e.guid), PGUID (rd->e.guid)); m->rd_guid = rd->e.guid; - m->tcreate = now_mt (); + m->tcreate = ddsrt_time_monotonic (); /* We track the last heartbeat count value per reader--proxy-writer pair, so that we can correctly handle directed heartbeats. The @@ -2191,7 +2190,7 @@ static void proxy_writer_add_connection (struct proxy_writer *pwr, struct reader hopefully it won't make that much of a difference in practice.) */ if (rd->reliable) { - m->acknack_xevent = qxev_acknack (pwr->evq, add_duration_to_mtime (tnow, pwr->e.gv->config.preemptive_ack_delay), &pwr->e.guid, &rd->e.guid); + m->acknack_xevent = qxev_acknack (pwr->evq, ddsrt_mtime_add_duration (tnow, pwr->e.gv->config.preemptive_ack_delay), &pwr->e.guid, &rd->e.guid); m->u.not_in_sync.reorder = nn_reorder_new (&pwr->e.gv->logconfig, NN_REORDER_MODE_NORMAL, pwr->e.gv->config.secondary_reorder_maxsamples, pwr->e.gv->config.late_ack_mode); pwr->n_reliable_readers++; @@ -2336,7 +2335,7 @@ static bool topickind_qos_match_p_lock (struct entity_common *rd, const dds_qos_ return ret; } -static void connect_writer_with_proxy_reader (struct writer *wr, struct proxy_reader *prd, nn_mtime_t tnow) +static void connect_writer_with_proxy_reader (struct writer *wr, struct proxy_reader *prd, ddsrt_mtime_t tnow) { const int isb0 = (is_builtin_entityid (wr->e.guid.entityid, NN_VENDORID_ECLIPSE) != 0); const int isb1 = (is_builtin_entityid (prd->e.guid.entityid, prd->c.vendor) != 0); @@ -2355,7 +2354,7 @@ static void connect_writer_with_proxy_reader (struct writer *wr, struct proxy_re writer_add_connection (wr, prd); } -static void connect_proxy_writer_with_reader (struct proxy_writer *pwr, struct reader *rd, nn_mtime_t tnow) +static void connect_proxy_writer_with_reader (struct proxy_writer *pwr, struct reader *rd, ddsrt_mtime_t tnow) { const int isb0 = (is_builtin_entityid (pwr->e.guid.entityid, pwr->c.vendor) != 0); const int isb1 = (is_builtin_entityid (rd->e.guid.entityid, NN_VENDORID_ECLIPSE) != 0); @@ -2410,7 +2409,7 @@ static bool ignore_local_p (const ddsi_guid_t *guid1, const ddsi_guid_t *guid2, return false; } -static void connect_writer_with_reader (struct writer *wr, struct reader *rd, nn_mtime_t tnow) +static void connect_writer_with_reader (struct writer *wr, struct reader *rd, ddsrt_mtime_t tnow) { dds_qos_policy_id_t reason; struct alive_state alive_state; @@ -2438,7 +2437,7 @@ static void connect_writer_with_reader (struct writer *wr, struct reader *rd, nn reader_update_notify_wr_alive_state (rd, wr, &alive_state); } -static void connect_writer_with_proxy_reader_wrapper (struct entity_common *vwr, struct entity_common *vprd, nn_mtime_t tnow) +static void connect_writer_with_proxy_reader_wrapper (struct entity_common *vwr, struct entity_common *vprd, ddsrt_mtime_t tnow) { struct writer *wr = (struct writer *) vwr; struct proxy_reader *prd = (struct proxy_reader *) vprd; @@ -2448,7 +2447,7 @@ static void connect_writer_with_proxy_reader_wrapper (struct entity_common *vwr, connect_writer_with_proxy_reader (wr, prd, tnow); } -static void connect_proxy_writer_with_reader_wrapper (struct entity_common *vpwr, struct entity_common *vrd, nn_mtime_t tnow) +static void connect_proxy_writer_with_reader_wrapper (struct entity_common *vpwr, struct entity_common *vrd, ddsrt_mtime_t tnow) { struct proxy_writer *pwr = (struct proxy_writer *) vpwr; struct reader *rd = (struct reader *) vrd; @@ -2458,7 +2457,7 @@ static void connect_proxy_writer_with_reader_wrapper (struct entity_common *vpwr connect_proxy_writer_with_reader (pwr, rd, tnow); } -static void connect_writer_with_reader_wrapper (struct entity_common *vwr, struct entity_common *vrd, nn_mtime_t tnow) +static void connect_writer_with_reader_wrapper (struct entity_common *vwr, struct entity_common *vrd, ddsrt_mtime_t tnow) { struct writer *wr = (struct writer *) vwr; struct reader *rd = (struct reader *) vrd; @@ -2486,7 +2485,7 @@ static enum entity_kind generic_do_match_mkind (enum entity_kind kind, bool loca return EK_WRITER; } -static void generic_do_match_connect (struct entity_common *e, struct entity_common *em, nn_mtime_t tnow, bool local) +static void generic_do_match_connect (struct entity_common *e, struct entity_common *em, ddsrt_mtime_t tnow, bool local) { switch (e->kind) { @@ -2534,7 +2533,7 @@ static const char *entity_topic_name (const struct entity_common *e) return ""; } -static void generic_do_match (struct entity_common *e, nn_mtime_t tnow, bool local) +static void generic_do_match (struct entity_common *e, ddsrt_mtime_t tnow, bool local) { static const struct { const char *full; const char *full_us; const char *abbrev; } kindstr[] = { [EK_WRITER] = { "writer", "writer", "wr" }, @@ -2600,32 +2599,32 @@ static void generic_do_match (struct entity_common *e, nn_mtime_t tnow, bool loc } } -static void match_writer_with_proxy_readers (struct writer *wr, nn_mtime_t tnow) +static void match_writer_with_proxy_readers (struct writer *wr, ddsrt_mtime_t tnow) { generic_do_match (&wr->e, tnow, false); } -static void match_writer_with_local_readers (struct writer *wr, nn_mtime_t tnow) +static void match_writer_with_local_readers (struct writer *wr, ddsrt_mtime_t tnow) { generic_do_match (&wr->e, tnow, true); } -static void match_reader_with_proxy_writers (struct reader *rd, nn_mtime_t tnow) +static void match_reader_with_proxy_writers (struct reader *rd, ddsrt_mtime_t tnow) { generic_do_match (&rd->e, tnow, false); } -static void match_reader_with_local_writers (struct reader *rd, nn_mtime_t tnow) +static void match_reader_with_local_writers (struct reader *rd, ddsrt_mtime_t tnow) { generic_do_match (&rd->e, tnow, true); } -static void match_proxy_writer_with_readers (struct proxy_writer *pwr, nn_mtime_t tnow) +static void match_proxy_writer_with_readers (struct proxy_writer *pwr, ddsrt_mtime_t tnow) { generic_do_match (&pwr->e, tnow, false); } -static void match_proxy_reader_with_writers (struct proxy_reader *prd, nn_mtime_t tnow) +static void match_proxy_reader_with_writers (struct proxy_reader *prd, ddsrt_mtime_t tnow) { generic_do_match(&prd->e, tnow, false); } @@ -2660,7 +2659,7 @@ static void new_reader_writer_common (const struct ddsrt_log_cfg *logcfg, const static void endpoint_common_init (struct entity_common *e, struct endpoint_common *c, struct ddsi_domaingv *gv, enum entity_kind kind, const struct ddsi_guid *guid, const struct ddsi_guid *group_guid, struct participant *pp, bool onlylocal) { - entity_common_init (e, gv, guid, NULL, kind, now (), NN_VENDORID_ECLIPSE, pp->e.onlylocal || onlylocal); + entity_common_init (e, gv, guid, NULL, kind, ddsrt_time_wallclock (), NN_VENDORID_ECLIPSE, pp->e.onlylocal || onlylocal); c->pp = ref_participant (pp, &e->guid); if (group_guid) c->group_guid = *group_guid; @@ -2861,7 +2860,7 @@ void writer_set_retransmitting (struct writer *wr) void writer_clear_retransmitting (struct writer *wr) { wr->retransmitting = 0; - wr->t_whc_high_upd = wr->t_rexmit_end = now_et(); + wr->t_whc_high_upd = wr->t_rexmit_end = ddsrt_time_elapsed(); ddsrt_cond_broadcast (&wr->throttle_cond); } @@ -2924,7 +2923,7 @@ void writer_set_alive_may_unlock (struct writer *wr, bool notify) if (wr->xqos->liveliness.kind == DDS_LIVELINESS_MANUAL_BY_PARTICIPANT) participant_add_wr_lease_locked (wr->c.pp, wr); else if (wr->xqos->liveliness.kind == DDS_LIVELINESS_MANUAL_BY_TOPIC) - lease_set_expiry (wr->lease, add_duration_to_etime (now_et (), wr->lease->tdur)); + lease_set_expiry (wr->lease, ddsrt_etime_add_duration (ddsrt_time_elapsed (), wr->lease->tdur)); } ddsrt_mutex_unlock (&wr->c.pp->e.lock); @@ -3092,7 +3091,7 @@ static void new_writer_guid_common_init (struct writer *wr, const struct ddsi_se scheduled, and this can only change by writing data, which won't happen until after it becomes visible. */ if (wr->reliable) - wr->heartbeat_xevent = qxev_heartbeat (wr->evq, NN_MTIME_NEVER, &wr->e.guid); + wr->heartbeat_xevent = qxev_heartbeat (wr->evq, DDSRT_MTIME_NEVER, &wr->e.guid); else wr->heartbeat_xevent = NULL; @@ -3133,7 +3132,7 @@ static void new_writer_guid_common_init (struct writer *wr, const struct ddsi_se static dds_return_t new_writer_guid (struct writer **wr_out, const struct ddsi_guid *guid, const struct ddsi_guid *group_guid, struct participant *pp, const struct ddsi_sertopic *topic, const struct dds_qos *xqos, struct whc *whc, status_cb_t status_cb, void *status_entity) { struct writer *wr; - nn_mtime_t tnow = now_mt (); + ddsrt_mtime_t tnow = ddsrt_time_monotonic (); assert (is_writer_entityid (guid->entityid)); assert (entidx_lookup_writer_guid (pp->e.gv->entity_index, guid) == NULL); @@ -3159,7 +3158,7 @@ static dds_return_t new_writer_guid (struct writer **wr_out, const struct ddsi_g the other. */ ddsrt_mutex_lock (&wr->e.lock); entidx_insert_writer_guid (pp->e.gv->entity_index, wr); - builtintopic_write (wr->e.gv->builtin_topic_interface, &wr->e, now(), true); + builtintopic_write (wr->e.gv->builtin_topic_interface, &wr->e, ddsrt_time_wallclock(), true); ddsrt_mutex_unlock (&wr->e.lock); /* once it exists, match it with proxy writers and broadcast @@ -3184,11 +3183,11 @@ static dds_return_t new_writer_guid (struct writer **wr_out, const struct ddsi_g ddsrt_mutex_unlock (&pp->e.lock); /* Trigger pmd update */ - (void) resched_xevent_if_earlier (pp->pmd_update_xevent, now_mt ()); + (void) resched_xevent_if_earlier (pp->pmd_update_xevent, ddsrt_time_monotonic ()); } else { - nn_etime_t texpire = add_duration_to_etime (now_et (), wr->lease_duration->ldur); + ddsrt_etime_t texpire = ddsrt_etime_add_duration (ddsrt_time_elapsed (), wr->lease_duration->ldur); wr->lease = lease_new (texpire, wr->lease_duration->ldur, &wr->e); if (wr->xqos->liveliness.kind == DDS_LIVELINESS_MANUAL_BY_PARTICIPANT) { @@ -3233,7 +3232,7 @@ struct local_orphan_writer *new_local_orphan_writer (struct ddsi_domaingv *gv, d ddsi_guid_t guid; struct local_orphan_writer *lowr; struct writer *wr; - nn_mtime_t tnow = now_mt (); + ddsrt_mtime_t tnow = ddsrt_time_monotonic (); GVLOGDISC ("new_local_orphan_writer(%s/%s)\n", topic->name, topic->type_name); lowr = ddsrt_malloc (sizeof (*lowr)); @@ -3241,12 +3240,12 @@ struct local_orphan_writer *new_local_orphan_writer (struct ddsi_domaingv *gv, d memset (&guid.prefix, 0, sizeof (guid.prefix)); guid.entityid = entityid; - entity_common_init (&wr->e, gv, &guid, NULL, EK_WRITER, now (), NN_VENDORID_ECLIPSE, true); + entity_common_init (&wr->e, gv, &guid, NULL, EK_WRITER, ddsrt_time_wallclock (), NN_VENDORID_ECLIPSE, true); wr->c.pp = NULL; memset (&wr->c.group_guid, 0, sizeof (wr->c.group_guid)); new_writer_guid_common_init (wr, topic, xqos, whc, 0, NULL); entidx_insert_writer_guid (gv->entity_index, wr); - builtintopic_write (gv->builtin_topic_interface, &wr->e, now(), true); + builtintopic_write (gv->builtin_topic_interface, &wr->e, ddsrt_time_wallclock(), true); match_writer_with_local_readers (wr, tnow); return lowr; } @@ -3254,7 +3253,7 @@ struct local_orphan_writer *new_local_orphan_writer (struct ddsi_domaingv *gv, d void update_writer_qos (struct writer *wr, const dds_qos_t *xqos) { ddsrt_mutex_lock (&wr->e.lock); - if (update_qos_locked (&wr->e, wr->xqos, xqos, now ())) + if (update_qos_locked (&wr->e, wr->xqos, xqos, ddsrt_time_wallclock ())) sedp_write_writer (wr); ddsrt_mutex_unlock (&wr->e.lock); } @@ -3271,7 +3270,7 @@ static void gc_delete_writer (struct gcreq *gcreq) if (wr->heartbeat_xevent) { - wr->hbcontrol.tsched = NN_MTIME_NEVER; + wr->hbcontrol.tsched = DDSRT_MTIME_NEVER; delete_xevent (wr->heartbeat_xevent); } @@ -3388,7 +3387,7 @@ dds_return_t delete_writer_nolinger_locked (struct writer *wr) { ELOGDISC (wr, "delete_writer_nolinger(guid "PGUIDFMT") ...\n", PGUID (wr->e.guid)); ASSERT_MUTEX_HELD (&wr->e.lock); - builtintopic_write (wr->e.gv->builtin_topic_interface, &wr->e, now(), false); + builtintopic_write (wr->e.gv->builtin_topic_interface, &wr->e, ddsrt_time_wallclock(), false); local_reader_ary_setinvalid (&wr->rdary); entidx_remove_writer_guid (wr->e.gv->entity_index, wr); writer_set_state (wr, WRST_DELETING); @@ -3399,7 +3398,7 @@ dds_return_t delete_writer_nolinger_locked (struct writer *wr) ddsrt_mutex_lock (&wr->c.pp->e.lock); ddsrt_fibheap_delete (&ldur_fhdef, &wr->c.pp->ldur_auto_wr, wr->lease_duration); ddsrt_mutex_unlock (&wr->c.pp->e.lock); - resched_xevent_if_earlier (wr->c.pp->pmd_update_xevent, now_mt ()); + resched_xevent_if_earlier (wr->c.pp->pmd_update_xevent, ddsrt_time_monotonic ()); } else { @@ -3468,12 +3467,12 @@ dds_return_t delete_writer (struct ddsi_domaingv *gv, const struct ddsi_guid *gu } else { - nn_mtime_t tsched; + ddsrt_mtime_t tsched; int32_t tsec, tusec; writer_set_state (wr, WRST_LINGERING); ddsrt_mutex_unlock (&wr->e.lock); - tsched = add_duration_to_mtime (now_mt (), wr->e.gv->config.writer_linger_duration); - mtime_to_sec_usec (&tsec, &tusec, tsched); + tsched = ddsrt_mtime_add_duration (ddsrt_time_monotonic (), wr->e.gv->config.writer_linger_duration); + ddsrt_mtime_to_sec_usec (&tsec, &tusec, tsched); GVLOGDISC ("delete_writer(guid "PGUIDFMT") - unack'ed samples, will delete when ack'd or at t = %"PRId32".%06"PRId32"\n", PGUID (*guid), tsec, tusec); qxev_delete_writer (gv->xevents, tsched, &wr->e.guid); @@ -3604,7 +3603,7 @@ static dds_return_t new_reader_guid /* see new_writer_guid for commenets */ struct reader *rd; - nn_mtime_t tnow = now_mt (); + ddsrt_mtime_t tnow = ddsrt_time_monotonic (); assert (!is_writer_entityid (guid->entityid)); assert (entidx_lookup_reader_guid (pp->e.gv->entity_index, guid) == NULL); @@ -3715,7 +3714,7 @@ static dds_return_t new_reader_guid ddsrt_mutex_lock (&rd->e.lock); entidx_insert_reader_guid (pp->e.gv->entity_index, rd); - builtintopic_write (pp->e.gv->builtin_topic_interface, &rd->e, now(), true); + builtintopic_write (pp->e.gv->builtin_topic_interface, &rd->e, ddsrt_time_wallclock(), true); ddsrt_mutex_unlock (&rd->e.lock); match_reader_with_proxy_writers (rd, tnow); @@ -3816,7 +3815,7 @@ dds_return_t delete_reader (struct ddsi_domaingv *gv, const struct ddsi_guid *gu return DDS_RETCODE_BAD_PARAMETER; } GVLOGDISC ("delete_reader_guid(guid "PGUIDFMT") ...\n", PGUID (*guid)); - builtintopic_write (rd->e.gv->builtin_topic_interface, &rd->e, now(), false); + builtintopic_write (rd->e.gv->builtin_topic_interface, &rd->e, ddsrt_time_wallclock(), false); entidx_remove_reader_guid (gv->entity_index, rd); gcreq_reader (rd); return 0; @@ -3825,7 +3824,7 @@ dds_return_t delete_reader (struct ddsi_domaingv *gv, const struct ddsi_guid *gu void update_reader_qos (struct reader *rd, const dds_qos_t *xqos) { ddsrt_mutex_lock (&rd->e.lock); - if (update_qos_locked (&rd->e, rd->xqos, xqos, now ())) + if (update_qos_locked (&rd->e, rd->xqos, xqos, ddsrt_time_wallclock ())) sedp_write_reader (rd); ddsrt_mutex_unlock (&rd->e.lock); } @@ -3858,7 +3857,7 @@ void proxy_participant_reassign_lease (struct proxy_participant *proxypp, struct { dds_duration_t trem = minl->tdur - proxypp->lease->tdur; assert (trem >= 0); - nn_etime_t texp = add_duration_to_etime (now_et(), trem); + ddsrt_etime_t texp = ddsrt_etime_add_duration (ddsrt_time_elapsed(), trem); struct lease *lnew = lease_new (texp, minl->tdur, minl->entity); proxy_participant_replace_minl (proxypp, false, lnew); lease_register (lnew); @@ -3908,7 +3907,7 @@ static void proxy_participant_add_pwr_lease_locked (struct proxy_participant * p /* if inserted lease is new shortest lease */ if (proxypp->owns_lease && minl_prev != minl_new) { - nn_etime_t texp = add_duration_to_etime (now_et (), minl_new->tdur); + ddsrt_etime_t texp = ddsrt_etime_add_duration (ddsrt_time_elapsed (), minl_new->tdur); struct lease *lnew = lease_new (texp, minl_new->tdur, minl_new->entity); if (minl_prev == NULL) { @@ -3942,7 +3941,7 @@ static void proxy_participant_remove_pwr_lease_locked (struct proxy_participant { dds_duration_t trem = minl->tdur - pwr->lease->tdur; assert (trem >= 0); - nn_etime_t texp = add_duration_to_etime (now_et(), trem); + ddsrt_etime_t texp = ddsrt_etime_add_duration (ddsrt_time_elapsed(), trem); struct lease *lnew = lease_new (texp, minl->tdur, minl->entity); proxy_participant_replace_minl (proxypp, manbypp, lnew); lease_register (lnew); @@ -3954,7 +3953,7 @@ static void proxy_participant_remove_pwr_lease_locked (struct proxy_participant } } -void new_proxy_participant (struct ddsi_domaingv *gv, const struct ddsi_guid *ppguid, uint32_t bes, const struct ddsi_guid *privileged_pp_guid, struct addrset *as_default, struct addrset *as_meta, const ddsi_plist_t *plist, dds_duration_t tlease_dur, nn_vendorid_t vendor, unsigned custom_flags, nn_wctime_t timestamp, seqno_t seq) +void new_proxy_participant (struct ddsi_domaingv *gv, const struct ddsi_guid *ppguid, uint32_t bes, const struct ddsi_guid *privileged_pp_guid, struct addrset *as_default, struct addrset *as_meta, const ddsi_plist_t *plist, dds_duration_t tlease_dur, nn_vendorid_t vendor, unsigned custom_flags, ddsrt_wctime_t timestamp, seqno_t seq) { /* No locking => iff all participants use unique guids, and sedp runs on a single thread, it can't go wrong. FIXME, maybe? The @@ -3965,7 +3964,7 @@ void new_proxy_participant (struct ddsi_domaingv *gv, const struct ddsi_guid *pp assert (entidx_lookup_proxy_participant_guid (gv->entity_index, ppguid) == NULL); assert (privileged_pp_guid == NULL || privileged_pp_guid->entityid.u == NN_ENTITYID_PARTICIPANT); - prune_deleted_participant_guids (gv->deleted_participants, now_mt ()); + prune_deleted_participant_guids (gv->deleted_participants, ddsrt_time_monotonic ()); proxypp = ddsrt_malloc (sizeof (*proxypp)); @@ -4018,7 +4017,7 @@ void new_proxy_participant (struct ddsi_domaingv *gv, const struct ddsi_guid *pp no further triggers for deleting it. Instead, we take tlease_dur == NEVER as a special value meaning a lease that doesn't expire now and that has a "reasonable" lease duration. That way the lease renewal in the data path is fine, and we only need to do something special in SEDP handling. */ - nn_etime_t texp = add_duration_to_etime (now_et(), tlease_dur); + ddsrt_etime_t texp = ddsrt_etime_add_duration (ddsrt_time_elapsed(), tlease_dur); dds_duration_t dur = (tlease_dur == DDS_INFINITY) ? gv->config.lease_duration : tlease_dur; proxypp->lease = lease_new (texp, dur, &proxypp->e); proxypp->owns_lease = 1; @@ -4139,7 +4138,7 @@ void new_proxy_participant (struct ddsi_domaingv *gv, const struct ddsi_guid *pp ddsrt_mutex_unlock (&proxypp->e.lock); } -int update_proxy_participant_plist_locked (struct proxy_participant *proxypp, seqno_t seq, const struct ddsi_plist *datap, nn_wctime_t timestamp) +int update_proxy_participant_plist_locked (struct proxy_participant *proxypp, seqno_t seq, const struct ddsi_plist *datap, ddsrt_wctime_t timestamp) { if (seq > proxypp->seq) { @@ -4160,7 +4159,7 @@ int update_proxy_participant_plist_locked (struct proxy_participant *proxypp, se return 0; } -int update_proxy_participant_plist (struct proxy_participant *proxypp, seqno_t seq, const struct ddsi_plist *datap, nn_wctime_t timestamp) +int update_proxy_participant_plist (struct proxy_participant *proxypp, seqno_t seq, const struct ddsi_plist *datap, ddsrt_wctime_t timestamp) { ddsrt_mutex_lock (&proxypp->e.lock); update_proxy_participant_plist_locked (proxypp, seq, datap, timestamp); @@ -4194,7 +4193,7 @@ static int ref_proxy_participant (struct proxy_participant *proxypp, struct prox static void unref_proxy_participant (struct proxy_participant *proxypp, struct proxy_endpoint_common *c) { uint32_t refc; - const nn_wctime_t tnow = now(); + const ddsrt_wctime_t tnow = ddsrt_time_wallclock(); ddsrt_mutex_lock (&proxypp->e.lock); refc = --proxypp->refc; @@ -4269,7 +4268,7 @@ static struct entity_common *entity_common_from_proxy_endpoint_common (const str return (struct entity_common *) ((char *) c - offsetof (struct proxy_writer, c)); } -static void delete_or_detach_dependent_pp (struct proxy_participant *p, struct proxy_participant *proxypp, nn_wctime_t timestamp, int isimplicit) +static void delete_or_detach_dependent_pp (struct proxy_participant *p, struct proxy_participant *proxypp, ddsrt_wctime_t timestamp, int isimplicit) { ddsrt_mutex_lock (&p->e.lock); if (memcmp (&p->privileged_pp_guid, &proxypp->e.guid, sizeof (proxypp->e.guid)) != 0) @@ -4286,7 +4285,7 @@ static void delete_or_detach_dependent_pp (struct proxy_participant *p, struct p } else { - nn_etime_t texp = add_duration_to_etime (now_et(), p->e.gv->config.ds_grace_period); + ddsrt_etime_t texp = ddsrt_etime_add_duration (ddsrt_time_elapsed(), p->e.gv->config.ds_grace_period); /* Clear dependency (but don't touch entity id, which must be 0x1c1) and set the lease ticking */ ELOGDISC (p, PGUIDFMT" detach-from-DS "PGUIDFMT"\n", PGUID(p->e.guid), PGUID(proxypp->e.guid)); memset (&p->privileged_pp_guid.prefix, 0, sizeof (p->privileged_pp_guid.prefix)); @@ -4296,7 +4295,7 @@ static void delete_or_detach_dependent_pp (struct proxy_participant *p, struct p } } -static void delete_ppt (struct proxy_participant *proxypp, nn_wctime_t timestamp, int isimplicit) +static void delete_ppt (struct proxy_participant *proxypp, ddsrt_wctime_t timestamp, int isimplicit) { ddsi_entityid_t *eps; ddsi_guid_t ep_guid; @@ -4351,7 +4350,7 @@ static void delete_ppt (struct proxy_participant *proxypp, nn_wctime_t timestamp typedef struct proxy_purge_data { struct proxy_participant *proxypp; const nn_locator_t *loc; - nn_wctime_t timestamp; + ddsrt_wctime_t timestamp; } *proxy_purge_data_t; static void purge_helper (const nn_locator_t *n, void * varg) @@ -4371,7 +4370,7 @@ void purge_proxy_participants (struct ddsi_domaingv *gv, const nn_locator_t *loc thread_state_awake_fixed_domain (ts1); data.loc = loc; - data.timestamp = now(); + data.timestamp = ddsrt_time_wallclock(); entidx_enum_proxy_participant_init (&est, gv->entity_index); while ((data.proxypp = entidx_enum_proxy_participant_next (&est)) != NULL) addrset_forall (data.proxypp->as_meta, purge_helper, &data); @@ -4384,7 +4383,7 @@ void purge_proxy_participants (struct ddsi_domaingv *gv, const nn_locator_t *loc thread_state_asleep (ts1); } -int delete_proxy_participant_by_guid (struct ddsi_domaingv *gv, const struct ddsi_guid *guid, nn_wctime_t timestamp, int isimplicit) +int delete_proxy_participant_by_guid (struct ddsi_domaingv *gv, const struct ddsi_guid *guid, ddsrt_wctime_t timestamp, int isimplicit) { struct proxy_participant *ppt; @@ -4421,7 +4420,7 @@ uint64_t get_entity_instance_id (const struct ddsi_domaingv *gv, const struct dd /* PROXY-ENDPOINT --------------------------------------------------- */ -static int proxy_endpoint_common_init (struct entity_common *e, struct proxy_endpoint_common *c, enum entity_kind kind, const struct ddsi_guid *guid, nn_wctime_t tcreate, seqno_t seq, struct proxy_participant *proxypp, struct addrset *as, const ddsi_plist_t *plist) +static int proxy_endpoint_common_init (struct entity_common *e, struct proxy_endpoint_common *c, enum entity_kind kind, const struct ddsi_guid *guid, ddsrt_wctime_t tcreate, seqno_t seq, struct proxy_participant *proxypp, struct addrset *as, const ddsi_plist_t *plist) { const char *name; int ret; @@ -4466,12 +4465,12 @@ static void proxy_endpoint_common_fini (struct entity_common *e, struct proxy_en /* PROXY-WRITER ----------------------------------------------------- */ -int new_proxy_writer (struct ddsi_domaingv *gv, const struct ddsi_guid *ppguid, const struct ddsi_guid *guid, struct addrset *as, const ddsi_plist_t *plist, struct nn_dqueue *dqueue, struct xeventq *evq, nn_wctime_t timestamp, seqno_t seq) +int new_proxy_writer (struct ddsi_domaingv *gv, const struct ddsi_guid *ppguid, const struct ddsi_guid *guid, struct addrset *as, const ddsi_plist_t *plist, struct nn_dqueue *dqueue, struct xeventq *evq, ddsrt_wctime_t timestamp, seqno_t seq) { struct proxy_participant *proxypp; struct proxy_writer *pwr; int isreliable; - nn_mtime_t tnow = now_mt (); + ddsrt_mtime_t tnow = ddsrt_time_monotonic (); int ret; assert (is_writer_entityid (guid->entityid)); @@ -4524,7 +4523,7 @@ int new_proxy_writer (struct ddsi_domaingv *gv, const struct ddsi_guid *ppguid, assert (pwr->c.xqos->present & QP_LIVELINESS); if (pwr->c.xqos->liveliness.lease_duration != DDS_INFINITY) { - nn_etime_t texpire = add_duration_to_etime (now_et (), pwr->c.xqos->liveliness.lease_duration); + ddsrt_etime_t texpire = ddsrt_etime_add_duration (ddsrt_time_elapsed (), pwr->c.xqos->liveliness.lease_duration); pwr->lease = lease_new (texpire, pwr->c.xqos->liveliness.lease_duration, &pwr->e); if (pwr->c.xqos->liveliness.kind != DDS_LIVELINESS_MANUAL_BY_TOPIC) { @@ -4573,7 +4572,7 @@ int new_proxy_writer (struct ddsi_domaingv *gv, const struct ddsi_guid *ppguid, return 0; } -void update_proxy_writer (struct proxy_writer *pwr, seqno_t seq, struct addrset *as, const struct dds_qos *xqos, nn_wctime_t timestamp) +void update_proxy_writer (struct proxy_writer *pwr, seqno_t seq, struct addrset *as, const struct dds_qos *xqos, ddsrt_wctime_t timestamp) { struct reader * rd; struct pwr_rd_match * m; @@ -4610,7 +4609,7 @@ void update_proxy_writer (struct proxy_writer *pwr, seqno_t seq, struct addrset ddsrt_mutex_unlock (&pwr->e.lock); } -void update_proxy_reader (struct proxy_reader *prd, seqno_t seq, struct addrset *as, const struct dds_qos *xqos, nn_wctime_t timestamp) +void update_proxy_reader (struct proxy_reader *prd, seqno_t seq, struct addrset *as, const struct dds_qos *xqos, ddsrt_wctime_t timestamp) { struct prd_wr_match * m; ddsi_guid_t wrguid; @@ -4692,7 +4691,7 @@ static void gc_delete_proxy_writer (struct gcreq *gcreq) /* First stage in deleting the proxy writer. In this function the pwr and its member pointers will remain valid. The real cleaning-up is done async in gc_delete_proxy_writer. */ -int delete_proxy_writer (struct ddsi_domaingv *gv, const struct ddsi_guid *guid, nn_wctime_t timestamp, int isimplicit) +int delete_proxy_writer (struct ddsi_domaingv *gv, const struct ddsi_guid *guid, ddsrt_wctime_t timestamp, int isimplicit) { struct proxy_writer *pwr; DDSRT_UNUSED_ARG (isimplicit); @@ -4766,7 +4765,7 @@ void proxy_writer_set_alive_may_unlock (struct proxy_writer *pwr, bool notify) if (pwr->c.xqos->liveliness.kind != DDS_LIVELINESS_MANUAL_BY_TOPIC) proxy_participant_add_pwr_lease_locked (pwr->c.proxypp, pwr); else - lease_set_expiry (pwr->lease, add_duration_to_etime (now_et (), pwr->lease->tdur)); + lease_set_expiry (pwr->lease, ddsrt_etime_add_duration (ddsrt_time_elapsed (), pwr->lease->tdur)); } ddsrt_mutex_unlock (&pwr->c.proxypp->e.lock); @@ -4800,7 +4799,7 @@ int proxy_writer_set_notalive (struct proxy_writer *pwr, bool notify) /* PROXY-READER ----------------------------------------------------- */ -int new_proxy_reader (struct ddsi_domaingv *gv, const struct ddsi_guid *ppguid, const struct ddsi_guid *guid, struct addrset *as, const ddsi_plist_t *plist, nn_wctime_t timestamp, seqno_t seq +int new_proxy_reader (struct ddsi_domaingv *gv, const struct ddsi_guid *ppguid, const struct ddsi_guid *guid, struct addrset *as, const ddsi_plist_t *plist, ddsrt_wctime_t timestamp, seqno_t seq #ifdef DDSI_INCLUDE_SSM , int favours_ssm #endif @@ -4808,7 +4807,7 @@ int new_proxy_reader (struct ddsi_domaingv *gv, const struct ddsi_guid *ppguid, { struct proxy_participant *proxypp; struct proxy_reader *prd; - nn_mtime_t tnow = now_mt (); + ddsrt_mtime_t tnow = ddsrt_time_monotonic (); int ret; assert (!is_writer_entityid (guid->entityid)); @@ -4911,7 +4910,7 @@ static void gc_delete_proxy_reader (struct gcreq *gcreq) ddsrt_free (prd); } -int delete_proxy_reader (struct ddsi_domaingv *gv, const struct ddsi_guid *guid, nn_wctime_t timestamp, int isimplicit) +int delete_proxy_reader (struct ddsi_domaingv *gv, const struct ddsi_guid *guid, ddsrt_wctime_t timestamp, int isimplicit) { struct proxy_reader *prd; (void)isimplicit; diff --git a/src/core/ddsi/src/q_gc.c b/src/core/ddsi/src/q_gc.c index 8d205b5..4c29ee2 100644 --- a/src/core/ddsi/src/q_gc.c +++ b/src/core/ddsi/src/q_gc.c @@ -19,7 +19,6 @@ #include "dds/ddsi/q_gc.h" #include "dds/ddsi/q_log.h" #include "dds/ddsi/q_config.h" -#include "dds/ddsi/q_time.h" #include "dds/ddsi/q_thread.h" #include "dds/ddsi/ddsi_entity_index.h" #include "dds/ddsi/q_unused.h" @@ -89,8 +88,8 @@ static int threads_vtime_check (uint32_t *nivs, struct idx_vtime *ivs) static uint32_t gcreq_queue_thread (struct gcreq_queue *q) { struct thread_state1 * const ts1 = lookup_thread_state (); - nn_mtime_t next_thread_cputime = { 0 }; - nn_mtime_t t_trigger_recv_threads = { 0 }; + ddsrt_mtime_t next_thread_cputime = { 0 }; + ddsrt_mtime_t t_trigger_recv_threads = { 0 }; int64_t shortsleep = DDS_MSECS (1); int64_t delay = DDS_MSECS (1); /* force evaluation after startup */ struct gcreq *gcreq = NULL; @@ -105,7 +104,7 @@ static uint32_t gcreq_queue_thread (struct gcreq_queue *q) groups. Do rate-limit it a bit. */ if (q->gv->deaf) { - nn_mtime_t tnow_mt = now_mt (); + ddsrt_mtime_t tnow_mt = ddsrt_time_monotonic (); if (tnow_mt.v > t_trigger_recv_threads.v) { trigger_recv_threads (q->gv); @@ -149,7 +148,7 @@ static uint32_t gcreq_queue_thread (struct gcreq_queue *q) burden on the system than having a separate thread or adding it to the workload of the data handling threads. */ thread_state_awake_fixed_domain (ts1); - delay = check_and_handle_lease_expiration (q->gv, now_et ()); + delay = check_and_handle_lease_expiration (q->gv, ddsrt_time_elapsed ()); thread_state_asleep (ts1); if (gcreq) diff --git a/src/core/ddsi/src/q_init.c b/src/core/ddsi/src/q_init.c index 13173eb..226d75d 100644 --- a/src/core/ddsi/src/q_init.c +++ b/src/core/ddsi/src/q_init.c @@ -728,13 +728,13 @@ struct wait_for_receive_threads_helper_arg { unsigned count; }; -static void wait_for_receive_threads_helper (struct xevent *xev, void *varg, nn_mtime_t tnow) +static void wait_for_receive_threads_helper (struct xevent *xev, void *varg, ddsrt_mtime_t tnow) { struct wait_for_receive_threads_helper_arg * const arg = varg; if (arg->count++ == arg->gv->config.recv_thread_stop_maxretries) abort (); trigger_recv_threads (arg->gv); - (void) resched_xevent_if_earlier (xev, add_duration_to_mtime (tnow, DDS_SECS (1))); + (void) resched_xevent_if_earlier (xev, ddsrt_mtime_add_duration (tnow, DDS_SECS (1))); } static void wait_for_receive_threads (struct ddsi_domaingv *gv) @@ -743,7 +743,7 @@ static void wait_for_receive_threads (struct ddsi_domaingv *gv) struct wait_for_receive_threads_helper_arg cbarg; cbarg.gv = gv; cbarg.count = 0; - if ((trigev = qxev_callback (gv->xevents, add_duration_to_mtime (now_mt (), DDS_SECS (1)), wait_for_receive_threads_helper, &cbarg)) == NULL) + if ((trigev = qxev_callback (gv->xevents, ddsrt_mtime_add_duration (ddsrt_time_monotonic (), DDS_SECS (1)), wait_for_receive_threads_helper, &cbarg)) == NULL) { /* retrying is to deal a packet geting lost because the socket buffer is full or because the macOS firewall (and perhaps others) likes to ask if the process is allowed to receive data, @@ -924,7 +924,7 @@ static uint32_t ddsi_sertopic_hash_wrap (const void *tp) return ddsi_sertopic_hash (tp); } -static void reset_deaf_mute (struct xevent *xev, void *varg, UNUSED_ARG (nn_mtime_t tnow)) +static void reset_deaf_mute (struct xevent *xev, void *varg, UNUSED_ARG (ddsrt_mtime_t tnow)) { struct ddsi_domaingv *gv = varg; gv->deaf = 0; @@ -940,7 +940,7 @@ void ddsi_set_deafmute (struct ddsi_domaingv *gv, bool deaf, bool mute, int64_t GVLOGDISC (" DEAFMUTE set [deaf, mute]=[%d, %d]", gv->deaf, gv->mute); if (reset_after < DDS_INFINITY) { - nn_mtime_t when = add_duration_to_mtime (now_mt (), reset_after); + ddsrt_mtime_t when = ddsrt_mtime_add_duration (ddsrt_time_monotonic (), reset_after); GVTRACE (" reset after %"PRId64".%09u ns", reset_after / DDS_NSECS_IN_SEC, (unsigned) (reset_after % DDS_NSECS_IN_SEC)); qxev_callback (gv->xevents, when, reset_deaf_mute, gv); } @@ -952,9 +952,9 @@ int rtps_init (struct ddsi_domaingv *gv) uint32_t port_disc_uc = 0; uint32_t port_data_uc = 0; bool mc_available = true; - nn_mtime_t reset_deaf_mute_time = NN_MTIME_NEVER; + ddsrt_mtime_t reset_deaf_mute_time = DDSRT_MTIME_NEVER; - gv->tstart = now (); /* wall clock time, used in logs */ + gv->tstart = ddsrt_time_wallclock (); /* wall clock time, used in logs */ ddsi_plist_init_tables (); @@ -982,7 +982,7 @@ int rtps_init (struct ddsi_domaingv *gv) if (gv->deaf || gv->mute) { GVLOG (DDS_LC_CONFIG | DDS_LC_DISCOVERY, "DEAFMUTE initial deaf=%d mute=%d reset after %"PRId64"d ns\n", gv->deaf, gv->mute, gv->config.initial_deaf_mute_reset); - reset_deaf_mute_time = add_duration_to_mtime (now_mt (), gv->config.initial_deaf_mute_reset); + reset_deaf_mute_time = ddsrt_mtime_add_duration (ddsrt_time_monotonic (), gv->config.initial_deaf_mute_reset); } /* Initialize thread pool */ @@ -1640,7 +1640,7 @@ void rtps_stop (struct ddsi_domaingv *gv) { struct entidx_enum_proxy_participant est; struct proxy_participant *proxypp; - const nn_wctime_t tnow = now(); + const ddsrt_wctime_t tnow = ddsrt_time_wallclock(); /* Clean up proxy readers, proxy writers and proxy participants. Deleting a proxy participants deletes all its readers and writers automatically */ diff --git a/src/core/ddsi/src/q_lease.c b/src/core/ddsi/src/q_lease.c index 0469a46..a7a40c5 100644 --- a/src/core/ddsi/src/q_lease.c +++ b/src/core/ddsi/src/q_lease.c @@ -76,7 +76,7 @@ void lease_management_term (struct ddsi_domaingv *gv) ddsrt_mutex_destroy (&gv->leaseheap_lock); } -struct lease *lease_new (nn_etime_t texpire, dds_duration_t tdur, struct entity_common *e) +struct lease *lease_new (ddsrt_etime_t texpire, dds_duration_t tdur, struct entity_common *e) { struct lease *l; if ((l = ddsrt_malloc (sizeof (*l))) == NULL) @@ -96,7 +96,7 @@ struct lease *lease_new (nn_etime_t texpire, dds_duration_t tdur, struct entity_ */ struct lease *lease_clone (const struct lease *l) { - nn_etime_t texp; + ddsrt_etime_t texp; dds_duration_t tdur; texp.v = (int64_t) ddsrt_atomic_ld64 (&l->tend); tdur = l->tdur; @@ -144,7 +144,7 @@ void lease_free (struct lease *l) ddsrt_free (l); } -static void trace_lease_renew (const struct lease *l, const char *tag, nn_etime_t tend_new) +static void trace_lease_renew (const struct lease *l, const char *tag, ddsrt_etime_t tend_new) { struct ddsi_domaingv const * gv = l->entity->gv; if (gv->logconfig.c.mask & DDS_LC_TRACE) @@ -155,14 +155,14 @@ static void trace_lease_renew (const struct lease *l, const char *tag, nn_etime_ GVTRACE (":%"PRIx32, l->entity->guid.entityid.u); else GVTRACE (""PGUIDFMT"", PGUID (l->entity->guid)); - etime_to_sec_usec (&tsec, &tusec, tend_new); + ddsrt_etime_to_sec_usec (&tsec, &tusec, tend_new); GVTRACE (" %"PRId32".%06"PRId32")", tsec, tusec); } } -void lease_renew (struct lease *l, nn_etime_t tnowE) +void lease_renew (struct lease *l, ddsrt_etime_t tnowE) { - nn_etime_t tend_new = add_duration_to_etime (tnowE, l->tdur); + ddsrt_etime_t tend_new = ddsrt_etime_add_duration (tnowE, l->tdur); /* do not touch tend if moving forward or if already expired */ int64_t tend; @@ -179,7 +179,7 @@ void lease_renew (struct lease *l, nn_etime_t tnowE) trace_lease_renew (l, "", tend_new); } -void lease_set_expiry (struct lease *l, nn_etime_t when) +void lease_set_expiry (struct lease *l, ddsrt_etime_t when) { struct ddsi_domaingv * const gv = l->entity->gv; bool trigger = false; @@ -212,7 +212,7 @@ void lease_set_expiry (struct lease *l, nn_etime_t when) force_lease_check (gv->gcreq_queue); } -int64_t check_and_handle_lease_expiration (struct ddsi_domaingv *gv, nn_etime_t tnowE) +int64_t check_and_handle_lease_expiration (struct ddsi_domaingv *gv, ddsrt_etime_t tnowE) { struct lease *l; int64_t delay; @@ -273,7 +273,7 @@ int64_t check_and_handle_lease_expiration (struct ddsi_domaingv *gv, nn_etime_t entidx_lookup_proxy_participant_guid (gv->entity_index, &proxypp->privileged_pp_guid) != NULL) { GVLOGDISC ("but postponing because privileged pp "PGUIDFMT" is still live\n", PGUID (proxypp->privileged_pp_guid)); - l->tsched = add_duration_to_etime (tnowE, DDS_MSECS (200)); + l->tsched = ddsrt_etime_add_duration (tnowE, DDS_MSECS (200)); ddsrt_fibheap_insert (&lease_fhdef, &gv->leaseheap, l); continue; } @@ -285,7 +285,7 @@ int64_t check_and_handle_lease_expiration (struct ddsi_domaingv *gv, nn_etime_t switch (k) { case EK_PROXY_PARTICIPANT: - delete_proxy_participant_by_guid (gv, &g, now(), 1); + delete_proxy_participant_by_guid (gv, &g, ddsrt_time_wallclock(), 1); break; case EK_PROXY_WRITER: proxy_writer_set_notalive ((struct proxy_writer *) l->entity, true); diff --git a/src/core/ddsi/src/q_pcap.c b/src/core/ddsi/src/q_pcap.c index 42b2824..601c96d 100644 --- a/src/core/ddsi/src/q_pcap.c +++ b/src/core/ddsi/src/q_pcap.c @@ -14,7 +14,6 @@ #include "dds/ddsrt/endian.h" #include "dds/ddsi/q_log.h" -#include "dds/ddsi/q_time.h" #include "dds/ddsi/q_config.h" #include "dds/ddsi/ddsi_domaingv.h" #include "dds/ddsi/q_bswap.h" @@ -127,7 +126,7 @@ static uint16_t calc_ipv4_checksum (const uint16_t *x) return (uint16_t) ~s; } -void write_pcap_received (struct ddsi_domaingv *gv, nn_wctime_t tstamp, const struct sockaddr_storage *src, const struct sockaddr_storage *dst, unsigned char *buf, size_t sz) +void write_pcap_received (struct ddsi_domaingv *gv, ddsrt_wctime_t tstamp, const struct sockaddr_storage *src, const struct sockaddr_storage *dst, unsigned char *buf, size_t sz) { if (gv->config.transport_selector == TRANS_UDP) { @@ -140,7 +139,7 @@ void write_pcap_received (struct ddsi_domaingv *gv, nn_wctime_t tstamp, const st size_t sz_ud = sz + UDP_HDR_SIZE; size_t sz_iud = sz_ud + IPV4_HDR_SIZE; ddsrt_mutex_lock (&gv->pcap_lock); - wctime_to_sec_usec (&pcap_hdr.ts_sec, &pcap_hdr.ts_usec, tstamp); + ddsrt_wctime_to_sec_usec (&pcap_hdr.ts_sec, &pcap_hdr.ts_usec, tstamp); pcap_hdr.incl_len = pcap_hdr.orig_len = (uint32_t) sz_iud; (void) fwrite (&pcap_hdr, sizeof (pcap_hdr), 1, gv->pcap_fp); u.ipv4_hdr = ipv4_hdr_template; @@ -160,7 +159,7 @@ void write_pcap_received (struct ddsi_domaingv *gv, nn_wctime_t tstamp, const st } } -void write_pcap_sent (struct ddsi_domaingv *gv, nn_wctime_t tstamp, const struct sockaddr_storage *src, const ddsrt_msghdr_t *hdr, size_t sz) +void write_pcap_sent (struct ddsi_domaingv *gv, ddsrt_wctime_t tstamp, const struct sockaddr_storage *src, const ddsrt_msghdr_t *hdr, size_t sz) { if (gv->config.transport_selector == TRANS_UDP) { @@ -173,7 +172,7 @@ void write_pcap_sent (struct ddsi_domaingv *gv, nn_wctime_t tstamp, const struct size_t sz_ud = sz + UDP_HDR_SIZE; size_t sz_iud = sz_ud + IPV4_HDR_SIZE; ddsrt_mutex_lock (&gv->pcap_lock); - wctime_to_sec_usec (&pcap_hdr.ts_sec, &pcap_hdr.ts_usec, tstamp); + ddsrt_wctime_to_sec_usec (&pcap_hdr.ts_sec, &pcap_hdr.ts_usec, tstamp); pcap_hdr.incl_len = pcap_hdr.orig_len = (uint32_t) sz_iud; (void) fwrite (&pcap_hdr, sizeof (pcap_hdr), 1, gv->pcap_fp); u.ipv4_hdr = ipv4_hdr_template; diff --git a/src/core/ddsi/src/q_qosmatch.c b/src/core/ddsi/src/q_qosmatch.c index 7c951e1..b20468f 100644 --- a/src/core/ddsi/src/q_qosmatch.c +++ b/src/core/ddsi/src/q_qosmatch.c @@ -12,7 +12,6 @@ #include #include -#include "dds/ddsi/q_time.h" #include "dds/ddsi/ddsi_xqos.h" #include "dds/ddsi/q_misc.h" #include "dds/ddsi/q_qosmatch.h" diff --git a/src/core/ddsi/src/q_radmin.c b/src/core/ddsi/src/q_radmin.c index e269b35..c224919 100644 --- a/src/core/ddsi/src/q_radmin.c +++ b/src/core/ddsi/src/q_radmin.c @@ -2427,7 +2427,7 @@ static uint32_t dqueue_thread (struct nn_dqueue *q) { struct thread_state1 * const ts1 = lookup_thread_state (); struct ddsi_domaingv const * const gv = ddsrt_atomic_ldvoidp (&ts1->gv); - nn_mtime_t next_thread_cputime = { 0 }; + ddsrt_mtime_t next_thread_cputime = { 0 }; int keepgoing = 1; ddsi_guid_t rdguid, *prdguid = NULL; uint32_t rdguid_count = 0; diff --git a/src/core/ddsi/src/q_receive.c b/src/core/ddsi/src/q_receive.c index 54e5d7b..17e9654 100644 --- a/src/core/ddsi/src/q_receive.c +++ b/src/core/ddsi/src/q_receive.c @@ -205,7 +205,7 @@ static int valid_InfoTS (InfoTS_t *msg, size_t size, int byteswap) msg->time.seconds = ddsrt_bswap4 (msg->time.seconds); msg->time.fraction = ddsrt_bswap4u (msg->time.fraction); } - return valid_ddsi_timestamp (msg->time); + return ddsi_is_valid_timestamp (msg->time); } } @@ -585,7 +585,7 @@ static int acknack_is_nack (const AckNack_t *msg) return x != 0; } -static int accept_ack_or_hb_w_timeout (nn_count_t new_count, nn_count_t *exp_count, nn_etime_t tnow, nn_etime_t *t_last_accepted, int force_accept) +static int accept_ack_or_hb_w_timeout (nn_count_t new_count, nn_count_t *exp_count, ddsrt_etime_t tnow, ddsrt_etime_t *t_last_accepted, int force_accept) { /* AckNacks and Heartbeats with a sequence number (called "count" for some reason) equal to or less than the highest one received @@ -613,7 +613,7 @@ static int accept_ack_or_hb_w_timeout (nn_count_t new_count, nn_count_t *exp_cou return 1; } -static int handle_AckNack (struct receiver_state *rst, nn_etime_t tnow, const AckNack_t *msg, nn_wctime_t timestamp) +static int handle_AckNack (struct receiver_state *rst, ddsrt_etime_t tnow, const AckNack_t *msg, ddsrt_wctime_t timestamp) { struct proxy_reader *prd; struct wr_prd_match *rn; @@ -712,7 +712,7 @@ static int handle_AckNack (struct receiver_state *rst, nn_etime_t tnow, const Ac moment. */ if (rst->gv->config.meas_hb_to_ack_latency && timestamp.v) { - nn_wctime_t tstamp_now = now (); + ddsrt_wctime_t tstamp_now = ddsrt_time_wallclock (); nn_lat_estim_update (&rn->hb_to_ack_latency, tstamp_now.v - timestamp.v); if ((rst->gv->logconfig.c.mask & DDS_LC_TRACE) && tstamp_now.v > rn->hb_to_ack_latency_tlastlog.v + DDS_SECS (10)) { @@ -860,7 +860,7 @@ static int handle_AckNack (struct receiver_state *rst, nn_etime_t tnow, const Ac if (rst->gv->config.retransmit_merging != REXMIT_MERGE_NEVER && rn->assumed_in_sync) { /* send retransmit to all receivers, but skip if recently done */ - nn_mtime_t tstamp = now_mt (); + ddsrt_mtime_t tstamp = ddsrt_time_monotonic (); if (tstamp.v > sample.last_rexmit_ts.v + rst->gv->config.retransmit_merging_period) { RSTTRACE (" RX%"PRId64, seqbase + i); @@ -968,7 +968,7 @@ static int handle_AckNack (struct receiver_state *rst, nn_etime_t tnow, const Ac gradually lowering rate. If we just got a request for a retransmit, and there is more to be retransmitted, surely the rate should be kept up for now */ - writer_hbcontrol_note_asyncwrite (wr, now_mt ()); + writer_hbcontrol_note_asyncwrite (wr, ddsrt_time_monotonic ()); } /* If "final" flag not set, we must respond with a heartbeat. Do it now if we haven't done so already */ @@ -1033,9 +1033,9 @@ struct handle_Heartbeat_helper_arg { struct receiver_state *rst; const Heartbeat_t *msg; struct proxy_writer *pwr; - nn_wctime_t timestamp; - nn_etime_t tnow; - nn_mtime_t tnow_mt; + ddsrt_wctime_t timestamp; + ddsrt_etime_t tnow; + ddsrt_mtime_t tnow_mt; }; static void handle_Heartbeat_helper (struct pwr_rd_match * const wn, struct handle_Heartbeat_helper_arg * const arg) @@ -1072,7 +1072,7 @@ static void handle_Heartbeat_helper (struct pwr_rd_match * const wn, struct hand once, regardless of which readers care about it. */ if (wn->acknack_xevent) { - nn_mtime_t tsched = NN_MTIME_NEVER; + ddsrt_mtime_t tsched = DDSRT_MTIME_NEVER; if (pwr->last_seq > refseq) { RSTTRACE ("/NAK"); @@ -1096,7 +1096,7 @@ static void handle_Heartbeat_helper (struct pwr_rd_match * const wn, struct hand } } -static int handle_Heartbeat (struct receiver_state *rst, nn_etime_t tnow, struct nn_rmsg *rmsg, const Heartbeat_t *msg, nn_wctime_t timestamp) +static int handle_Heartbeat (struct receiver_state *rst, ddsrt_etime_t tnow, struct nn_rmsg *rmsg, const Heartbeat_t *msg, ddsrt_wctime_t timestamp) { /* We now cheat: and process the heartbeat for _all_ readers, always, regardless of the destination address in the Heartbeat @@ -1243,7 +1243,7 @@ static int handle_Heartbeat (struct receiver_state *rst, nn_etime_t tnow, struct arg.pwr = pwr; arg.timestamp = timestamp; arg.tnow = tnow; - arg.tnow_mt = now_mt (); + arg.tnow_mt = ddsrt_time_monotonic (); handle_forall_destinations (&dst, pwr, (ddsrt_avl_walk_t) handle_Heartbeat_helper, &arg); RSTTRACE (")"); @@ -1251,7 +1251,7 @@ static int handle_Heartbeat (struct receiver_state *rst, nn_etime_t tnow, struct return 1; } -static int handle_HeartbeatFrag (struct receiver_state *rst, UNUSED_ARG(nn_etime_t tnow), const HeartbeatFrag_t *msg) +static int handle_HeartbeatFrag (struct receiver_state *rst, UNUSED_ARG(ddsrt_etime_t tnow), const HeartbeatFrag_t *msg) { const seqno_t seq = fromSN (msg->writerSN); const nn_fragment_number_t fragnum = msg->lastFragmentNum - 1; /* we do 0-based */ @@ -1353,7 +1353,7 @@ static int handle_HeartbeatFrag (struct receiver_state *rst, UNUSED_ARG(nn_etime samples we no longer care about) */ int64_t delay = rst->gv->config.nack_delay; RSTTRACE ("/nackfrag"); - (void) resched_xevent_if_earlier (m->acknack_xevent, add_duration_to_mtime (now_mt(), delay)); + (void) resched_xevent_if_earlier (m->acknack_xevent, ddsrt_mtime_add_duration (ddsrt_time_monotonic(), delay)); } } } @@ -1362,7 +1362,7 @@ static int handle_HeartbeatFrag (struct receiver_state *rst, UNUSED_ARG(nn_etime return 1; } -static int handle_NackFrag (struct receiver_state *rst, nn_etime_t tnow, const NackFrag_t *msg) +static int handle_NackFrag (struct receiver_state *rst, ddsrt_etime_t tnow, const NackFrag_t *msg) { struct proxy_reader *prd; struct wr_prd_match *rn; @@ -1475,7 +1475,7 @@ static int handle_NackFrag (struct receiver_state *rst, nn_etime_t tnow, const N struct whc_state whcst; whc_get_state(wr->whc, &whcst); force_heartbeat_to_peer (wr, &whcst, prd, 1); - writer_hbcontrol_note_asyncwrite (wr, now_mt ()); + writer_hbcontrol_note_asyncwrite (wr, ddsrt_time_monotonic ()); } out: @@ -1515,17 +1515,17 @@ static int handle_InfoSRC (struct receiver_state *rst, const InfoSRC_t *msg) return 1; } -static int handle_InfoTS (const struct receiver_state *rst, const InfoTS_t *msg, nn_wctime_t *timestamp) +static int handle_InfoTS (const struct receiver_state *rst, const InfoTS_t *msg, ddsrt_wctime_t *timestamp) { RSTTRACE ("INFOTS("); if (msg->smhdr.flags & INFOTS_INVALIDATE_FLAG) { - *timestamp = NN_WCTIME_INVALID; + *timestamp = DDSRT_WCTIME_INVALID; RSTTRACE ("invalidate"); } else { - *timestamp = nn_wctime_from_ddsi_time (msg->time); + *timestamp = ddsi_wctime_from_ddsi_time (msg->time); if (rst->gv->logconfig.c.mask & DDS_LC_TRACE) RSTTRACE ("%d.%09d", (int) (timestamp->v / 1000000000), (int) (timestamp->v % 1000000000)); } @@ -1597,7 +1597,7 @@ static int handle_one_gap (struct proxy_writer *pwr, struct pwr_rd_match *wn, se return gap_was_valuable; } -static int handle_Gap (struct receiver_state *rst, nn_etime_t tnow, struct nn_rmsg *rmsg, const Gap_t *msg) +static int handle_Gap (struct receiver_state *rst, ddsrt_etime_t tnow, struct nn_rmsg *rmsg, const Gap_t *msg) { /* Option 1: Process the Gap for the proxy writer and all out-of-sync readers: what do I care which reader is being @@ -1722,7 +1722,7 @@ static int handle_Gap (struct receiver_state *rst, nn_etime_t tnow, struct nn_rm return 1; } -static struct ddsi_serdata *get_serdata (struct ddsi_sertopic const * const topic, const struct nn_rdata *fragchain, uint32_t sz, int justkey, unsigned statusinfo, nn_wctime_t tstamp) +static struct ddsi_serdata *get_serdata (struct ddsi_sertopic const * const topic, const struct nn_rdata *fragchain, uint32_t sz, int justkey, unsigned statusinfo, ddsrt_wctime_t tstamp) { struct ddsi_serdata *sd = ddsi_serdata_from_ser (topic, justkey ? SDK_KEY : SDK_DATA, fragchain, sz); if (sd) @@ -1739,7 +1739,7 @@ struct remote_sourceinfo { const ddsi_plist_t *qos; const struct nn_rdata *fragchain; unsigned statusinfo; - nn_wctime_t tstamp; + ddsrt_wctime_t tstamp; }; static struct ddsi_serdata *remote_make_sample (struct ddsi_tkmap_instance **tk, struct ddsi_domaingv *gv, struct ddsi_sertopic const * const topic, void *vsourceinfo) @@ -1751,7 +1751,7 @@ static struct ddsi_serdata *remote_make_sample (struct ddsi_tkmap_instance **tk, const struct nn_rdata * __restrict fragchain = si->fragchain; const uint32_t statusinfo = si->statusinfo; const unsigned char data_smhdr_flags = si->data_smhdr_flags; - const nn_wctime_t tstamp = si->tstamp; + const ddsrt_wctime_t tstamp = si->tstamp; const ddsi_plist_t * __restrict qos = si->qos; const char *failmsg = NULL; struct ddsi_serdata *sample = NULL; @@ -1984,7 +1984,7 @@ static int deliver_user_data (const struct nn_rsample_info *sampleinfo, const st } /* FIXME: should it be 0, local wall clock time or INVALID? */ - const nn_wctime_t tstamp = (sampleinfo->timestamp.v != NN_WCTIME_INVALID.v) ? sampleinfo->timestamp : ((nn_wctime_t) {0}); + const ddsrt_wctime_t tstamp = (sampleinfo->timestamp.v != DDSRT_WCTIME_INVALID.v) ? sampleinfo->timestamp : ((ddsrt_wctime_t) {0}); struct ddsi_writer_info wrinfo; ddsi_make_writer_info (&wrinfo, &pwr->e, pwr->c.xqos, statusinfo); @@ -2052,7 +2052,7 @@ static void clean_defrag (struct proxy_writer *pwr) nn_defrag_notegap (pwr->defrag, 1, seq); } -static void handle_regular (struct receiver_state *rst, nn_etime_t tnow, struct nn_rmsg *rmsg, const Data_DataFrag_common_t *msg, const struct nn_rsample_info *sampleinfo, +static void handle_regular (struct receiver_state *rst, ddsrt_etime_t tnow, struct nn_rmsg *rmsg, const Data_DataFrag_common_t *msg, const struct nn_rsample_info *sampleinfo, uint32_t fragnum, struct nn_rdata *rdata, struct nn_dqueue **deferred_wakeup, bool renew_manbypp_lease) { struct proxy_writer *pwr; @@ -2320,7 +2320,7 @@ static void drop_oversize (struct receiver_state *rst, struct nn_rmsg *rmsg, con } } -static int handle_Data (struct receiver_state *rst, nn_etime_t tnow, struct nn_rmsg *rmsg, const Data_t *msg, size_t size, struct nn_rsample_info *sampleinfo, unsigned char *datap, struct nn_dqueue **deferred_wakeup) +static int handle_Data (struct receiver_state *rst, ddsrt_etime_t tnow, struct nn_rmsg *rmsg, const Data_t *msg, size_t size, struct nn_rsample_info *sampleinfo, unsigned char *datap, struct nn_dqueue **deferred_wakeup) { RSTTRACE ("DATA("PGUIDFMT" -> "PGUIDFMT" #%"PRId64, PGUIDPREFIX (rst->src_guid_prefix), msg->x.writerId.u, @@ -2372,7 +2372,7 @@ static int handle_Data (struct receiver_state *rst, nn_etime_t tnow, struct nn_r return 1; } -static int handle_DataFrag (struct receiver_state *rst, nn_etime_t tnow, struct nn_rmsg *rmsg, const DataFrag_t *msg, size_t size, struct nn_rsample_info *sampleinfo, unsigned char *datap, struct nn_dqueue **deferred_wakeup) +static int handle_DataFrag (struct receiver_state *rst, ddsrt_etime_t tnow, struct nn_rmsg *rmsg, const DataFrag_t *msg, size_t size, struct nn_rsample_info *sampleinfo, unsigned char *datap, struct nn_dqueue **deferred_wakeup) { RSTTRACE ("DATAFRAG("PGUIDFMT" -> "PGUIDFMT" #%"PRId64"/[%u..%u]", PGUIDPREFIX (rst->src_guid_prefix), msg->x.writerId.u, @@ -2586,8 +2586,8 @@ static int handle_submsg_sequence struct ddsi_domaingv *gv, ddsi_tran_conn_t conn, const nn_locator_t *srcloc, - nn_wctime_t tnowWC, - nn_etime_t tnowE, + ddsrt_wctime_t tnowWC, + ddsrt_etime_t tnowE, const ddsi_guid_prefix_t * const src_prefix, const ddsi_guid_prefix_t * const dst_prefix, unsigned char * const msg /* NOT const - we may byteswap it */, @@ -2601,7 +2601,7 @@ static int handle_submsg_sequence Header_t * hdr = (Header_t *) msg; struct receiver_state *rst; int rst_live, ts_for_latmeas; - nn_wctime_t timestamp; + ddsrt_wctime_t timestamp; size_t submsg_size = 0; unsigned char * end = msg + len; struct nn_dqueue *deferred_wakeup = NULL; @@ -2632,7 +2632,7 @@ static int handle_submsg_sequence rst->gv = gv; rst_live = 0; ts_for_latmeas = 0; - timestamp = NN_WCTIME_INVALID; + timestamp = DDSRT_WCTIME_INVALID; assert (thread_is_asleep ()); thread_state_awake_fixed_domain (ts1); @@ -2687,14 +2687,14 @@ static int handle_submsg_sequence state = "parse:acknack"; if (!valid_AckNack (rst, &sm->acknack, submsg_size, byteswap)) goto malformed; - handle_AckNack (rst, tnowE, &sm->acknack, ts_for_latmeas ? timestamp : NN_WCTIME_INVALID); + handle_AckNack (rst, tnowE, &sm->acknack, ts_for_latmeas ? timestamp : DDSRT_WCTIME_INVALID); ts_for_latmeas = 0; break; case SMID_HEARTBEAT: state = "parse:heartbeat"; if (!valid_Heartbeat (&sm->heartbeat, submsg_size, byteswap)) goto malformed; - handle_Heartbeat (rst, tnowE, rmsg, &sm->heartbeat, ts_for_latmeas ? timestamp : NN_WCTIME_INVALID); + handle_Heartbeat (rst, tnowE, rmsg, &sm->heartbeat, ts_for_latmeas ? timestamp : DDSRT_WCTIME_INVALID); ts_for_latmeas = 0; break; case SMID_GAP: @@ -2975,7 +2975,7 @@ static bool do_packet (struct thread_state1 * const ts1, struct ddsi_domaingv *g PGUIDPREFIX (hdr->guid_prefix), hdr->vendorid.id[0], hdr->vendorid.id[1], (unsigned long) sz, addrstr); } - handle_submsg_sequence (ts1, gv, conn, &srcloc, now (), now_et (), &hdr->guid_prefix, guidprefix, buff, (size_t) sz, buff + RTPS_MESSAGE_HEADER_SIZE, rmsg); + handle_submsg_sequence (ts1, gv, conn, &srcloc, ddsrt_time_wallclock (), ddsrt_time_elapsed (), &hdr->guid_prefix, guidprefix, buff, (size_t) sz, buff + RTPS_MESSAGE_HEADER_SIZE, rmsg); } } nn_rmsg_commit (rmsg); @@ -3174,7 +3174,7 @@ uint32_t recv_thread (void *vrecv_thread_arg) struct ddsi_domaingv * const gv = recv_thread_arg->gv; struct nn_rbufpool *rbpool = recv_thread_arg->rbpool; os_sockWaitset waitset = recv_thread_arg->mode == RTM_MANY ? recv_thread_arg->u.many.ws : NULL; - nn_mtime_t next_thread_cputime = { 0 }; + ddsrt_mtime_t next_thread_cputime = { 0 }; nn_rbufpool_setowner (rbpool, ddsrt_thread_self ()); if (waitset == NULL) diff --git a/src/core/ddsi/src/q_time.c b/src/core/ddsi/src/q_time.c deleted file mode 100644 index d25dd02..0000000 --- a/src/core/ddsi/src/q_time.c +++ /dev/null @@ -1,185 +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 - -#include "dds/ddsrt/time.h" -#include "dds/ddsi/q_time.h" - -nn_wctime_t now (void) -{ - /* This function uses the wall clock. - * This clock is not affected by time spent in suspend mode. - * This clock is affected when the real time system clock jumps - * forwards/backwards */ - nn_wctime_t t; - t.v = dds_time(); - return t; -} - -nn_mtime_t now_mt (void) -{ - /* This function uses the monotonic clock. - * This clock stops while the system is in suspend mode. - * This clock is not affected by any jumps of the realtime clock. */ - nn_mtime_t t; - t.v = ddsrt_time_monotonic(); - return t; -} - -nn_etime_t now_et (void) -{ - /* This function uses the elapsed clock. - * This clock is not affected by any jumps of the realtime clock. - * This clock does NOT stop when the system is in suspend mode. - * This clock stops when the system is shut down, and starts when the system is restarted. - * When restarted, there are no assumptions about the initial value of clock. */ - nn_etime_t t; - t.v = ddsrt_time_elapsed(); - return t; -} - -static void time_to_sec_usec (int32_t * __restrict sec, int32_t * __restrict usec, int64_t t) -{ - *sec = (int32_t) (t / DDS_NSECS_IN_SEC); - *usec = (int32_t) (t % DDS_NSECS_IN_SEC) / 1000; -} - -void mtime_to_sec_usec (int32_t * __restrict sec, int32_t * __restrict usec, nn_mtime_t t) -{ - time_to_sec_usec (sec, usec, t.v); -} - -void wctime_to_sec_usec (int32_t * __restrict sec, int32_t * __restrict usec, nn_wctime_t t) -{ - time_to_sec_usec (sec, usec, t.v); -} - -void etime_to_sec_usec (int32_t * __restrict sec, int32_t * __restrict usec, nn_etime_t t) -{ - time_to_sec_usec (sec, usec, t.v); -} - - -nn_mtime_t mtime_round_up (nn_mtime_t t, int64_t round) -{ - /* This function rounds up t to the nearest next multiple of round. - t is nanoseconds, round is milliseconds. Avoid functions from - maths libraries to keep code portable */ - assert (t.v >= 0 && round >= 0); - if (round == 0 || t.v == DDS_INFINITY) - { - return t; - } - else - { - int64_t remainder = t.v % round; - if (remainder == 0) - { - return t; - } - else - { - nn_mtime_t u; - u.v = t.v + round - remainder; - return u; - } - } -} - -static int64_t add_duration_to_time (int64_t t, int64_t d) -{ - uint64_t sum; - assert (t >= 0 && d >= 0); - sum = (uint64_t)t + (uint64_t)d; - return sum >= DDS_NEVER ? DDS_NEVER : (int64_t)sum; -} - -nn_mtime_t add_duration_to_mtime (nn_mtime_t t, int64_t d) -{ - /* assumed DDS_NEVER <=> MAX_INT64 */ - nn_mtime_t u; - u.v = add_duration_to_time (t.v, d); - return u; -} - -nn_wctime_t add_duration_to_wctime (nn_wctime_t t, int64_t d) -{ - /* assumed DDS_NEVER <=> MAX_INT64 */ - nn_wctime_t u; - u.v = add_duration_to_time (t.v, d); - return u; -} - -nn_etime_t add_duration_to_etime (nn_etime_t t, int64_t d) -{ - /* assumed DDS_NEVER <=> MAX_INT64 */ - nn_etime_t u; - u.v = add_duration_to_time (t.v, d); - return u; -} - -int valid_ddsi_timestamp (ddsi_time_t t) -{ - return t.seconds != DDSI_TIME_INVALID.seconds && t.fraction != DDSI_TIME_INVALID.fraction; -} - -static ddsi_time_t nn_to_ddsi_time (int64_t t) -{ - if (t == DDS_NEVER) - return DDSI_TIME_INFINITE; - else - { - /* ceiling(ns * 2^32/10^9) -- can't change the ceiling to round-to-nearest - because that would break backwards compatibility, but round-to-nearest - of the inverse is correctly rounded anyway, so it shouldn't ever matter. */ - ddsi_time_t x; - int ns = (int) (t % DDS_NSECS_IN_SEC); - x.seconds = (int) (t / DDS_NSECS_IN_SEC); - x.fraction = (unsigned) (((DDS_NSECS_IN_SEC-1) + ((int64_t) ns << 32)) / DDS_NSECS_IN_SEC); - return x; - } -} - -ddsi_time_t nn_wctime_to_ddsi_time (nn_wctime_t t) -{ - return nn_to_ddsi_time (t.v); -} - -static int64_t nn_from_ddsi_time (ddsi_time_t x) -{ - if (x.seconds == DDSI_TIME_INFINITE.seconds && x.fraction == DDSI_TIME_INFINITE.fraction) - return DDS_NEVER; - else - { - /* Round-to-nearest conversion of DDSI time fraction to nanoseconds */ - int ns = (int) (((int64_t) 2147483648u + (int64_t) x.fraction * DDS_NSECS_IN_SEC) >> 32); - return x.seconds * DDS_NSECS_IN_SEC + ns; - } -} - -nn_wctime_t nn_wctime_from_ddsi_time (ddsi_time_t x) -{ - nn_wctime_t t; - t.v = nn_from_ddsi_time (x); - return t; -} - -ddsi_duration_t nn_to_ddsi_duration (int64_t x) -{ - return nn_to_ddsi_time (x); -} - -int64_t nn_from_ddsi_duration (ddsi_duration_t x) -{ - return nn_from_ddsi_time (x); -} - diff --git a/src/core/ddsi/src/q_transmit.c b/src/core/ddsi/src/q_transmit.c index 79cb661..8cd0508 100644 --- a/src/core/ddsi/src/q_transmit.c +++ b/src/core/ddsi/src/q_transmit.c @@ -25,7 +25,6 @@ #include "dds/ddsi/q_misc.h" #include "dds/ddsi/q_thread.h" #include "dds/ddsi/q_xevent.h" -#include "dds/ddsi/q_time.h" #include "dds/ddsi/q_config.h" #include "dds/ddsi/ddsi_domaingv.h" #include "dds/ddsi/q_transmit.h" @@ -58,12 +57,12 @@ void writer_hbcontrol_init (struct hbcontrol *hbc) hbc->t_of_last_write.v = 0; hbc->t_of_last_hb.v = 0; hbc->t_of_last_ackhb.v = 0; - hbc->tsched = NN_MTIME_NEVER; + hbc->tsched = DDSRT_MTIME_NEVER; hbc->hbs_since_last_write = 0; hbc->last_packetid = 0; } -static void writer_hbcontrol_note_hb (struct writer *wr, nn_mtime_t tnow, int ansreq) +static void writer_hbcontrol_note_hb (struct writer *wr, ddsrt_mtime_t tnow, int ansreq) { struct hbcontrol * const hbc = &wr->hbcontrol; @@ -77,7 +76,7 @@ static void writer_hbcontrol_note_hb (struct writer *wr, nn_mtime_t tnow, int an hbc->hbs_since_last_write++; } -int64_t writer_hbcontrol_intv (const struct writer *wr, const struct whc_state *whcst, UNUSED_ARG (nn_mtime_t tnow)) +int64_t writer_hbcontrol_intv (const struct writer *wr, const struct whc_state *whcst, UNUSED_ARG (ddsrt_mtime_t tnow)) { struct ddsi_domaingv const * const gv = wr->e.gv; struct hbcontrol const * const hbc = &wr->hbcontrol; @@ -103,11 +102,11 @@ int64_t writer_hbcontrol_intv (const struct writer *wr, const struct whc_state * return ret; } -void writer_hbcontrol_note_asyncwrite (struct writer *wr, nn_mtime_t tnow) +void writer_hbcontrol_note_asyncwrite (struct writer *wr, ddsrt_mtime_t tnow) { struct ddsi_domaingv const * const gv = wr->e.gv; struct hbcontrol * const hbc = &wr->hbcontrol; - nn_mtime_t tnext; + ddsrt_mtime_t tnext; /* Reset number of heartbeats since last write: that means the heartbeat rate will go back up to the default */ @@ -126,13 +125,13 @@ void writer_hbcontrol_note_asyncwrite (struct writer *wr, nn_mtime_t tnow) } } -int writer_hbcontrol_must_send (const struct writer *wr, const struct whc_state *whcst, nn_mtime_t tnow /* monotonic */) +int writer_hbcontrol_must_send (const struct writer *wr, const struct whc_state *whcst, ddsrt_mtime_t tnow /* monotonic */) { struct hbcontrol const * const hbc = &wr->hbcontrol; return (tnow.v >= hbc->t_of_last_hb.v + writer_hbcontrol_intv (wr, whcst, tnow)); } -struct nn_xmsg *writer_hbcontrol_create_heartbeat (struct writer *wr, const struct whc_state *whcst, nn_mtime_t tnow, int hbansreq, int issync) +struct nn_xmsg *writer_hbcontrol_create_heartbeat (struct writer *wr, const struct whc_state *whcst, ddsrt_mtime_t tnow, int hbansreq, int issync) { struct ddsi_domaingv const * const gv = wr->e.gv; struct nn_xmsg *msg; @@ -224,7 +223,7 @@ struct nn_xmsg *writer_hbcontrol_create_heartbeat (struct writer *wr, const stru return msg; } -static int writer_hbcontrol_ack_required_generic (const struct writer *wr, const struct whc_state *whcst, nn_mtime_t tlast, nn_mtime_t tnow, int piggyback) +static int writer_hbcontrol_ack_required_generic (const struct writer *wr, const struct whc_state *whcst, ddsrt_mtime_t tlast, ddsrt_mtime_t tnow, int piggyback) { struct ddsi_domaingv const * const gv = wr->e.gv; struct hbcontrol const * const hbc = &wr->hbcontrol; @@ -260,17 +259,17 @@ static int writer_hbcontrol_ack_required_generic (const struct writer *wr, const return 0; } -int writer_hbcontrol_ack_required (const struct writer *wr, const struct whc_state *whcst, nn_mtime_t tnow) +int writer_hbcontrol_ack_required (const struct writer *wr, const struct whc_state *whcst, ddsrt_mtime_t tnow) { struct hbcontrol const * const hbc = &wr->hbcontrol; return writer_hbcontrol_ack_required_generic (wr, whcst, hbc->t_of_last_write, tnow, 0); } -struct nn_xmsg *writer_hbcontrol_piggyback (struct writer *wr, const struct whc_state *whcst, nn_mtime_t tnow, uint32_t packetid, int *hbansreq) +struct nn_xmsg *writer_hbcontrol_piggyback (struct writer *wr, const struct whc_state *whcst, ddsrt_mtime_t tnow, uint32_t packetid, int *hbansreq) { struct hbcontrol * const hbc = &wr->hbcontrol; uint32_t last_packetid; - nn_mtime_t tlast; + ddsrt_mtime_t tlast; struct nn_xmsg *msg; tlast = hbc->t_of_last_write; @@ -332,7 +331,7 @@ void add_Heartbeat (struct nn_xmsg *msg, struct writer *wr, const struct whc_sta { /* If configured to measure heartbeat-to-ack latency, we must add a timestamp. No big deal if it fails. */ - nn_xmsg_add_timestamp (msg, now ()); + nn_xmsg_add_timestamp (msg, ddsrt_time_wallclock ()); } hb = nn_xmsg_append (msg, &sm_marker, sizeof (Heartbeat_t)); @@ -687,9 +686,9 @@ dds_return_t write_hb_liveliness (struct ddsi_domaingv * const gv, struct ddsi_g } if (wr->xqos->liveliness.kind == DDS_LIVELINESS_MANUAL_BY_PARTICIPANT && ((lease = ddsrt_atomic_ldvoidp (&wr->c.pp->minl_man)) != NULL)) - lease_renew (lease, now_et()); + lease_renew (lease, ddsrt_time_elapsed()); else if (wr->xqos->liveliness.kind == DDS_LIVELINESS_MANUAL_BY_TOPIC && wr->lease != NULL) - lease_renew (wr->lease, now_et()); + lease_renew (wr->lease, ddsrt_time_elapsed()); if ((msg = nn_xmsg_new (gv->xmsgpool, &wr->e.guid.prefix, sizeof (InfoTS_t) + sizeof (Heartbeat_t), NN_XMSG_KIND_CONTROL)) == NULL) return DDS_RETCODE_OUT_OF_RESOURCES; @@ -920,13 +919,13 @@ static int insert_sample_in_whc (struct writer *wr, seqno_t seq, struct ddsi_pli if ((wr->reliable && have_reliable_subs (wr)) || wr_deadline || wr->handle_as_transient_local) { - nn_mtime_t exp = NN_MTIME_NEVER; + ddsrt_mtime_t exp = DDSRT_MTIME_NEVER; #ifdef DDSI_INCLUDE_LIFESPAN /* Don't set expiry for samples with flags unregister or dispose, because these are required * for sample lifecycle and should always be delivered to the reader so that is can clean up * its history cache. */ if (wr->xqos->lifespan.duration != DDS_INFINITY && (serdata->statusinfo & (NN_STATUSINFO_UNREGISTER | NN_STATUSINFO_DISPOSE)) == 0) - exp = add_duration_to_mtime(serdata->twrite, wr->xqos->lifespan.duration); + exp = ddsrt_mtime_add_duration(serdata->twrite, wr->xqos->lifespan.duration); #endif res = ((insres = whc_insert (wr->whc, writer_max_drop_seq (wr), seq, exp, plist, serdata, tk)) < 0) ? insres : 1; @@ -999,8 +998,8 @@ static dds_return_t throttle_writer (struct thread_state1 * const ts1, struct nn writer. */ struct ddsi_domaingv const * const gv = wr->e.gv; dds_return_t result = DDS_RETCODE_OK; - nn_mtime_t tnow = now_mt (); - const nn_mtime_t abstimeout = add_duration_to_mtime (tnow, wr->xqos->reliability.max_blocking_time); + ddsrt_mtime_t tnow = ddsrt_time_monotonic (); + const ddsrt_mtime_t abstimeout = ddsrt_mtime_add_duration (tnow, wr->xqos->reliability.max_blocking_time); struct whc_state whcst; whc_get_state (wr->whc, &whcst); @@ -1036,7 +1035,7 @@ static dds_return_t throttle_writer (struct thread_state1 * const ts1, struct nn while (ddsrt_atomic_ld32 (&gv->rtps_keepgoing) && !writer_may_continue (wr, &whcst)) { int64_t reltimeout; - tnow = now_mt (); + tnow = ddsrt_time_monotonic (); reltimeout = abstimeout.v - tnow.v; result = DDS_RETCODE_TIMEOUT; if (reltimeout > 0) @@ -1071,8 +1070,8 @@ static int maybe_grow_whc (struct writer *wr) struct ddsi_domaingv const * const gv = wr->e.gv; if (!wr->retransmitting && gv->config.whc_adaptive && wr->whc_high < gv->config.whc_highwater_mark) { - nn_etime_t tnow = now_et(); - nn_etime_t tgrow = add_duration_to_etime (wr->t_whc_high_upd, DDS_MSECS (10)); + ddsrt_etime_t tnow = ddsrt_time_elapsed(); + ddsrt_etime_t tgrow = ddsrt_etime_add_duration (wr->t_whc_high_upd, DDS_MSECS (10)); if (tnow.v >= tgrow.v) { uint32_t m = (gv->config.whc_highwater_mark - wr->whc_high) / 32; @@ -1089,7 +1088,7 @@ static int write_sample_eot (struct thread_state1 * const ts1, struct nn_xpack * struct ddsi_domaingv const * const gv = wr->e.gv; int r; seqno_t seq; - nn_mtime_t tnow; + ddsrt_mtime_t tnow; struct lease *lease; /* If GC not allowed, we must be sure to never block when writing. That is only the case for (true, aggressive) KEEP_LAST writers, and also only if there is no limit to how much unacknowledged data the WHC may contain. */ @@ -1113,9 +1112,9 @@ static int write_sample_eot (struct thread_state1 * const ts1, struct nn_xpack * } if (wr->xqos->liveliness.kind == DDS_LIVELINESS_MANUAL_BY_PARTICIPANT && ((lease = ddsrt_atomic_ldvoidp (&wr->c.pp->minl_man)) != NULL)) - lease_renew (lease, now_et()); + lease_renew (lease, ddsrt_time_elapsed()); else if (wr->xqos->liveliness.kind == DDS_LIVELINESS_MANUAL_BY_TOPIC && wr->lease != NULL) - lease_renew (wr->lease, now_et()); + lease_renew (wr->lease, ddsrt_time_elapsed()); ddsrt_mutex_lock (&wr->e.lock); @@ -1162,7 +1161,7 @@ static int write_sample_eot (struct thread_state1 * const ts1, struct nn_xpack * } /* Always use the current monotonic time */ - tnow = now_mt (); + tnow = ddsrt_time_monotonic (); serdata->twrite = tnow; seq = ++wr->seq; diff --git a/src/core/ddsi/src/q_whc.c b/src/core/ddsi/src/q_whc.c index 457045d..7cc86fd 100644 --- a/src/core/ddsi/src/q_whc.c +++ b/src/core/ddsi/src/q_whc.c @@ -10,7 +10,6 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include "dds/ddsi/q_rtps.h" -#include "dds/ddsi/q_time.h" #include "dds/ddsi/q_whc.h" extern inline seqno_t whc_next_seq (const struct whc *whc, seqno_t seq); @@ -21,7 +20,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, nn_mtime_t exp, struct ddsi_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk); +extern int whc_insert (struct whc *whc, seqno_t max_drop_seq, seqno_t seq, ddsrt_mtime_t exp, struct ddsi_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); diff --git a/src/core/ddsi/src/q_xevent.c b/src/core/ddsi/src/q_xevent.c index 4fa7554..54bdb22 100644 --- a/src/core/ddsi/src/q_xevent.c +++ b/src/core/ddsi/src/q_xevent.c @@ -19,7 +19,6 @@ #include "dds/ddsrt/avl.h" #include "dds/ddsrt/fibheap.h" -#include "dds/ddsi/q_time.h" #include "dds/ddsi/q_log.h" #include "dds/ddsi/q_addrset.h" #include "dds/ddsi/q_xmsg.h" @@ -66,7 +65,7 @@ struct xevent { ddsrt_fibheap_node_t heapnode; struct xeventq *evq; - nn_mtime_t tsched; + ddsrt_mtime_t tsched; enum xeventkind kind; union { struct { @@ -92,7 +91,7 @@ struct xevent ddsi_guid_t guid; } delete_writer; struct { - void (*cb) (struct xevent *ev, void *arg, nn_mtime_t tnow); + void (*cb) (struct xevent *ev, void *arg, ddsrt_mtime_t tnow); void *arg; bool executing; } callback; @@ -152,7 +151,7 @@ struct xeventq { }; static uint32_t xevent_thread (struct xeventq *xevq); -static nn_mtime_t earliest_in_xeventq (struct xeventq *evq); +static ddsrt_mtime_t earliest_in_xeventq (struct xeventq *evq); static int msg_xevents_cmp (const void *a, const void *b); static int compare_xevent_tsched (const void *va, const void *vb); static void handle_nontimed_xevent (struct xevent_nt *xev, struct nn_xpack *xp); @@ -360,7 +359,7 @@ void delete_xevent_callback (struct xevent *ev) free_xevent (evq, ev); } -int resched_xevent_if_earlier (struct xevent *ev, nn_mtime_t tsched) +int resched_xevent_if_earlier (struct xevent *ev, ddsrt_mtime_t tsched) { struct xeventq *evq = ev->evq; int is_resched; @@ -376,7 +375,7 @@ int resched_xevent_if_earlier (struct xevent *ev, nn_mtime_t tsched) is_resched = 0; else { - nn_mtime_t tbefore = earliest_in_xeventq (evq); + ddsrt_mtime_t tbefore = earliest_in_xeventq (evq); if (ev->tsched.v != DDS_NEVER) { ev->tsched = tsched; @@ -395,7 +394,25 @@ int resched_xevent_if_earlier (struct xevent *ev, nn_mtime_t tsched) return is_resched; } -static struct xevent *qxev_common (struct xeventq *evq, nn_mtime_t tsched, enum xeventkind kind) +static ddsrt_mtime_t mtime_round_up (ddsrt_mtime_t t, int64_t round) +{ + /* This function rounds up t to the nearest next multiple of round. + t is nanoseconds, round is milliseconds. Avoid functions from + maths libraries to keep code portable */ + assert (t.v >= 0 && round >= 0); + if (round == 0 || t.v == DDS_INFINITY) + return t; + else + { + int64_t remainder = t.v % round; + if (remainder == 0) + return t; + else + return (ddsrt_mtime_t) { t.v + round - remainder }; + } +} + +static struct xevent *qxev_common (struct xeventq *evq, ddsrt_mtime_t tsched, enum xeventkind kind) { /* qxev_common is the route by which all timed xevents are created. */ @@ -407,7 +424,7 @@ static struct xevent *qxev_common (struct xeventq *evq, nn_mtime_t tsched, enum /* round up the scheduled time if required */ if (tsched.v != DDS_NEVER && evq->gv->config.schedule_time_rounding != 0) { - nn_mtime_t tsched_rounded = mtime_round_up (tsched, evq->gv->config.schedule_time_rounding); + ddsrt_mtime_t tsched_rounded = mtime_round_up (tsched, evq->gv->config.schedule_time_rounding); EVQTRACE ("rounded event scheduled for %"PRId64" to %"PRId64"\n", tsched.v, tsched_rounded.v); tsched = tsched_rounded; } @@ -427,11 +444,11 @@ static struct xevent_nt *qxev_common_nt (struct xeventq *evq, enum xeventkind_nt return ev; } -static nn_mtime_t earliest_in_xeventq (struct xeventq *evq) +static ddsrt_mtime_t earliest_in_xeventq (struct xeventq *evq) { struct xevent *min; ASSERT_MUTEX_HELD (&evq->lock); - return ((min = ddsrt_fibheap_min (&evq_xevents_fhdef, &evq->xevents)) != NULL) ? min->tsched : NN_MTIME_NEVER; + return ((min = ddsrt_fibheap_min (&evq_xevents_fhdef, &evq->xevents)) != NULL) ? min->tsched : DDSRT_MTIME_NEVER; } static void qxev_insert (struct xevent *ev) @@ -442,7 +459,7 @@ static void qxev_insert (struct xevent *ev) ASSERT_MUTEX_HELD (&evq->lock); if (ev->tsched.v != DDS_NEVER) { - nn_mtime_t tbefore = earliest_in_xeventq (evq); + ddsrt_mtime_t tbefore = earliest_in_xeventq (evq); ddsrt_fibheap_insert (&evq_xevents_fhdef, &evq->xevents, ev); if (ev->tsched.v < tbefore.v) ddsrt_cond_broadcast (&evq->cond); @@ -584,12 +601,12 @@ static void handle_xevk_entityid (struct nn_xpack *xp, struct xevent_nt *ev) nn_xpack_addmsg (xp, ev->u.entityid.msg, 0); } -static void handle_xevk_heartbeat (struct nn_xpack *xp, struct xevent *ev, nn_mtime_t tnow /* monotonic */) +static void handle_xevk_heartbeat (struct nn_xpack *xp, struct xevent *ev, ddsrt_mtime_t tnow /* monotonic */) { struct ddsi_domaingv const * const gv = ev->evq->gv; struct nn_xmsg *msg; struct writer *wr; - nn_mtime_t t_next; + ddsrt_mtime_t t_next; int hbansreq = 0; struct whc_state whcst; @@ -846,7 +863,7 @@ static void add_AckNack (struct nn_xmsg *msg, struct proxy_writer *pwr, struct p ETRACE (pwr, "\n"); } -static void handle_xevk_acknack (UNUSED_ARG (struct nn_xpack *xp), struct xevent *ev, nn_mtime_t tnow) +static void handle_xevk_acknack (UNUSED_ARG (struct nn_xpack *xp), struct xevent *ev, ddsrt_mtime_t tnow) { /* FIXME: ought to keep track of which NACKs are being generated in response to a Heartbeat. There is no point in having multiple @@ -901,7 +918,7 @@ static void handle_xevk_acknack (UNUSED_ARG (struct nn_xpack *xp), struct xevent HEARTBEAT, I've seen too many cases of not sending an NACK because the writing side got confused ... Better to recover eventually. */ - (void) resched_xevent_if_earlier (ev, add_duration_to_mtime (tnow, gv->config.auto_resched_nack_delay)); + (void) resched_xevent_if_earlier (ev, ddsrt_mtime_add_duration (tnow, gv->config.auto_resched_nack_delay)); } GVTRACE ("send acknack(rd "PGUIDFMT" -> pwr "PGUIDFMT")\n", PGUID (ev->u.acknack.rd_guid), PGUID (ev->u.acknack.pwr_guid)); @@ -927,7 +944,7 @@ static void handle_xevk_acknack (UNUSED_ARG (struct nn_xpack *xp), struct xevent intv = 5; else intv = 10; - (void) resched_xevent_if_earlier (ev, add_duration_to_mtime (tnow, intv * DDS_NSECS_IN_SEC)); + (void) resched_xevent_if_earlier (ev, ddsrt_mtime_add_duration (tnow, intv * DDS_NSECS_IN_SEC)); } ddsrt_mutex_unlock (&pwr->e.lock); @@ -940,7 +957,7 @@ static void handle_xevk_acknack (UNUSED_ARG (struct nn_xpack *xp), struct xevent outofmem: /* What to do if out of memory? Crash or burn? */ ddsrt_mutex_unlock (&pwr->e.lock); - (void) resched_xevent_if_earlier (ev, add_duration_to_mtime (tnow, DDS_MSECS (100))); + (void) resched_xevent_if_earlier (ev, ddsrt_mtime_add_duration (tnow, DDS_MSECS (100))); } static bool resend_spdp_sample_by_guid_key (struct writer *wr, const ddsi_guid_t *guid, struct proxy_reader *prd) @@ -981,7 +998,7 @@ static bool resend_spdp_sample_by_guid_key (struct writer *wr, const ddsi_guid_t return sample_found; } -static void handle_xevk_spdp (UNUSED_ARG (struct nn_xpack *xp), struct xevent *ev, nn_mtime_t tnow) +static void handle_xevk_spdp (UNUSED_ARG (struct nn_xpack *xp), struct xevent *ev, ddsrt_mtime_t tnow) { /* Like the writer pointer in the heartbeat event, the participant pointer in the spdp event is assumed valid. */ struct ddsi_domaingv *gv = ev->evq->gv; @@ -1060,7 +1077,7 @@ static void handle_xevk_spdp (UNUSED_ARG (struct nn_xpack *xp), struct xevent *e delete_xevent (ev); else { - nn_mtime_t tnext = add_duration_to_mtime (tnow, DDS_SECS (1)); + ddsrt_mtime_t tnext = ddsrt_mtime_add_duration (tnow, DDS_SECS (1)); GVTRACE ("xmit spdp "PGUIDFMT" to %"PRIx32":%"PRIx32":%"PRIx32":%x (resched %gs)\n", PGUID (pp->e.guid), PGUIDPREFIX (ev->u.spdp.dest_proxypp_guid_prefix), NN_ENTITYID_SPDP_BUILTIN_PARTICIPANT_READER, @@ -1075,7 +1092,7 @@ static void handle_xevk_spdp (UNUSED_ARG (struct nn_xpack *xp), struct xevent *e but never wait longer than spdp_interval */ const dds_duration_t mindelta = DDS_MSECS (10); const dds_duration_t ldur = pp->lease_duration; - nn_mtime_t tnext; + ddsrt_mtime_t tnext; int64_t intv; if (ldur < 5 * mindelta / 4) @@ -1087,7 +1104,7 @@ static void handle_xevk_spdp (UNUSED_ARG (struct nn_xpack *xp), struct xevent *e if (intv > gv->config.spdp_interval) intv = gv->config.spdp_interval; - tnext = add_duration_to_mtime (tnow, intv); + tnext = ddsrt_mtime_add_duration (tnow, intv); GVTRACE ("xmit spdp "PGUIDFMT" to %"PRIx32":%"PRIx32":%"PRIx32":%x (resched %gs)\n", PGUID (pp->e.guid), PGUIDPREFIX (ev->u.spdp.dest_proxypp_guid_prefix), NN_ENTITYID_SPDP_BUILTIN_PARTICIPANT_READER, @@ -1096,12 +1113,12 @@ static void handle_xevk_spdp (UNUSED_ARG (struct nn_xpack *xp), struct xevent *e } } -static void handle_xevk_pmd_update (struct thread_state1 * const ts1, struct nn_xpack *xp, struct xevent *ev, nn_mtime_t tnow) +static void handle_xevk_pmd_update (struct thread_state1 * const ts1, struct nn_xpack *xp, struct xevent *ev, ddsrt_mtime_t tnow) { struct ddsi_domaingv * const gv = ev->evq->gv; struct participant *pp; dds_duration_t intv; - nn_mtime_t tnext; + ddsrt_mtime_t tnext; if ((pp = entidx_lookup_participant_guid (gv->entity_index, &ev->u.pmd_update.pp_guid)) == NULL) { @@ -1130,7 +1147,7 @@ static void handle_xevk_pmd_update (struct thread_state1 * const ts1, struct nn_ (void) resched_xevent_if_earlier (ev, tnext); } -static void handle_xevk_delete_writer (UNUSED_ARG (struct nn_xpack *xp), struct xevent *ev, UNUSED_ARG (nn_mtime_t tnow)) +static void handle_xevk_delete_writer (UNUSED_ARG (struct nn_xpack *xp), struct xevent *ev, UNUSED_ARG (ddsrt_mtime_t tnow)) { /* don't worry if the writer is already gone by the time we get here. */ struct ddsi_domaingv * const gv = ev->evq->gv; @@ -1139,7 +1156,7 @@ static void handle_xevk_delete_writer (UNUSED_ARG (struct nn_xpack *xp), struct delete_xevent (ev); } -static void handle_individual_xevent (struct thread_state1 * const ts1, struct xevent *xev, struct nn_xpack *xp, nn_mtime_t tnow) +static void handle_individual_xevent (struct thread_state1 * const ts1, struct xevent *xev, struct nn_xpack *xp, ddsrt_mtime_t tnow) { struct xeventq *xevq = xev->evq; /* We relinquish the lock while processing the event, but require it @@ -1200,7 +1217,7 @@ static void handle_individual_xevent_nt (struct xevent_nt *xev, struct nn_xpack ddsrt_free (xev); } -static void handle_timed_xevent (struct thread_state1 * const ts1, struct xevent *xev, struct nn_xpack *xp, nn_mtime_t tnow /* monotonic */) +static void handle_timed_xevent (struct thread_state1 * const ts1, struct xevent *xev, struct nn_xpack *xp, ddsrt_mtime_t tnow /* monotonic */) { /* This function handles the individual xevent irrespective of whether it is a "timed" or "non-timed" xevent */ @@ -1228,7 +1245,7 @@ static void handle_nontimed_xevent (struct xevent_nt *xev, struct nn_xpack *xp) ASSERT_MUTEX_HELD (&xevq->lock); } -static void handle_xevents (struct thread_state1 * const ts1, struct xeventq *xevq, struct nn_xpack *xp, nn_mtime_t tnow /* monotonic */) +static void handle_xevents (struct thread_state1 * const ts1, struct xeventq *xevq, struct nn_xpack *xp, ddsrt_mtime_t tnow /* monotonic */) { int xeventsToProcess = 1; @@ -1265,7 +1282,7 @@ static void handle_xevents (struct thread_state1 * const ts1, struct xeventq *xe /* Limited-bandwidth channels means events can take a LONG time to process. So read the clock more often. */ - tnow = now_mt (); + tnow = ddsrt_time_monotonic (); } if (!non_timed_xmit_list_is_empty (xevq)) @@ -1273,7 +1290,7 @@ static void handle_xevents (struct thread_state1 * const ts1, struct xeventq *xe struct xevent_nt *xev = getnext_from_non_timed_xmit_list (xevq); thread_state_awake_to_awake_no_nest (ts1); handle_nontimed_xevent (xev, xp); - tnow = now_mt (); + tnow = ddsrt_time_monotonic (); } else { @@ -1288,14 +1305,14 @@ static uint32_t xevent_thread (struct xeventq * xevq) { struct thread_state1 * const ts1 = lookup_thread_state (); struct nn_xpack *xp; - nn_mtime_t next_thread_cputime = { 0 }; + ddsrt_mtime_t next_thread_cputime = { 0 }; xp = nn_xpack_new (xevq->tev_conn, xevq->auxiliary_bandwidth_limit, xevq->gv->config.xpack_send_async); ddsrt_mutex_lock (&xevq->lock); while (!xevq->terminate) { - nn_mtime_t tnow = now_mt (); + ddsrt_mtime_t tnow = ddsrt_time_monotonic (); LOG_THREAD_CPUTIME (&xevq->gv->logconfig, next_thread_cputime); @@ -1313,7 +1330,7 @@ static uint32_t xevent_thread (struct xeventq * xevq) } else { - nn_mtime_t twakeup = earliest_in_xeventq (xevq); + ddsrt_mtime_t twakeup = earliest_in_xeventq (xevq); if (twakeup.v == DDS_NEVER) { /* no scheduled events nor any non-timed events */ @@ -1325,7 +1342,7 @@ static uint32_t xevent_thread (struct xeventq * xevq) don't want to sleep much longer than we have to. With os_condTimedWait requiring a relative time, we don't have much choice but to read the clock now */ - tnow = now_mt (); + tnow = ddsrt_time_monotonic (); if (twakeup.v > tnow.v) { twakeup.v -= tnow.v; /* ddsrt_cond_waitfor: relative timeout */ @@ -1453,7 +1470,7 @@ int qxev_msg_rexmit_wrlock_held (struct xeventq *evq, struct nn_xmsg *msg, int f } } -struct xevent *qxev_heartbeat (struct xeventq *evq, nn_mtime_t tsched, const ddsi_guid_t *wr_guid) +struct xevent *qxev_heartbeat (struct xeventq *evq, ddsrt_mtime_t tsched, const ddsi_guid_t *wr_guid) { /* Event _must_ be deleted before enough of the writer is freed to cause trouble. Currently used exclusively for @@ -1468,7 +1485,7 @@ struct xevent *qxev_heartbeat (struct xeventq *evq, nn_mtime_t tsched, const dds return ev; } -struct xevent *qxev_acknack (struct xeventq *evq, nn_mtime_t tsched, const ddsi_guid_t *pwr_guid, const ddsi_guid_t *rd_guid) +struct xevent *qxev_acknack (struct xeventq *evq, ddsrt_mtime_t tsched, const ddsi_guid_t *pwr_guid, const ddsi_guid_t *rd_guid) { struct xevent *ev; assert(evq); @@ -1481,7 +1498,7 @@ struct xevent *qxev_acknack (struct xeventq *evq, nn_mtime_t tsched, const ddsi_ return ev; } -struct xevent *qxev_spdp (struct xeventq *evq, nn_mtime_t tsched, const ddsi_guid_t *pp_guid, const ddsi_guid_t *dest_proxypp_guid) +struct xevent *qxev_spdp (struct xeventq *evq, ddsrt_mtime_t tsched, const ddsi_guid_t *pp_guid, const ddsi_guid_t *dest_proxypp_guid) { struct xevent *ev; ddsrt_mutex_lock (&evq->lock); @@ -1499,7 +1516,7 @@ struct xevent *qxev_spdp (struct xeventq *evq, nn_mtime_t tsched, const ddsi_gui return ev; } -struct xevent *qxev_pmd_update (struct xeventq *evq, nn_mtime_t tsched, const ddsi_guid_t *pp_guid) +struct xevent *qxev_pmd_update (struct xeventq *evq, ddsrt_mtime_t tsched, const ddsi_guid_t *pp_guid) { struct xevent *ev; ddsrt_mutex_lock (&evq->lock); @@ -1510,7 +1527,7 @@ struct xevent *qxev_pmd_update (struct xeventq *evq, nn_mtime_t tsched, const dd return ev; } -struct xevent *qxev_delete_writer (struct xeventq *evq, nn_mtime_t tsched, const ddsi_guid_t *guid) +struct xevent *qxev_delete_writer (struct xeventq *evq, ddsrt_mtime_t tsched, const ddsi_guid_t *guid) { struct xevent *ev; ddsrt_mutex_lock (&evq->lock); @@ -1521,7 +1538,7 @@ struct xevent *qxev_delete_writer (struct xeventq *evq, nn_mtime_t tsched, const return ev; } -struct xevent *qxev_callback (struct xeventq *evq, nn_mtime_t tsched, void (*cb) (struct xevent *ev, void *arg, nn_mtime_t tnow), void *arg) +struct xevent *qxev_callback (struct xeventq *evq, ddsrt_mtime_t tsched, void (*cb) (struct xevent *ev, void *arg, ddsrt_mtime_t tnow), void *arg) { struct xevent *ev; ddsrt_mutex_lock (&evq->lock); diff --git a/src/core/ddsi/src/q_xmsg.c b/src/core/ddsi/src/q_xmsg.c index ef76893..c897550 100644 --- a/src/core/ddsi/src/q_xmsg.c +++ b/src/core/ddsi/src/q_xmsg.c @@ -538,14 +538,14 @@ void nn_xmsg_shrink (struct nn_xmsg *m, struct nn_xmsg_marker marker, size_t sz) m->sz = marker.offset + sz; } -void nn_xmsg_add_timestamp (struct nn_xmsg *m, nn_wctime_t t) +void nn_xmsg_add_timestamp (struct nn_xmsg *m, ddsrt_wctime_t t) { InfoTimestamp_t * ts; struct nn_xmsg_marker sm; ts = (InfoTimestamp_t*) nn_xmsg_append (m, &sm, sizeof (InfoTimestamp_t)); nn_xmsg_submsg_init (m, sm, SMID_INFO_TS); - ts->time = nn_wctime_to_ddsi_time (t); + ts->time = ddsi_wctime_to_ddsi_time (t); nn_xmsg_submsg_setnext (m, sm); } diff --git a/src/core/xtests/rhc_torture/rhc_torture.c b/src/core/xtests/rhc_torture/rhc_torture.c index b662b7a..fe9dc53 100644 --- a/src/core/xtests/rhc_torture/rhc_torture.c +++ b/src/core/xtests/rhc_torture/rhc_torture.c @@ -108,9 +108,9 @@ static struct ddsi_serdata *mkkeysample (int32_t keyval, unsigned statusinfo) } #if defined(DDSI_INCLUDE_LIFESPAN) || defined (DDSI_INCLUDE_DEADLINE_MISSED) -static nn_mtime_t rand_texp () +static ddsrt_mtime_t rand_texp () { - nn_mtime_t ret = now_mt(); + ddsrt_mtime_t ret = ddsrt_time_monotonic(); ret.v -= DDS_MSECS(500) + (int64_t) (ddsrt_prng_random (&prng) % DDS_MSECS(1500)); return ret; } @@ -158,7 +158,7 @@ static uint64_t store (struct ddsi_tkmap *tkmap, struct dds_rhc *rhc, struct pro if (lifespan_expiry && (sd->statusinfo & (NN_STATUSINFO_UNREGISTER | NN_STATUSINFO_DISPOSE)) == 0) pwr_info.lifespan_exp = rand_texp(); else - pwr_info.lifespan_exp = NN_MTIME_NEVER; + pwr_info.lifespan_exp = DDSRT_MTIME_NEVER; #endif dds_rhc_store (rhc, &pwr_info, sd, tk); ddsi_tkmap_instance_unref (tkmap, tk); @@ -831,7 +831,7 @@ static void test_conditions (dds_entity_t pp, dds_entity_t tp, const int count, wr_info.iid = wr[which]->e.iid; wr_info.ownership_strength = wr[which]->c.xqos->ownership_strength.value; #ifdef DDSI_INCLUDE_LIFESPAN - wr_info.lifespan_exp = NN_MTIME_NEVER; + wr_info.lifespan_exp = DDSRT_MTIME_NEVER; #endif for (size_t k = 0; k < nrd; k++) dds_rhc_unregister_wr (rhc[k], &wr_info); @@ -962,7 +962,7 @@ int main (int argc, char **argv) wr0_info.iid = wr0->e.iid; wr0_info.ownership_strength = wr0->c.xqos->ownership_strength.value; #ifdef DDSI_INCLUDE_LIFESPAN - wr0_info.lifespan_exp = NN_MTIME_NEVER; + wr0_info.lifespan_exp = DDSRT_MTIME_NEVER; #endif dds_rhc_unregister_wr (rhc, &wr0_info); thread_state_asleep (lookup_thread_state ()); diff --git a/src/ddsrt/include/dds/ddsrt/time.h b/src/ddsrt/include/dds/ddsrt/time.h index 61992f8..224862e 100644 --- a/src/ddsrt/include/dds/ddsrt/time.h +++ b/src/ddsrt/include/dds/ddsrt/time.h @@ -21,6 +21,7 @@ #define DDS_TIME_H #include +#include #include "dds/export.h" #include "dds/ddsrt/types.h" @@ -69,6 +70,23 @@ typedef int64_t dds_duration_t; #define DDS_USECS(n) ((n) * DDS_NSECS_IN_USEC) /** @}*/ +typedef struct { + dds_time_t v; +} ddsrt_mtime_t; + +typedef struct { + dds_time_t v; +} ddsrt_wctime_t; + +typedef struct { + dds_time_t v; +} ddsrt_etime_t; + +#define DDSRT_MTIME_NEVER ((ddsrt_mtime_t) { DDS_NEVER }) +#define DDSRT_WCTIME_NEVER ((ddsrt_wctime_t) { DDS_NEVER }) +#define DDSRT_ETIME_NEVER ((ddsrt_etime_t) { DDS_NEVER }) +#define DDSRT_WCTIME_INVALID ((ddsrt_wctime_t) { INT64_MIN }) + /** * @brief Get the current time in nanoseconds since the UNIX Epoch. * @@ -86,6 +104,14 @@ DDS_EXPORT dds_time_t dds_time(void); */ DDS_EXPORT void dds_sleepfor (dds_duration_t reltime); +/** + * @brief Get the current time in nanoseconds since the UNIX Epoch. Identical + * to (ddsrt_wctime_t){dds_time()} + * + * @returns Curren time. + */ +DDS_EXPORT ddsrt_wctime_t ddsrt_time_wallclock(void); + /** * @brief Get high resolution, monotonic time. * @@ -99,7 +125,7 @@ DDS_EXPORT void dds_sleepfor (dds_duration_t reltime); * * @returns Monotonic time if available, otherwise real time. */ -DDS_EXPORT dds_time_t ddsrt_time_monotonic(void); +DDS_EXPORT ddsrt_mtime_t ddsrt_time_monotonic(void); /** * @brief Get high resolution, elapsed (and thus monotonic) time since some @@ -113,7 +139,7 @@ DDS_EXPORT dds_time_t ddsrt_time_monotonic(void); * * @returns Elapsed time if available, otherwise return monotonic time. */ -DDS_EXPORT dds_time_t ddsrt_time_elapsed(void); +DDS_EXPORT ddsrt_etime_t ddsrt_time_elapsed(void); /** * @brief Convert time into a human readable string in RFC 3339 format. @@ -135,6 +161,131 @@ DDS_EXPORT dds_time_t ddsrt_time_elapsed(void); DDS_EXPORT size_t ddsrt_ctime(dds_time_t abstime, char *str, size_t size); +/** + * @brief Calculate a time given an offset time and a duration. + * + * Negative time can become positive by adding a large enough duration, of + * course a positive time can become negative given a large enough negative + * duration. + * + * @param[in] abstime Timestamp in nanoseconds since UNIX Epoch. + * @param[in] reltime Relative time in nanoseconds. + * + * @returns A timestamp in nanoseconds since UNIX Epoch. + */ +inline dds_time_t ddsrt_time_add_duration(dds_time_t abstime, dds_duration_t reltime) +{ + assert(abstime >= 0); + assert(reltime >= 0); + return (reltime >= DDS_NEVER - abstime ? DDS_NEVER : abstime + reltime); +} + +/** + * @brief Calculate a monotonic time given an offset time and a duration. + * + * Negative time can become positive by adding a large enough duration, of + * course a positive time can become negative given a large enough negative + * duration. + * + * @param[in] abstime Timestamp in nanoseconds since UNIX Epoch. + * @param[in] reltime Relative time in nanoseconds. + * + * @returns A timestamp in nanoseconds since UNIX Epoch. + */ +inline ddsrt_mtime_t ddsrt_mtime_add_duration(ddsrt_mtime_t abstime, dds_duration_t reltime) { + return (ddsrt_mtime_t) { ddsrt_time_add_duration (abstime.v, reltime) }; +} + +/** + * @brief Calculate a wall-clock time given an offset time and a duration. + * + * Negative time can become positive by adding a large enough duration, of + * course a positive time can become negative given a large enough negative + * duration. + * + * @param[in] abstime Timestamp in nanoseconds since UNIX Epoch. + * @param[in] reltime Relative time in nanoseconds. + * + * @returns A timestamp in nanoseconds since UNIX Epoch. + */ +inline ddsrt_wctime_t ddsrt_wctime_add_duration(ddsrt_wctime_t abstime, dds_duration_t reltime) { + return (ddsrt_wctime_t) { ddsrt_time_add_duration (abstime.v, reltime) }; +} + +/** + * @brief Calculate an elapsed time given an offset time and a duration. + * + * Negative time can become positive by adding a large enough duration, of + * course a positive time can become negative given a large enough negative + * duration. + * + * @param[in] abstime Timestamp in nanoseconds since UNIX Epoch. + * @param[in] reltime Relative time in nanoseconds. + * + * @returns A timestamp in nanoseconds since UNIX Epoch. + */ +inline ddsrt_etime_t ddsrt_etime_add_duration(ddsrt_etime_t abstime, dds_duration_t reltime) { + return (ddsrt_etime_t) { ddsrt_time_add_duration (abstime.v, reltime) }; +} + +#if _WIN32 +/** + * @brief Convert a relative time to microseconds rounding up. + * + * @param[in] reltime Relative time to convert. + * + * @returns INFINITE if @reltime was @DDS_INIFINITY, relative time converted to + * microseconds otherwise. + */ +inline DWORD +ddsrt_duration_to_msecs_ceil(dds_duration_t reltime) +{ + if (reltime == DDS_INFINITY) { + return INFINITE; + } else if (reltime > 0) { + assert(INFINITE < (DDS_INFINITY / DDS_NSECS_IN_MSEC)); + dds_duration_t max_nsecs = (INFINITE - 1) * DDS_NSECS_IN_MSEC; + + if (reltime < (max_nsecs - (DDS_NSECS_IN_MSEC - 1))) { + reltime += (DDS_NSECS_IN_MSEC - 1); + } else { + reltime = max_nsecs; + } + + return (DWORD)(reltime / DDS_NSECS_IN_MSEC); + } + + return 0; +} +#endif + +/** + * @brief Convert monotonic time seconds & microseconds + * + * @param[in] t Monotonic time to convert + * @param[out] sec Seconds part + * @param[out] usec Microseconds part + */ +DDS_EXPORT void ddsrt_mtime_to_sec_usec (int32_t * __restrict sec, int32_t * __restrict usec, ddsrt_mtime_t t); + +/** + * @brief Convert wall-clock time seconds & microseconds + * + * @param[in] t Wall-clock time to convert + * @param[out] sec Seconds part + * @param[out] usec Microseconds part + */ +DDS_EXPORT void ddsrt_wctime_to_sec_usec (int32_t * __restrict sec, int32_t * __restrict usec, ddsrt_wctime_t t); + +/** + * @brief Convert elapsed time seconds & microseconds + * + * @param[in] t Elasped time to convert + * @param[out] sec Seconds part + * @param[out] usec Microseconds part + */ +DDS_EXPORT void ddsrt_etime_to_sec_usec (int32_t * __restrict sec, int32_t * __restrict usec, ddsrt_etime_t t); + #if defined(__cplusplus) } #endif diff --git a/src/ddsrt/src/process/windows/process.c b/src/ddsrt/src/process/windows/process.c index 65c5125..8fd942b 100644 --- a/src/ddsrt/src/process/windows/process.c +++ b/src/ddsrt/src/process/windows/process.c @@ -18,7 +18,6 @@ #include "dds/ddsrt/string.h" #include "dds/ddsrt/atomics.h" #include "dds/ddsrt/process.h" -#include "dds/ddsrt/timeconv.h" ddsrt_pid_t diff --git a/src/ddsrt/src/sync/freertos/sync.c b/src/ddsrt/src/sync/freertos/sync.c index f38b0c2..2f024ee 100644 --- a/src/ddsrt/src/sync/freertos/sync.c +++ b/src/ddsrt/src/sync/freertos/sync.c @@ -19,7 +19,7 @@ #include "dds/ddsrt/heap.h" #include "dds/ddsrt/log.h" #include "dds/ddsrt/sync.h" -#include "dds/ddsrt/timeconv.h" +#include "dds/ddsrt/time.h" void ddsrt_mutex_init(ddsrt_mutex_t *mutex) { diff --git a/src/ddsrt/src/sync/posix/sync.c b/src/ddsrt/src/sync/posix/sync.c index ff03c52..a7f92e8 100644 --- a/src/ddsrt/src/sync/posix/sync.c +++ b/src/ddsrt/src/sync/posix/sync.c @@ -18,7 +18,7 @@ #include #include "dds/ddsrt/sync.h" -#include "dds/ddsrt/timeconv.h" +#include "dds/ddsrt/time.h" void ddsrt_mutex_init (ddsrt_mutex_t *mutex) { diff --git a/src/ddsrt/src/sync/solaris2.6/sync.c b/src/ddsrt/src/sync/solaris2.6/sync.c index 884f597..a3731bd 100644 --- a/src/ddsrt/src/sync/solaris2.6/sync.c +++ b/src/ddsrt/src/sync/solaris2.6/sync.c @@ -18,7 +18,7 @@ #include #include "dds/ddsrt/sync.h" -#include "dds/ddsrt/timeconv.h" +#include "dds/ddsrt/time.h" void ddsrt_mutex_init (ddsrt_mutex_t *mutex) { diff --git a/src/ddsrt/src/sync/windows/sync.c b/src/ddsrt/src/sync/windows/sync.c index b069239..4657f91 100644 --- a/src/ddsrt/src/sync/windows/sync.c +++ b/src/ddsrt/src/sync/windows/sync.c @@ -13,7 +13,7 @@ #include #include "dds/ddsrt/sync.h" -#include "dds/ddsrt/timeconv.h" +#include "dds/ddsrt/time.h" void ddsrt_mutex_init(ddsrt_mutex_t *mutex) { diff --git a/src/ddsrt/src/time.c b/src/ddsrt/src/time.c index 8dfa587..f5043df 100644 --- a/src/ddsrt/src/time.c +++ b/src/ddsrt/src/time.c @@ -12,11 +12,14 @@ #include #include -#include "dds/ddsrt/timeconv.h" +#include "dds/ddsrt/time.h" #include "dds/ddsrt/string.h" +#include "dds/ddsrt/static_assert.h" -extern inline dds_time_t -ddsrt_time_add_duration(dds_time_t abstime, dds_duration_t reltime); +extern inline dds_time_t ddsrt_time_add_duration(dds_time_t abstime, dds_duration_t reltime); +extern inline ddsrt_mtime_t ddsrt_mtime_add_duration(ddsrt_mtime_t abstime, dds_duration_t reltime); +extern inline ddsrt_wctime_t ddsrt_wctime_add_duration(ddsrt_wctime_t abstime, dds_duration_t reltime); +extern inline ddsrt_etime_t ddsrt_etime_add_duration(ddsrt_etime_t abstime, dds_duration_t reltime); #if !_WIN32 && !DDSRT_WITH_FREERTOS #include @@ -71,3 +74,23 @@ ddsrt_ctime(dds_time_t n, char *str, size_t size) return ddsrt_strlcpy(str, buf, size); } +static void time_to_sec_usec (int32_t * __restrict sec, int32_t * __restrict usec, int64_t t) +{ + *sec = (int32_t) (t / DDS_NSECS_IN_SEC); + *usec = (int32_t) (t % DDS_NSECS_IN_SEC) / 1000; +} + +void ddsrt_mtime_to_sec_usec (int32_t * __restrict sec, int32_t * __restrict usec, ddsrt_mtime_t t) +{ + time_to_sec_usec (sec, usec, t.v); +} + +void ddsrt_wctime_to_sec_usec (int32_t * __restrict sec, int32_t * __restrict usec, ddsrt_wctime_t t) +{ + time_to_sec_usec (sec, usec, t.v); +} + +void ddsrt_etime_to_sec_usec (int32_t * __restrict sec, int32_t * __restrict usec, ddsrt_etime_t t) +{ + time_to_sec_usec (sec, usec, t.v); +} diff --git a/src/ddsrt/src/time/darwin/time.c b/src/ddsrt/src/time/darwin/time.c index eda70f9..9e4c894 100644 --- a/src/ddsrt/src/time/darwin/time.c +++ b/src/ddsrt/src/time/darwin/time.c @@ -32,10 +32,15 @@ dds_time_t dds_time(void) #endif } -dds_time_t ddsrt_time_monotonic(void) +ddsrt_wctime_t ddsrt_time_wallclock(void) +{ + return (ddsrt_wctime_t) { dds_time () }; +} + +ddsrt_mtime_t ddsrt_time_monotonic(void) { #if defined MAC_OS_X_VERSION_10_12 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 - return (int64_t) clock_gettime_nsec_np (CLOCK_UPTIME_RAW); + return (ddsrt_mtime_t) { (int64_t) clock_gettime_nsec_np (CLOCK_UPTIME_RAW) }; #else static mach_timebase_info_data_t timeInfo; uint64_t mt; @@ -57,16 +62,17 @@ dds_time_t ddsrt_time_monotonic(void) (void)mach_timebase_info(&timeInfo); } - return (dds_time_t)(mt * timeInfo.numer / timeInfo.denom); + return (ddsrt_mtime_t) { mt * timeInfo.numer / timeInfo.denom }; #endif } -dds_time_t ddsrt_time_elapsed(void) +ddsrt_etime_t ddsrt_time_elapsed(void) { #if defined MAC_OS_X_VERSION_10_12 && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 - return (int64_t) clock_gettime_nsec_np (CLOCK_MONOTONIC_RAW); + return (ddsrt_etime_t) { (int64_t) clock_gettime_nsec_np (CLOCK_MONOTONIC_RAW) }; #else /* Elapsed time clock not (yet) supported on this platform. */ - return ddsrt_time_monotonic(); + dds_mtime_t mt = ddsrt_time_monotonic(); + return (ddsrt_etime_t) { mt.v }; #endif } diff --git a/src/ddsrt/src/time/freertos/time.c b/src/ddsrt/src/time/freertos/time.c index 39ee345..438ca0a 100644 --- a/src/ddsrt/src/time/freertos/time.c +++ b/src/ddsrt/src/time/freertos/time.c @@ -33,15 +33,20 @@ dds_time_t dds_time(void) #define NSECS_PER_TICK (DDS_NSECS_IN_SEC / configTICK_RATE_HZ) -dds_time_t ddsrt_time_monotonic (void) +ddsrt_wctime_t ddsrt_time_wallclock (void) { - return (xTaskGetTickCount() * NSECS_PER_TICK); + return (ddsrt_wctime_t) { dds_time() }; } -dds_time_t ddsrt_time_elapsed (void) +ddsrt_mtime_t ddsrt_time_monotonic (void) +{ + return (ddsrt_mtime_t) { xTaskGetTickCount() * NSECS_PER_TICK }; +} + +ddsrt_etime_t ddsrt_time_elapsed (void) { /* Elapsed time clock not (yet) supported on this platform. */ - return ddsrt_time_monotonic (); + return (ddsrt_etime_t) { xTaskGetTickCount() * NSECS_PER_TICK }; } void dds_sleepfor (dds_duration_t reltime) diff --git a/src/ddsrt/src/time/include/dds/ddsrt/timeconv.h b/src/ddsrt/src/time/include/dds/ddsrt/timeconv.h index 7ee22d3..8b5efbc 100644 --- a/src/ddsrt/src/time/include/dds/ddsrt/timeconv.h +++ b/src/ddsrt/src/time/include/dds/ddsrt/timeconv.h @@ -15,54 +15,3 @@ #include "dds/ddsrt/misc.h" #include "dds/ddsrt/time.h" -/** - * @brief Calculate a time given an offset time and a duration. - * - * Negative time can become positive by adding a large enough duration, of - * course a positive time can become negative given a large enough negative - * duration. - * - * @param[in] abstime Timestamp in nanoseconds since UNIX Epoch. - * @param[in] reltime Relative time in nanoseconds. - * - * @returns A timestamp in nanoseconds since UNIX Epoch. - */ -inline dds_time_t -ddsrt_time_add_duration(dds_time_t abstime, dds_duration_t reltime) -{ - assert(abstime >= 0); - assert(reltime >= 0); - - return (reltime >= DDS_NEVER - abstime ? DDS_NEVER : abstime + reltime); -} - -#if _WIN32 -/** - * @brief Convert a relative time to microseconds rounding up. - * - * @param[in] reltime Relative time to convert. - * - * @returns INFINITE if @reltime was @DDS_INIFINITY, relative time converted to - * microseconds otherwise. - */ -inline DWORD -ddsrt_duration_to_msecs_ceil(dds_duration_t reltime) -{ - if (reltime == DDS_INFINITY) { - return INFINITE; - } else if (reltime > 0) { - assert(INFINITE < (DDS_INFINITY / DDS_NSECS_IN_MSEC)); - dds_duration_t max_nsecs = (INFINITE - 1) * DDS_NSECS_IN_MSEC; - - if (reltime < (max_nsecs - (DDS_NSECS_IN_MSEC - 1))) { - reltime += (DDS_NSECS_IN_MSEC - 1); - } else { - reltime = max_nsecs; - } - - return (DWORD)(reltime / DDS_NSECS_IN_MSEC); - } - - return 0; -} -#endif diff --git a/src/ddsrt/src/time/posix/time.c b/src/ddsrt/src/time/posix/time.c index cfc98f5..9ac2ff5 100644 --- a/src/ddsrt/src/time/posix/time.c +++ b/src/ddsrt/src/time/posix/time.c @@ -21,21 +21,28 @@ dds_time_t dds_time(void) { struct timespec ts; - (void)clock_gettime(CLOCK_REALTIME, &ts); return (ts.tv_sec * DDS_NSECS_IN_SEC) + ts.tv_nsec; } -dds_time_t ddsrt_time_monotonic(void) +ddsrt_wctime_t ddsrt_time_wallclock(void) { struct timespec ts; - - (void)clock_gettime(CLOCK_MONOTONIC, &ts); - return (ts.tv_sec * DDS_NSECS_IN_SEC) + ts.tv_nsec; + (void)clock_gettime(CLOCK_REALTIME, &ts); + return (ddsrt_wctime_t) { (ts.tv_sec * DDS_NSECS_IN_SEC) + ts.tv_nsec }; } -dds_time_t ddsrt_time_elapsed(void) +ddsrt_mtime_t ddsrt_time_monotonic(void) +{ + struct timespec ts; + (void)clock_gettime(CLOCK_MONOTONIC, &ts); + return (ddsrt_mtime_t) { (ts.tv_sec * DDS_NSECS_IN_SEC) + ts.tv_nsec }; +} + +ddsrt_etime_t ddsrt_time_elapsed(void) { /* Elapsed time clock not worth the bother for now. */ - return ddsrt_time_monotonic(); + struct timespec ts; + (void)clock_gettime(CLOCK_MONOTONIC, &ts); + return (ddsrt_etime_t) { (ts.tv_sec * DDS_NSECS_IN_SEC) + ts.tv_nsec }; } diff --git a/src/ddsrt/src/time/solaris2.6/time.c b/src/ddsrt/src/time/solaris2.6/time.c index 0c5fb7c..46f98db 100644 --- a/src/ddsrt/src/time/solaris2.6/time.c +++ b/src/ddsrt/src/time/solaris2.6/time.c @@ -26,13 +26,17 @@ dds_time_t dds_time(void) return (ts.tv_sec * DDS_NSECS_IN_SEC) + ts.tv_nsec; } -dds_time_t ddsrt_time_monotonic(void) +ddsrt_wctime_t ddsrt_time_wallclock(void) { - return gethrtime (); + return (ddsrt_wctime_t) { dds_time() }; } -dds_time_t ddsrt_time_elapsed(void) +ddsrt_mtime_t ddsrt_time_monotonic(void) { - /* Elapsed time clock not worth the bother for now. */ - return ddsrt_time_monotonic(); + return (ddsrt_mtime_t) { gethrtime () }; +} + +ddsrt_etime_t ddsrt_time_elapsed(void) +{ + return (ddsrt_etime_t) { gethrtime () }; } diff --git a/src/ddsrt/src/time/windows/time.c b/src/ddsrt/src/time/windows/time.c index e4c9c87..04262dd 100644 --- a/src/ddsrt/src/time/windows/time.c +++ b/src/ddsrt/src/time/windows/time.c @@ -13,7 +13,7 @@ #include #include -#include "dds/ddsrt/timeconv.h" +#include "dds/ddsrt/time.h" extern inline DWORD ddsrt_duration_to_msecs_ceil(dds_duration_t reltime); @@ -100,16 +100,21 @@ void ddsrt_time_fini(void) #endif } -dds_time_t ddsrt_time_monotonic(void) +ddsrt_wctime_t ddsrt_time_wallclock(void) +{ + return (ddsrt_wctime_t) { dds_time() } ; +} + +ddsrt_mtime_t ddsrt_time_monotonic(void) { ULONGLONG ubit; (void)QueryUnbiasedInterruptTime(&ubit); /* 100ns ticks */ - return (dds_time_t)(ubit * 100); + return (ddsrt_mtime_t) { ubit * 100 }; } -dds_time_t ddsrt_time_elapsed(void) +ddsrt_etime_t ddsrt_time_elapsed(void) { LARGE_INTEGER qpc; static LONGLONG qpc_freq; /* Counts per nanosecond. */ @@ -152,7 +157,7 @@ dds_time_t ddsrt_time_elapsed(void) * the time progression to actual time progression. */ QueryPerformanceCounter(&qpc); - return (dds_time_t)(qpc.QuadPart * qpc_freq); + return (ddsrt_etime_t) { qpc.QuadPart * qpc_freq }; } void dds_sleepfor(dds_duration_t reltime) diff --git a/src/ddsrt/tests/hopscotch.c b/src/ddsrt/tests/hopscotch.c index fdb0f0c..aab275f 100644 --- a/src/ddsrt/tests/hopscotch.c +++ b/src/ddsrt/tests/hopscotch.c @@ -167,7 +167,7 @@ CU_Theory ((const struct ops *ops, bool random, adj_fun_t adj, const char *adjna void *h = ops->new (); uint32_t i, nk = 0; uint64_t nn = 0; - dds_time_t t0, t1; + ddsrt_mtime_t t0, t1; t0 = ddsrt_time_monotonic (); for (uint32_t iter = 0; iter < MAX_ITERS; iter++) { @@ -205,5 +205,5 @@ CU_Theory ((const struct ops *ops, bool random, adj_fun_t adj, const char *adjna } t1 = ddsrt_time_monotonic (); ops->free (h); - printf (" %"PRIu64" %.0f ns/cycle\n", nn, (double) (t1 - t0) / (double) nn); + printf (" %"PRIu64" %.0f ns/cycle\n", nn, (double) (t1.v - t0.v) / (double) nn); }