mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-30 14:58:21 +00:00
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.
This commit is contained in:
parent
1eb595b8b4
commit
e14b98c08e
@ -27,6 +27,7 @@
|
|||||||
#include <haproxy/ring-t.h>
|
#include <haproxy/ring-t.h>
|
||||||
|
|
||||||
struct ring *ring_new(size_t size);
|
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);
|
struct ring *ring_resize(struct ring *ring, size_t size);
|
||||||
void ring_free(struct ring *ring);
|
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);
|
ssize_t ring_write(struct ring *ring, size_t maxlen, const struct ist pfx[], size_t npfx, const struct ist msg[], size_t nmsg);
|
||||||
|
21
src/ring.c
21
src/ring.c
@ -27,6 +27,19 @@
|
|||||||
#include <haproxy/stream_interface.h>
|
#include <haproxy/stream_interface.h>
|
||||||
#include <haproxy/thread.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
|
/* Creates and returns a ring buffer of size <size> bytes. Returns NULL on
|
||||||
* allocation failure.
|
* allocation failure.
|
||||||
*/
|
*/
|
||||||
@ -46,13 +59,7 @@ struct ring *ring_new(size_t size)
|
|||||||
if (!area)
|
if (!area)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
HA_RWLOCK_INIT(&ring->lock);
|
ring_init(ring, area, size);
|
||||||
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);
|
|
||||||
return ring;
|
return ring;
|
||||||
fail:
|
fail:
|
||||||
free(area);
|
free(area);
|
||||||
|
Loading…
Reference in New Issue
Block a user