partition_findcreate_local_heap.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * partition_findcreate_local_heap.c
  3. */
  4. #include "private.h"
  5. /*-------------------------------------------------------- */
  6. lub_heap_t *
  7. lub_partition_findcreate_local_heap(lub_partition_t *this)
  8. {
  9. /* see whether one already exists */
  10. lub_heap_t *local_heap = 0;
  11. if(this->m_spec.use_local_heap)
  12. {
  13. local_heap = lub_partition__get_local_heap(this);
  14. if(!local_heap)
  15. {
  16. size_t required;
  17. /* work out how big the local heap will be... */
  18. required = lub_heap_overhead_size(this->m_spec.max_local_block_size,
  19. this->m_spec.num_local_max_blocks);
  20. /*
  21. * create a local heap for the current thread which
  22. * just contains a cache
  23. */
  24. (void)lub_partition_global_realloc(this,
  25. (char**)&local_heap,
  26. required,
  27. LUB_HEAP_ALIGN_NATIVE);
  28. if(local_heap)
  29. {
  30. /* initialise the heap object */
  31. lub_heap_create(local_heap,required);
  32. lub_heap_cache_init(local_heap,
  33. this->m_spec.max_local_block_size,
  34. this->m_spec.num_local_max_blocks);
  35. /* store this in the thread specific storage */
  36. lub_partition__set_local_heap(this,local_heap);
  37. }
  38. }
  39. }
  40. return local_heap;
  41. }
  42. /*-------------------------------------------------------- */