partition_findcreate_local_heap.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * partition_findcreate_local_heap.c
  3. */
  4. #include "private.h"
  5. /*-------------------------------------------------------- */
  6. lub_heap_t *lub_partition_findcreate_local_heap(lub_partition_t * this)
  7. {
  8. /* see whether one already exists */
  9. lub_heap_t *local_heap = 0;
  10. if (this->m_spec.use_local_heap) {
  11. local_heap = lub_partition__get_local_heap(this);
  12. if (!local_heap) {
  13. size_t required;
  14. /* work out how big the local heap will be... */
  15. required =
  16. lub_heap_overhead_size(this->m_spec.
  17. max_local_block_size,
  18. this->m_spec.
  19. 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. /* initialise the heap object */
  30. lub_heap_create(local_heap, required);
  31. lub_heap_cache_init(local_heap,
  32. this->m_spec.
  33. max_local_block_size,
  34. this->m_spec.
  35. num_local_max_blocks);
  36. /* store this in the thread specific storage */
  37. lub_partition__set_local_heap(this, local_heap);
  38. }
  39. }
  40. }
  41. return local_heap;
  42. }
  43. /*-------------------------------------------------------- */