heap_context_find_or_create.c 869 B

123456789101112131415161718192021222324252627282930
  1. #include "private.h"
  2. #include "context.h"
  3. /*--------------------------------------------------------- */
  4. const lub_heap_context_t *
  5. lub_heap_context_find_or_create(lub_heap_t * this,
  6. const stackframe_t * stack)
  7. {
  8. lub_heap_context_t *context;
  9. /*
  10. * look to see whether there is an
  11. * existing context for this allocation
  12. */
  13. context = lub_heap_context_find(stack);
  14. if(NULL == context)
  15. {
  16. lub_heap_leak_t *leak = lub_heap_leak_instance();
  17. context = lub_dblockpool_alloc(&leak->m_context_pool);
  18. lub_heap_leak_release(leak);
  19. if(NULL != context)
  20. {
  21. /* initialise the instance */
  22. lub_heap_context_init(context,this,stack);
  23. }
  24. }
  25. return context;
  26. }
  27. /*--------------------------------------------------------- */