From: Willy Tarreau Date: Mon, 20 Feb 2023 18:21:52 +0000 (+0100) Subject: MINOR: ring: reserve one special value for the readers count X-Git-Tag: v3.0-dev6~47 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b1c17a2dd88889319344b59c135493e07cd6471;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/include/haproxy/ring-t.h b/include/haproxy/ring-t.h index b89c886958..55867b54b5 100644 --- a/include/haproxy/ring-t.h +++ b/include/haproxy/ring-t.h @@ -27,7 +27,7 @@ #include /* 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" diff --git a/src/ring.c b/src/ring.c index c1e7484765..95e1e991f7 100644 --- a/src/ring.c +++ b/src/ring.c @@ -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)