From: Emeric Brun Date: Tue, 12 Jan 2021 13:21:00 +0000 (+0100) Subject: MINOR: ring: adds new ring_init function. X-Git-Tag: v2.4-dev8~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e14b98c08ed79a562f2af30e3a87bb77e81b441f;p=thirdparty%2Fhaproxy.git MINOR: ring: adds new ring_init function. Adds the new ring_init function to initialize a pre-allocated ring struct using the given memory area. --- diff --git a/include/haproxy/ring.h b/include/haproxy/ring.h index aa3a3c6d5e..c400f915d7 100644 --- a/include/haproxy/ring.h +++ b/include/haproxy/ring.h @@ -27,6 +27,7 @@ #include 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); diff --git a/src/ring.c b/src/ring.c index 2ee6c10b93..de57d6898f 100644 --- a/src/ring.c +++ b/src/ring.c @@ -27,6 +27,19 @@ #include #include +/* 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 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);