blob: d58ff973e95ddf01ab3ba7bf21bb6b980c7a857e [file] [log] [blame]
Frédéric Lécaillec6bc1852021-06-30 14:25:10 +02001/*
2 * Circular buffer management
3 *
4 * Copyright 2021 HAProxy Technologies, Frédéric Lécaille <flecaill@haproxy.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation, version 2.1
9 * exclusively.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <haproxy/list.h>
22#include <haproxy/pool.h>
23#include <haproxy/cbuf-t.h>
24
25DECLARE_POOL(pool_head_cbuf, "cbuf_pool", sizeof(struct cbuf));
26
27/* Allocate and return a new circular buffer if succeeded, NULL if not. */
28struct cbuf *cbuf_new(void)
29{
30 struct cbuf *cbuf;
31
32 cbuf = pool_alloc(pool_head_cbuf);
33 if (cbuf) {
34 cbuf->wr = 0;
35 cbuf->rd = 0;
36 }
37
38 return cbuf;
39}
40
41/* Free QUIC ring <cbuf> */
42void cbuf_free(struct cbuf *cbuf)
43{
44 if (!cbuf)
45 return;
46
47 pool_free(pool_head_cbuf, cbuf);
48}
49
50/*
51 * Local variables:
52 * c-indent-level: 8
53 * c-basic-offset: 8
54 * End:
55 */