lsquic_malo.h revision 229fce07
1229fce07SDmitri Tikhonov/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc. See LICENSE. */ 250aadb33SDmitri Tikhonov/* 350aadb33SDmitri Tikhonov * lsquic_malo.h -- Fast allocator for fixed-sized objects. 450aadb33SDmitri Tikhonov */ 550aadb33SDmitri Tikhonov 650aadb33SDmitri Tikhonov#ifndef LSQUIC_MALO_H 750aadb33SDmitri Tikhonov#define LSQUIC_MALO_H 1 850aadb33SDmitri Tikhonov 950aadb33SDmitri Tikhonovstruct malo; 1050aadb33SDmitri Tikhonov 1150aadb33SDmitri Tikhonov/* Create a malo allocator for objects of size `obj_size'. */ 1250aadb33SDmitri Tikhonovstruct malo * 1350aadb33SDmitri Tikhonovlsquic_malo_create (size_t obj_size); 1450aadb33SDmitri Tikhonov 1550aadb33SDmitri Tikhonov/* Get a new object. */ 1650aadb33SDmitri Tikhonovvoid * 1750aadb33SDmitri Tikhonovlsquic_malo_get (struct malo *); 1850aadb33SDmitri Tikhonov 1950aadb33SDmitri Tikhonov/* Return obj to the pool */ 2050aadb33SDmitri Tikhonovvoid 2150aadb33SDmitri Tikhonovlsquic_malo_put (void *obj); 2250aadb33SDmitri Tikhonov 2350aadb33SDmitri Tikhonov/* This deallocates all remaining objects. */ 2450aadb33SDmitri Tikhonovvoid 2550aadb33SDmitri Tikhonovlsquic_malo_destroy (struct malo *); 2650aadb33SDmitri Tikhonov 2750aadb33SDmitri Tikhonov/* The iterator is built-in. Usage: 2850aadb33SDmitri Tikhonov * void *obj; 2950aadb33SDmitri Tikhonov * for (obj = lsquic_malo_first(obj); obj; lsquic_malo_next(obj)) 3050aadb33SDmitri Tikhonov * do_stuff(obj); 3150aadb33SDmitri Tikhonov */ 3250aadb33SDmitri Tikhonovvoid * 3350aadb33SDmitri Tikhonovlsquic_malo_first (struct malo *); 3450aadb33SDmitri Tikhonov 3550aadb33SDmitri Tikhonovvoid * 3650aadb33SDmitri Tikhonovlsquic_malo_next (struct malo *); 3750aadb33SDmitri Tikhonov 38c51ce338SDmitri Tikhonovsize_t 39c51ce338SDmitri Tikhonovlsquic_malo_mem_used (const struct malo *); 40c51ce338SDmitri Tikhonov 4150aadb33SDmitri Tikhonov#endif 42