]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ring: reserve one special value for the readers count
authorWilly Tarreau <w@1wt.eu>
Mon, 20 Feb 2023 18:21:52 +0000 (19:21 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 25 Mar 2024 17:34:19 +0000 (17:34 +0000)
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.

include/haproxy/ring-t.h
src/ring.c

index b89c886958fa95d8723076a080bb63ccef9645bf..55867b54b52b9124d447d34014752ad5a8fcc529 100644 (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
 #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"
index c1e74847652ed5d0194b5f9dd91d165915f5498f..95e1e991f7fca8268e942656c3f6ad570df973c8 100644 (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)