From 6d92c73e5cdf93fe70b0646e78a250e01a8d2f65 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 11 Jan 2020 13:15:40 -0800 Subject: XREQ and others race on TTL. The TTL in these cases should have been atomic. To facilitate things we actually introduce an atomic int for convenience. We also introduce a convenience nni_msg_must_append_u32() and nni_msg_header_must_append_u32(), so that we can eliminate some failure tests that cannot ever happen. Combined with a new test for xreq, we have 100% coverage for xreq and more coverage for the other REQ/REP protocols. --- src/core/platform.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/core/platform.h') diff --git a/src/core/platform.h b/src/core/platform.h index 53d25137..70420061 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -192,7 +192,29 @@ extern void nni_atomic_inc64(nni_atomic_u64 *); // nni_atomic_cas64 is a compare and swap. The second argument is the // value to compare against, and the third is the new value. Returns // true if the value was set. -extern bool nni_atomic_cas64(nni_atomic_u64 *, uint64_t, uint64_t); +extern bool nni_atomic_cas64(nni_atomic_u64 *, uint64_t, uint64_t); + +// In a lot of circumstances, we want a simple atomic reference count, +// or atomic tunable values for integers like queue lengths or TTLs. +// These native integer forms should be preferred over the 64 bit versions +// unless larger bit sizes are truly needed. They will be more efficient +// on many platforms. +typedef struct nni_atomic_int nni_atomic_int; + +extern void nni_atomic_init(nni_atomic_int *); +extern void nni_atomic_add(nni_atomic_int *, int); +extern void nni_atomic_sub(nni_atomic_int *, int); +extern int nni_atomic_get(nni_atomic_int *); +extern void nni_atomic_set(nni_atomic_int *, int); +extern int nni_atomic_swap(nni_atomic_int *, int); +extern int nni_atomic_dec_nv(nni_atomic_int *); +extern void nni_atomic_dec(nni_atomic_int *); +extern void nni_atomic_inc(nni_atomic_int *); + +// nni_atomic_cas is a compare and swap. The second argument is the +// value to compare against, and the third is the new value. Returns +// true if the value was set. +extern bool nni_atomic_cas(nni_atomic_int *, int, int); // // Clock Support -- cgit v1.2.3-70-g09d2