dblockpool_free.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <stdlib.h>
  2. #include "private.h"
  3. /*--------------------------------------------------------- */
  4. void
  5. lub_dblockpool_free(lub_dblockpool_t *this,
  6. void *block)
  7. {
  8. lub_dblockpool_chunk_t **chunk_ptr;
  9. /* find the chunk from which this derived. */
  10. for(chunk_ptr = &this->first_chunk;
  11. *chunk_ptr;
  12. chunk_ptr = &(*chunk_ptr)->next)
  13. {
  14. const char *pool_start = (char *)&(*chunk_ptr)[1];
  15. const char *pool_end = pool_start + (this->block_size * this->chunk_size);
  16. const char *ptr = block;
  17. if((ptr >= pool_start) && (ptr < pool_end))
  18. {
  19. /* found the right pool */
  20. lub_blockpool_free(&(*chunk_ptr)->pool,block);
  21. (*chunk_ptr)->count--;
  22. /* track the number of allocations */
  23. if(0 == (*chunk_ptr)->count)
  24. {
  25. lub_dblockpool_chunk_t *tmp = *chunk_ptr;
  26. /* removing last block from this chunk */
  27. *chunk_ptr = (*chunk_ptr)->next;
  28. free(tmp);
  29. }
  30. break;
  31. }
  32. }
  33. }
  34. /*--------------------------------------------------------- */