1a74702c6SGeorge Wang/* Copyright (c) 2017 - 2022 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 95392f7a3SLiteSpeed Tech#ifndef LSQUIC_USE_POOLS 105392f7a3SLiteSpeed Tech#define LSQUIC_USE_POOLS 1 115392f7a3SLiteSpeed Tech#endif 125392f7a3SLiteSpeed Tech 1350aadb33SDmitri Tikhonovstruct malo; 1450aadb33SDmitri Tikhonov 1550aadb33SDmitri Tikhonov/* Create a malo allocator for objects of size `obj_size'. */ 1650aadb33SDmitri Tikhonovstruct malo * 1750aadb33SDmitri Tikhonovlsquic_malo_create (size_t obj_size); 1850aadb33SDmitri Tikhonov 1950aadb33SDmitri Tikhonov/* Get a new object. */ 2050aadb33SDmitri Tikhonovvoid * 2150aadb33SDmitri Tikhonovlsquic_malo_get (struct malo *); 2250aadb33SDmitri Tikhonov 2350aadb33SDmitri Tikhonov/* Return obj to the pool */ 2450aadb33SDmitri Tikhonovvoid 2550aadb33SDmitri Tikhonovlsquic_malo_put (void *obj); 2650aadb33SDmitri Tikhonov 2750aadb33SDmitri Tikhonov/* This deallocates all remaining objects. */ 2850aadb33SDmitri Tikhonovvoid 2950aadb33SDmitri Tikhonovlsquic_malo_destroy (struct malo *); 3050aadb33SDmitri Tikhonov 315392f7a3SLiteSpeed Tech/* This iterator is slow. It is only used in unit tests for verification. 325392f7a3SLiteSpeed Tech * 335392f7a3SLiteSpeed Tech * If you to iterate over all elements allocated in a pool, keep track yourself. 345392f7a3SLiteSpeed Tech */ 3550aadb33SDmitri Tikhonov/* The iterator is built-in. Usage: 3650aadb33SDmitri Tikhonov * void *obj; 3750aadb33SDmitri Tikhonov * for (obj = lsquic_malo_first(obj); obj; lsquic_malo_next(obj)) 3850aadb33SDmitri Tikhonov * do_stuff(obj); 3950aadb33SDmitri Tikhonov */ 4050aadb33SDmitri Tikhonovvoid * 4150aadb33SDmitri Tikhonovlsquic_malo_first (struct malo *); 4250aadb33SDmitri Tikhonov 4350aadb33SDmitri Tikhonovvoid * 4450aadb33SDmitri Tikhonovlsquic_malo_next (struct malo *); 4550aadb33SDmitri Tikhonov 46c51ce338SDmitri Tikhonovsize_t 47c51ce338SDmitri Tikhonovlsquic_malo_mem_used (const struct malo *); 48c51ce338SDmitri Tikhonov 4950aadb33SDmitri Tikhonov#endif 50