diff options
author | David Lamparter <equinox@diac24.net> | 2019-06-19 12:52:38 +0200 |
---|---|---|
committer | David Lamparter <equinox@diac24.net> | 2019-07-31 03:33:41 +0200 |
commit | 6046b690b53a5e1c14ccf261304f5aa1f53546ae (patch) | |
tree | 28058a3631b17f86492bb7d32c9aa8fd697b91a0 /lib/seqlock.h | |
parent | lib: make SA_SIGINFO use unconditional (diff) | |
download | frr-6046b690b53a5e1c14ccf261304f5aa1f53546ae.tar.xz frr-6046b690b53a5e1c14ccf261304f5aa1f53546ae.zip |
lib/seqlock: avoid syscalls in no-waiter cases
When we have no contention on the seqlock, we shouldn't incur the cost
of syscalls.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/seqlock.h')
-rw-r--r-- | lib/seqlock.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/seqlock.h b/lib/seqlock.h index eef05a430..0f5dc47cd 100644 --- a/lib/seqlock.h +++ b/lib/seqlock.h @@ -54,12 +54,18 @@ */ /* use sequentially increasing "ticket numbers". lowest bit will always - * be 1 to have a 'cleared' indication (i.e., counts 1,3,5,7,etc. ) + * be 1 to have a 'cleared' indication (i.e., counts 1,5,9,13,etc. ) + * 2nd lowest bit is used to indicate we have waiters. */ typedef _Atomic uint32_t seqlock_ctr_t; typedef uint32_t seqlock_val_t; -#define seqlock_assert_valid(val) assert(val & 1) +#define seqlock_assert_valid(val) assert((val) & SEQLOCK_HELD) +#define SEQLOCK_HELD (1U << 0) +#define SEQLOCK_WAITERS (1U << 1) +#define SEQLOCK_VAL(n) ((n) & ~SEQLOCK_WAITERS) +#define SEQLOCK_STARTVAL 1U +#define SEQLOCK_INCR 4U struct seqlock { /* always used */ |