mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 15:17:01 +02:00
OPTIM: ring: don't even try to update offset when failed to read
If there's nothing to read, it's pointless for a reader to try to update the offset pointer, that's two atomic ops to replace a value by itself twice. Let's just stop this.
This commit is contained in:
parent
9e99cfbeb6
commit
1f8b14b7be
22
src/ring.c
22
src/ring.c
@ -538,17 +538,19 @@ int ring_dispatch_messages(struct ring *ring, void *ctx, size_t *ofs_ptr, size_t
|
||||
|
||||
vp_data_to_ring(v1, v2, (char *)ring_area, ring_size, &head_ofs, &tail_ofs);
|
||||
|
||||
/* inc readers count on new place */
|
||||
do {
|
||||
readers = _HA_ATOMIC_LOAD(ring_area + head_ofs);
|
||||
} while ((readers > RING_MAX_READERS ||
|
||||
!_HA_ATOMIC_CAS(ring_area + head_ofs, &readers, readers + 1)) && __ha_cpu_relax());
|
||||
if (head_ofs != prev_ofs) {
|
||||
/* inc readers count on new place */
|
||||
do {
|
||||
readers = _HA_ATOMIC_LOAD(ring_area + head_ofs);
|
||||
} while ((readers > RING_MAX_READERS ||
|
||||
!_HA_ATOMIC_CAS(ring_area + head_ofs, &readers, readers + 1)) && __ha_cpu_relax());
|
||||
|
||||
/* dec readers count on old place */
|
||||
do {
|
||||
readers = _HA_ATOMIC_LOAD(ring_area + prev_ofs);
|
||||
} while ((readers > RING_MAX_READERS ||
|
||||
!_HA_ATOMIC_CAS(ring_area + prev_ofs, &readers, readers - 1)) && __ha_cpu_relax());
|
||||
/* dec readers count on old place */
|
||||
do {
|
||||
readers = _HA_ATOMIC_LOAD(ring_area + prev_ofs);
|
||||
} while ((readers > RING_MAX_READERS ||
|
||||
!_HA_ATOMIC_CAS(ring_area + prev_ofs, &readers, readers - 1)) && __ha_cpu_relax());
|
||||
}
|
||||
|
||||
if (last_ofs_ptr)
|
||||
*last_ofs_ptr = tail_ofs;
|
||||
|
Loading…
Reference in New Issue
Block a user