mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-06 13:33:02 +00:00
MINOR: ring: ring_cast_from_area() cast from an allocated area
Cast an unified ring + storage area to a ring from area, without reinitializing the data buffer. Reinitialize the waiters and the lock. It helps retrieving a previously allocated ring, from an mmap for example.
This commit is contained in:
parent
91b2305ad7
commit
9e4ead3095
@ -30,6 +30,7 @@ struct appctx;
|
||||
|
||||
struct ring *ring_new(size_t size);
|
||||
struct ring *ring_make_from_area(void *area, size_t size);
|
||||
struct ring *ring_cast_from_area(void *area);
|
||||
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);
|
||||
|
19
src/ring.c
19
src/ring.c
@ -99,6 +99,25 @@ struct ring *ring_make_from_area(void *area, size_t size)
|
||||
return ring;
|
||||
}
|
||||
|
||||
/* Cast an unified ring + storage area to a ring from <area>, without
|
||||
* reinitializing the data buffer.
|
||||
*
|
||||
* Reinitialize the waiters and the lock.
|
||||
*/
|
||||
struct ring *ring_cast_from_area(void *area)
|
||||
{
|
||||
struct ring *ring = NULL;
|
||||
|
||||
ring = area;
|
||||
ring->buf.area = area + sizeof(*ring);
|
||||
|
||||
HA_RWLOCK_INIT(&ring->lock);
|
||||
LIST_INIT(&ring->waiters);
|
||||
ring->readers_count = 0;
|
||||
|
||||
return ring;
|
||||
}
|
||||
|
||||
/* Resizes existing ring <ring> to <size> which must be larger, without losing
|
||||
* its contents. The new size must be at least as large as the previous one or
|
||||
* no change will be performed. The pointer to the ring is returned on success,
|
||||
|
Loading…
Reference in New Issue
Block a user