1
0

cache.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. {
  9. lub_heap_align_t m_max_block_size;
  10. unsigned m_num_max_blocks;
  11. unsigned m_num_buckets;
  12. size_t m_bucket_size;
  13. size_t m_misses;
  14. lub_heap_cache_bucket_t **m_bucket_lookup;
  15. lub_heap_cache_bucket_t **m_bucket_end;
  16. lub_heap_cache_bucket_t *m_bucket_start[1]; /* must be last */
  17. };
  18. lub_heap_cache_bucket_t *
  19. lub_heap_cache_find_bucket_from_address(lub_heap_cache_t *instance,
  20. const void *address);
  21. lub_heap_cache_bucket_t *
  22. lub_heap_cache_find_bucket_from_size(lub_heap_cache_t *instance,
  23. size_t size);
  24. void
  25. lub_heap_cache__get_stats(lub_heap_cache_t *this,
  26. lub_heap_stats_t *stats);
  27. /*-------------------------------------
  28. * lub_heap_cache_bucket_t class
  29. *------------------------------------- */
  30. struct _lub_heap_cache_bucket
  31. {
  32. lub_blockpool_t m_blockpool;
  33. lub_heap_cache_t *m_cache;
  34. char *m_memory_end;
  35. char m_memory_start[1]; /* must be last */
  36. };
  37. void
  38. lub_heap_cache_bucket_init(lub_heap_cache_bucket_t *instance,
  39. lub_heap_cache_t *cache,
  40. size_t block_size,
  41. size_t bucket_size);
  42. void *
  43. lub_heap_cache_bucket_alloc(lub_heap_cache_bucket_t *instance);
  44. lub_heap_status_t
  45. lub_heap_cache_bucket_free(lub_heap_cache_bucket_t *instance,
  46. void *ptr);
  47. size_t
  48. lub_heap_cache__get_max_free(lub_heap_cache_t *this);
  49. lub_heap_cache_bucket_t *
  50. lub_heap_cache_find_bucket_from_address(lub_heap_cache_t *this,
  51. const void *address);
  52. size_t
  53. lub_heap_cache_bucket__get_block_overhead(lub_heap_cache_bucket_t *this,
  54. const char *block);
  55. size_t
  56. lub_heap_cache_bucket__get_block_size(lub_heap_cache_bucket_t *this,
  57. const char *block);