mempool.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Copyright (c) 2007, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /* $Id$ */
  4. /**
  5. * \file util.h
  6. * \brief Headers for mempool.c
  7. **/
  8. #ifndef MEMPOOL_H
  9. #define MEMPOOL_H
  10. /** A memory pool is a context in which a large number of fixed-sized
  11. * objects can be allocated efficiently. See mempool.c for implementation
  12. * details. */
  13. typedef struct mp_pool_t mp_pool_t;
  14. void *mp_pool_get(mp_pool_t *pool);
  15. void mp_pool_release(void *item);
  16. mp_pool_t *mp_pool_new(size_t item_size, size_t chunk_capacity);
  17. void mp_pool_clean(mp_pool_t *pool, int n);
  18. void mp_pool_destroy(mp_pool_t *pool);
  19. void mp_pool_assert_ok(mp_pool_t *pool);
  20. void mp_pool_log_status(mp_pool_t *pool, int severity);
  21. #ifdef MEMPOOL_PRIVATE
  22. /* These declarations are only used by mempool.c and test.c */
  23. struct mp_pool_t {
  24. /** Doubly-linked list of chunks in which no items have been allocated.
  25. * The front of the list is the most recently emptied chunk. */
  26. struct mp_chunk_t *empty_chunks;
  27. /** Doubly-linked list of chunks in which some items have been allocated,
  28. * but which are not yet full. The front of the list is the chunk that has
  29. * most recently been modified. */
  30. struct mp_chunk_t *used_chunks;
  31. /** Doubly-linked list of chunks in which no more items can be allocated.
  32. * The front of the list is the chunk that has most recently become full. */
  33. struct mp_chunk_t *full_chunks;
  34. /** Length of <b>empty_chunks</b>. */
  35. int n_empty_chunks;
  36. /** Lowest value of <b>empty_chunks</b> since last call to
  37. * mp_pool_clean(-1). */
  38. int min_empty_chunks;
  39. /** Size of each chunk (in items). */
  40. int new_chunk_capacity;
  41. /** Size to allocate for each item, including overhead and alignment
  42. * padding. */
  43. size_t item_alloc_size;
  44. };
  45. #endif
  46. #endif