Skip to content

Commit 49c313a

Browse files
committed
Improve comments on condition variables and clocks
Signed-off-by: Erik Boasson <[email protected]>
1 parent 29d1b64 commit 49c313a

File tree

8 files changed

+54
-34
lines changed

8 files changed

+54
-34
lines changed

src/core/ddsc/src/dds__types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ typedef struct dds_waitset {
474474
acquired while holding an ancestor's lock, but a waitset must be capable of triggering on
475475
events on its parent */
476476
ddsrt_mutex_t wait_lock;
477+
478+
/* etime: dds_waitset_wait timeout */
477479
ddsrt_cond_etime_t wait_cond;
478480
size_t nentities; /* [wait_lock] */
479481
size_t ntriggered; /* [wait_lock] */

src/core/ddsi/include/dds/ddsi/ddsi_domaingv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,15 @@ struct ddsi_domaingv {
309309
ddsrt_avl_tree_t typelib;
310310
ddsrt_avl_tree_t typedeps;
311311
ddsrt_avl_tree_t typedeps_reverse;
312-
ddsrt_cond_etime_t typelib_resolved_cond;
312+
ddsrt_cond_etime_t typelib_resolved_cond; // etime: create_topic_descriptor timeout
313313
#endif
314314
#ifdef DDS_HAS_TOPIC_DISCOVERY
315315
ddsrt_mutex_t topic_defs_lock;
316316
struct ddsrt_hh *topic_defs;
317317
#endif
318318

319319
ddsrt_mutex_t new_topic_lock;
320-
ddsrt_cond_etime_t new_topic_cond;
320+
ddsrt_cond_etime_t new_topic_cond; // etime: find_topic timeout
321321
uint32_t new_topic_version;
322322

323323
/* security globals */

src/core/ddsi/include/dds/ddsi/ddsi_endpoint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct ddsi_writer
7272
struct ddsi_endpoint_common c;
7373
ddsi_status_cb_t status_cb;
7474
void * status_cb_entity;
75-
ddsrt_cond_mtime_t throttle_cond; /* used to trigger a transmit thread blocked in throttle_writer() or wait_for_acks() */
75+
ddsrt_cond_mtime_t throttle_cond; /* FIXME: mtime is historical, etime should be better because of max_blocking_time; used to trigger a transmit thread blocked in throttle_writer() or wait_for_acks() */
7676
ddsi_seqno_t seq; /* last sequence number (transmitted seqs are 1 ... seq, 0 when nothing published yet) */
7777
seq_xmit_t seq_xmit; /* last sequence number actually transmitted */
7878
ddsi_seqno_t min_local_readers_reject_seq; /* mimum of local_readers->last_deliv_seq */

src/core/ddsi/src/ddsi_threadmon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct ddsi_threadmon {
4545
bool noprogress_log_stacktraces;
4646

4747
ddsrt_mutex_t lock;
48-
ddsrt_cond_mtime_t cond;
48+
ddsrt_cond_mtime_t cond; // mtime: thread progress is absent when sleeping
4949
struct ddsi_thread_state *thrst;
5050
struct ddsrt_hh *domains;
5151
};

src/core/ddsi/src/ddsi_xevent.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ struct ddsi_xeventq {
103103
struct ddsi_thread_state *thrst;
104104
struct ddsi_domaingv *gv;
105105
ddsrt_mutex_t lock;
106+
107+
// Use monotonic clock to be independent of time jumps and because all timings was
108+
// using the monotonic clock already. Using etime would cause the least delay for
109+
// protocol messages that should have been sent while sleeping, but at the time scale
110+
// at which the protocol operates, it probably doesn't matter
106111
ddsrt_cond_mtime_t cond;
107112

108113
size_t cum_rexmit_bytes;

src/ddsrt/include/dds/ddsrt/sync.h

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ ddsrt_cond_destroy(
105105
ddsrt_nonnull_all;
106106

107107
/**
108-
* @brief Initialize a condition variable.
108+
* @brief Initialize a condition variable bound to the wall clock.
109109
*
110110
* @param[in] cond Condition variable to initialize.
111111
*/
@@ -115,7 +115,7 @@ ddsrt_cond_wctime_init(
115115
ddsrt_nonnull_all;
116116

117117
/**
118-
* @brief Destroy a condition variable.
118+
* @brief Destroy a condition variable bound to the wall clock.
119119
*
120120
* @param[in] cond Condition variable to destroy.
121121
*/
@@ -125,7 +125,7 @@ ddsrt_cond_wctime_destroy(
125125
ddsrt_nonnull_all;
126126

127127
/**
128-
* @brief Initialize a condition variable.
128+
* @brief Initialize a condition variable bound to the monotonic clock.
129129
*
130130
* @param[in] cond Condition variable to initialize.
131131
*/
@@ -135,7 +135,7 @@ ddsrt_cond_mtime_init(
135135
ddsrt_nonnull_all;
136136

137137
/**
138-
* @brief Destroy a condition variable.
138+
* @brief Destroy a condition variable bound to the monotonic clock.
139139
*
140140
* @param[in] cond Condition variable to destroy.
141141
*/
@@ -145,7 +145,7 @@ ddsrt_cond_mtime_destroy(
145145
ddsrt_nonnull_all;
146146

147147
/**
148-
* @brief Initialize a condition variable.
148+
* @brief Initialize a condition variable bound to the elasped clock.
149149
*
150150
* @param[in] cond Condition variable to initialize.
151151
*/
@@ -155,7 +155,7 @@ ddsrt_cond_etime_init(
155155
ddsrt_nonnull_all;
156156

157157
/**
158-
* @brief Destroy a condition variable.
158+
* @brief Destroy a condition variable bound to the elapsed clock.
159159
*
160160
* @param[in] cond Condition variable to destroy.
161161
*/
@@ -181,7 +181,7 @@ ddsrt_cond_wait(
181181
ddsrt_nonnull_all;
182182

183183
/**
184-
* @brief Wait for a condition variable to be signalled.
184+
* @brief Wait for a condition variable bound to the wall clock to be signalled.
185185
*
186186
* @param[in] cond Condition variable to block on.
187187
* @param[in] mutex Mutex to associate with condition variable.
@@ -197,7 +197,7 @@ ddsrt_cond_wctime_wait(
197197
ddsrt_nonnull_all;
198198

199199
/**
200-
* @brief Wait for a condition variable to be signalled.
200+
* @brief Wait for a condition variable bound to the monotonic clock to be signalled.
201201
*
202202
* @param[in] cond Condition variable to block on.
203203
* @param[in] mutex Mutex to associate with condition variable.
@@ -213,7 +213,7 @@ ddsrt_cond_mtime_wait(
213213
ddsrt_nonnull_all;
214214

215215
/**
216-
* @brief Wait for a condition variable to be signalled.
216+
* @brief Wait for a condition variable bound to the elapsed clock to be signalled.
217217
*
218218
* @param[in] cond Condition variable to block on.
219219
* @param[in] mutex Mutex to associate with condition variable.
@@ -229,7 +229,10 @@ ddsrt_cond_etime_wait(
229229
ddsrt_nonnull_all;
230230

231231
/**
232-
* @brief Wait until @abstime for a condition variable to be signalled.
232+
* @brief Wait until @abstime for a condition variable bound to the wall clock to be signalled.
233+
*
234+
* For platforms that only provide relative timeouts, the function will convert the absolute timeout
235+
* to a relative one by subtracting the current time according to the wall clock.
233236
*
234237
* @param[in] cond Condition variable to block on.
235238
* @param[in] mutex Mutex to associate with condition variable.
@@ -250,7 +253,13 @@ ddsrt_cond_wctime_waituntil(
250253
ddsrt_nonnull((1,2));
251254

252255
/**
253-
* @brief Wait until @abstime for a condition variable to be signalled.
256+
* @brief Wait until @abstime for a condition variable bound to the monotonic clock to be signalled.
257+
*
258+
* For platforms that only provide relative timeouts, the function will convert the absolute timeout
259+
* to a relative one by subtracting the current time according to the monotonic clock. For platforms
260+
* that do not support binding a condition variable to a specific clock and require an absolute timeout
261+
* the timeout is calculated by converting the relative timeout to an absolute timeout on the wall clock
262+
* by adding the current time according to the wall clock.
254263
*
255264
* @param[in] cond Condition variable to block on.
256265
* @param[in] mutex Mutex to associate with condition variable.
@@ -271,7 +280,13 @@ ddsrt_cond_mtime_waituntil(
271280
ddsrt_nonnull((1,2));
272281

273282
/**
274-
* @brief Wait until @abstime for a condition variable to be signalled.
283+
* @brief Wait until @abstime for a condition variable bound to the elapsed clock to be signalled.
284+
*
285+
* For platforms that only provide relative timeouts, the function will convert the absolute timeout
286+
* to a relative one by subtracting the current time according to the elapsed clock. For platforms
287+
* that do not support binding a condition variable to a specific clock and require an absolute timeout
288+
* the timeout is calculated by converting the relative timeout to an absolute timeout on the wall clock
289+
* by adding the current time according to the wall clock.
275290
*
276291
* @param[in] cond Condition variable to block on.
277292
* @param[in] mutex Mutex to associate with condition variable.
@@ -306,7 +321,7 @@ ddsrt_cond_signal(
306321
ddsrt_nonnull_all;
307322

308323
/**
309-
* @brief Signal a condition variable and unblock at least one thread.
324+
* @brief Signal a condition variable bound to the wall clock and unblock at least one thread.
310325
*
311326
* @param[in] cond Condition variable to signal.
312327
*
@@ -320,7 +335,7 @@ ddsrt_cond_wctime_signal(
320335
ddsrt_nonnull_all;
321336

322337
/**
323-
* @brief Signal a condition variable and unblock at least one thread.
338+
* @brief Signal a condition variable bound to the monotonic clock and unblock at least one thread.
324339
*
325340
* @param[in] cond Condition variable to signal.
326341
*
@@ -335,7 +350,7 @@ ddsrt_cond_mtime_signal(
335350
ddsrt_nonnull_all;
336351

337352
/**
338-
* @brief Signal a condition variable and unblock at least one thread.
353+
* @brief Signal a condition variable bound to the elapsed clock and unblock at least one thread.
339354
*
340355
* @param[in] cond Condition variable to signal.
341356
*
@@ -363,7 +378,7 @@ ddsrt_cond_broadcast(
363378
ddsrt_nonnull_all;
364379

365380
/**
366-
* @brief Signal a condition variable and unblock all threads.
381+
* @brief Signal a condition variable bound to the wall clock and unblock all threads.
367382
*
368383
* @param[in] cond Condition variable to signal.
369384
*
@@ -377,7 +392,7 @@ ddsrt_cond_wctime_broadcast(
377392
ddsrt_nonnull_all;
378393

379394
/**
380-
* @brief Signal a condition variable and unblock all threads.
395+
* @brief Signal a condition variable bound to the monotonic clock and unblock all threads.
381396
*
382397
* @param[in] cond Condition variable to signal.
383398
*
@@ -391,7 +406,7 @@ ddsrt_cond_mtime_broadcast(
391406
ddsrt_nonnull_all;
392407

393408
/**
394-
* @brief Signal a condition variable and unblock all threads.
409+
* @brief Signal a condition variable bound to the elapsed clock and unblock all threads.
395410
*
396411
* @param[in] cond Condition variable to signal.
397412
*

src/ddsrt/include/dds/ddsrt/time.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ DDS_EXPORT void dds_sleepfor (dds_duration_t reltime);
116116
* @brief Get the current time in nanoseconds since the UNIX Epoch. Identical
117117
* to (ddsrt_wctime_t){dds_time()}
118118
*
119-
* @returns Curren time.
119+
* @returns Current time.
120120
*/
121121
DDS_EXPORT ddsrt_wctime_t ddsrt_time_wallclock(void);
122122

123123
/**
124-
* @brief Get high resolution, monotonic time.
124+
* @brief Get monotonic time.
125125
*
126126
* The monotonic clock is a clock with near real-time progression and can be
127127
* used when a high-resolution time is needed without the need for it to be
@@ -136,7 +136,7 @@ DDS_EXPORT ddsrt_wctime_t ddsrt_time_wallclock(void);
136136
DDS_EXPORT ddsrt_mtime_t ddsrt_time_monotonic(void);
137137

138138
/**
139-
* @brief Get high resolution, elapsed (and thus monotonic) time since some
139+
* @brief Get elapsed (and thus monotonic) time since some
140140
* fixed unspecified past time.
141141
*
142142
* The elapsed time clock is a clock with near real-time progression and can be
@@ -150,16 +150,14 @@ DDS_EXPORT ddsrt_mtime_t ddsrt_time_monotonic(void);
150150
DDS_EXPORT ddsrt_etime_t ddsrt_time_elapsed(void);
151151

152152
/**
153-
* @brief Get high resolution, elapsed (and thus monotonic) time since some
154-
* fixed unspecified past time.
153+
* @brief Get a high resolution, monotonic time suitable for measuring time differences.
155154
*
156-
* The elapsed time clock is a clock with near real-time progression and can be
157-
* used when a high-resolution suspend-aware monotonic clock is needed, without
158-
* having to deal with the complications of discontinuities if for example the
159-
* time is changed. The fixed point from which the elapsed time is returned is
160-
* not guaranteed to be fixed over reboots of the system.
155+
* On most systems, the other time functions return a high resolution time stamp
156+
* anyway and this is just an alias for a monotonic timestamp. On some systems
157+
* this function provides a higher resolution. It should not be used for anything other
158+
* than measuring (short) time intervals.
161159
*
162-
* @returns Elapsed time if available, otherwise return monotonic time.
160+
* @returns High resolution time stamp.
163161
*/
164162
DDS_EXPORT ddsrt_hrtime_t ddsrt_time_highres(void);
165163

src/security/core/src/dds_security_fsm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct dds_security_fsm
6363
struct dds_security_fsm_control
6464
{
6565
ddsrt_mutex_t lock;
66-
ddsrt_cond_etime_t cond;
66+
ddsrt_cond_etime_t cond; // etime: timeouts in protocol machine (but see comment for xevent)
6767
struct ddsi_thread_state *thrst;
6868
struct ddsi_domaingv *gv;
6969
struct dds_security_fsm *first_fsm;

0 commit comments

Comments
 (0)