cache.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "lub/blockpool.h"
  2. #include "private.h"
  3. typedef struct _lub_heap_cache_bucket lub_heap_cache_bucket_t;
  4. /*-------------------------------------
  5. * lub_heap_cache_t class
  6. *------------------------------------- */
  7. struct _lub_heap_cache {
  8. lub_heap_align_t m_max_block_size;
  9. unsigned m_num_max_blocks;
  10. unsigned m_num_buckets;
  11. size_t m_bucket_size;
  12. size_t m_misses;
  13. lub_heap_cache_bucket_t **m_bucket_lookup;
  14. lub_heap_cache_bucket_t **m_bucket_end;
  15. lub_heap_cache_bucket_t *m_bucket_start[1]; /* must be last */
  16. };
  17. lub_heap_cache_bucket_t
  18. *lub_heap_cache_find_bucket_from_address(lub_heap_cache_t * instance,
  19. const void *address);
  20. lub_heap_cache_bucket_t *lub_heap_cache_find_bucket_from_size(lub_heap_cache_t *
  21. instance,
  22. size_t size);
  23. void lub_heap_cache__get_stats(lub_heap_cache_t * this,
  24. lub_heap_stats_t * stats);
  25. /*-------------------------------------
  26. * lub_heap_cache_bucket_t class
  27. *------------------------------------- */
  28. struct _lub_heap_cache_bucket {
  29. lub_blockpool_t m_blockpool;
  30. lub_heap_cache_t *m_cache;
  31. char *m_memory_end;
  32. char m_memory_start[1]; /* must be last */
  33. };
  34. void
  35. lub_heap_cache_bucket_init(lub_heap_cache_bucket_t * instance,
  36. lub_heap_cache_t * cache,
  37. size_t block_size, size_t bucket_size);
  38. void *lub_heap_cache_bucket_alloc(lub_heap_cache_bucket_t * instance);
  39. lub_heap_status_t
  40. lub_heap_cache_bucket_free(lub_heap_cache_bucket_t * instance, void *ptr);
  41. size_t lub_heap_cache__get_max_free(lub_heap_cache_t * this);
  42. lub_heap_cache_bucket_t
  43. *lub_heap_cache_find_bucket_from_address(lub_heap_cache_t * this,
  44. const void *address);
  45. size_t lub_heap_cache_bucket__get_block_overhead(lub_heap_cache_bucket_t * this,
  46. const char *block);
  47. size_t lub_heap_cache_bucket__get_block_size(lub_heap_cache_bucket_t * this,
  48. const char *block);