2 * Copyright © 2006 Joonas Pihlaja
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 #ifndef CAIRO_FREELIST_H
23 #define CAIRO_FREELIST_H
25 #include "cairo-types-private.h"
26 #include "cairo-compiler-private.h"
28 /* Opaque implementation types. */
29 typedef struct _cairo_freelist cairo_freelist_t
;
30 typedef struct _cairo_freelist_node cairo_freelist_node_t
;
32 struct _cairo_freelist_node
{
33 cairo_freelist_node_t
*next
;
36 struct _cairo_freelist
{
37 cairo_freelist_node_t
*first_free_node
;
42 /* Initialise a freelist that will be responsible for allocating
43 * nodes of size nodesize. */
45 _cairo_freelist_init (cairo_freelist_t
*freelist
, unsigned nodesize
);
47 /* Deallocate any nodes in the freelist. */
49 _cairo_freelist_fini (cairo_freelist_t
*freelist
);
51 /* Allocate a new node from the freelist. If the freelist contains no
52 * nodes, a new one will be allocated using malloc(). The caller is
53 * responsible for calling _cairo_freelist_free() or free() on the
54 * returned node. Returns %NULL on memory allocation error. */
56 _cairo_freelist_alloc (cairo_freelist_t
*freelist
);
58 /* Allocate a new node from the freelist. If the freelist contains no
59 * nodes, a new one will be allocated using calloc(). The caller is
60 * responsible for calling _cairo_freelist_free() or free() on the
61 * returned node. Returns %NULL on memory allocation error. */
63 _cairo_freelist_calloc (cairo_freelist_t
*freelist
);
65 /* Return a node to the freelist. This does not deallocate the memory,
66 * but makes it available for later reuse by
67 * _cairo_freelist_alloc(). */
69 _cairo_freelist_free (cairo_freelist_t
*freelist
, void *node
);
71 #endif /* CAIRO_FREELIST_H */