]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ring: adds new ring_init function.
authorEmeric Brun <ebrun@haproxy.com>
Tue, 12 Jan 2021 13:21:00 +0000 (14:21 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 13 Feb 2021 08:43:17 +0000 (09:43 +0100)
Adds the new ring_init function to initialize
a pre-allocated ring struct using the given
memory area.

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

index aa3a3c6d5e55a4b889257f306aa77ad92ef282af..c400f915d7106b5062f8b64e809f8d63d640c120 100644 (file)
@@ -27,6 +27,7 @@
 #include <haproxy/ring-t.h>
 
 struct ring *ring_new(size_t size);
+void ring_init(struct ring *ring, void* area, size_t size);
 struct ring *ring_resize(struct ring *ring, size_t size);
 void ring_free(struct ring *ring);
 ssize_t ring_write(struct ring *ring, size_t maxlen, const struct ist pfx[], size_t npfx, const struct ist msg[], size_t nmsg);
index 2ee6c10b938fc6e8665edf275c469f44b9eeef64..de57d6898f0aa28daea36ad914f41e5c981f1372 100644 (file)
 #include <haproxy/stream_interface.h>
 #include <haproxy/thread.h>
 
+/* Initialize a pre-allocated ring with the buffer area
+ * of size */
+void ring_init(struct ring *ring, void *area, size_t size)
+{
+       HA_RWLOCK_INIT(&ring->lock);
+       LIST_INIT(&ring->waiters);
+       ring->readers_count = 0;
+       ring->ofs = 0;
+       ring->buf = b_make(area, size, 0, 0);
+       /* write the initial RC byte */
+       b_putchr(&ring->buf, 0);
+}
+
 /* Creates and returns a ring buffer of size <size> bytes. Returns NULL on
  * allocation failure.
  */
@@ -46,13 +59,7 @@ struct ring *ring_new(size_t size)
        if (!area)
                goto fail;
 
-       HA_RWLOCK_INIT(&ring->lock);
-       LIST_INIT(&ring->waiters);
-       ring->readers_count = 0;
-       ring->ofs = 0;
-       ring->buf = b_make(area, size, 0, 0);
-       /* write the initial RC byte */
-       b_putchr(&ring->buf, 0);
+       ring_init(ring, area, size);
        return ring;
  fail:
        free(area);