diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-01-11 13:15:40 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-01-11 14:15:37 -0800 |
| commit | 6d92c73e5cdf93fe70b0646e78a250e01a8d2f65 (patch) | |
| tree | cb14648b92b02e17bcb48f41a623009cdd65e0ab /src/core/platform.h | |
| parent | 516b99946aad5da15020de9d7175d44c12fd14c6 (diff) | |
| download | nng-6d92c73e5cdf93fe70b0646e78a250e01a8d2f65.tar.gz nng-6d92c73e5cdf93fe70b0646e78a250e01a8d2f65.tar.bz2 nng-6d92c73e5cdf93fe70b0646e78a250e01a8d2f65.zip | |
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.
Diffstat (limited to 'src/core/platform.h')
| -rw-r--r-- | src/core/platform.h | 24 |
1 files changed, 23 insertions, 1 deletions
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 |
