MINOR: ring: reserve one special value for the readers count

In order to support concurrent writers we'll need to lock areas in the
buffer. For this we'll use one special value of the single-byte readers
count. Let's reserve it now and use the macro instead of the hardcoded
255.
This commit is contained in:
Willy Tarreau 2023-02-20 19:21:52 +01:00
parent 0f611987da
commit 0b1c17a2dd
2 changed files with 7 additions and 3 deletions

View File

@ -27,7 +27,7 @@
#include <haproxy/thread.h>
/* The code below handles circular buffers with single-producer and multiple
* readers (up to 255). The buffer storage area must remain always allocated.
* readers (up to 254). The buffer storage area must remain always allocated.
* It's made of series of payload blocks followed by a readers count (RC).
* There is always a readers count at the beginning of the buffer as well. Each
* payload block is composed of a varint-encoded size (VI) followed by the
@ -96,6 +96,10 @@
#define RING_WF_WAIT_MODE 0x00000001 /* wait for new contents */
#define RING_WF_SEEK_NEW 0x00000002 /* seek to new contents */
/* keep values below in decimal, they may be dumped in error messages */
#define RING_WRITING_SIZE 255 /* the next message's size is being written */
#define RING_MAX_READERS 254 /* highest supported value for RC */
struct ring {
struct buffer buf; // storage area
struct list waiters; // list of waiters, for now, CLI "show event"

View File

@ -270,7 +270,7 @@ int ring_attach(struct ring *ring)
int users = ring->readers_count;
do {
if (users >= 255)
if (users >= RING_MAX_READERS)
return 0;
} while (!_HA_ATOMIC_CAS(&ring->readers_count, &users, users + 1));
return 1;
@ -313,7 +313,7 @@ int ring_attach_cli(struct ring *ring, struct appctx *appctx, uint flags)
if (!ring_attach(ring))
return cli_err(appctx,
"Sorry, too many watchers (255) on this ring buffer. "
"Sorry, too many watchers (" TOSTR(RING_MAX_READERS) ") on this ring buffer. "
"What could it have so interesting to attract so many watchers ?");
if (!appctx->io_handler)