le_mem.h
Go to the documentation of this file.
1 
390 //--------------------------------------------------------------------------------------------------
398 //--------------------------------------------------------------------------------------------------
399 
400 #ifndef LEGATO_MEM_INCLUDE_GUARD
401 #define LEGATO_MEM_INCLUDE_GUARD
402 
403 #ifndef LEGATO_COMPONENT
404 #define LEGATO_COMPONENT
405 #endif
406 
407 
408 //--------------------------------------------------------------------------------------------------
413 //--------------------------------------------------------------------------------------------------
414 typedef struct le_mem_Pool* le_mem_PoolRef_t;
415 
416 
417 //--------------------------------------------------------------------------------------------------
429 //--------------------------------------------------------------------------------------------------
430 typedef void (*le_mem_Destructor_t)
431 (
432  void* objPtr
433 );
434 
435 
436 //--------------------------------------------------------------------------------------------------
440 //--------------------------------------------------------------------------------------------------
441 typedef struct
442 {
443  size_t numBlocksInUse;
445  size_t numOverflows;
446  uint64_t numAllocs;
447  size_t numFree;
448 }
450 
451 
452 #ifdef LE_MEM_TRACE
453  //----------------------------------------------------------------------------------------------
457  //----------------------------------------------------------------------------------------------
458  le_mem_PoolRef_t _le_mem_GetBlockPool
459  (
460  void* objPtr
461  );
462 
463  typedef void* (*_le_mem_AllocFunc_t)(le_mem_PoolRef_t pool);
464 
465  //----------------------------------------------------------------------------------------------
469  //----------------------------------------------------------------------------------------------
470  void* _le_mem_AllocTracer
471  (
472  le_mem_PoolRef_t pool,
473  _le_mem_AllocFunc_t funcPtr,
474  const char* poolFunction,
475  const char* file,
476  const char* callingfunction,
477  size_t line
478  );
480 
481  //----------------------------------------------------------------------------------------------
485  //----------------------------------------------------------------------------------------------
486  void _le_mem_Trace
487  (
488  le_mem_PoolRef_t pool,
489  const char* file,
490  const char* callingfunction,
491  size_t line,
492  const char* poolFunction,
494  void* blockPtr
495  );
496 #endif
497 
498 
499 //--------------------------------------------------------------------------------------------------
505 //--------------------------------------------------------------------------------------------------
506 le_mem_PoolRef_t _le_mem_CreatePool
507 (
508  const char* componentName,
509  const char* name,
510  size_t objSize
511 );
514 
515 
516 //--------------------------------------------------------------------------------------------------
527 //--------------------------------------------------------------------------------------------------
529 (
530  const char* name,
531  size_t objSize
532 )
534 {
535  return _le_mem_CreatePool(STRINGIZE(LEGATO_COMPONENT), name, objSize);
536 }
537 
538 
539 //--------------------------------------------------------------------------------------------------
548 //--------------------------------------------------------------------------------------------------
550 (
551  le_mem_PoolRef_t pool,
552  size_t numObjects
553 );
554 
555 
556 
557 #ifndef LE_MEM_TRACE
558  //----------------------------------------------------------------------------------------------
566  //----------------------------------------------------------------------------------------------
567  void* le_mem_TryAlloc
568  (
569  le_mem_PoolRef_t pool
570  );
571 #else
572  void* _le_mem_TryAlloc(le_mem_PoolRef_t pool);
575 
576  #define le_mem_TryAlloc(pool) \
577  _le_mem_AllocTracer(pool, \
578  _le_mem_TryAlloc, \
579  "le_mem_TryAlloc", \
580  __FILE__, \
581  __FUNCTION__, \
582  __LINE__)
583 
584 #endif
585 
586 
587 #ifndef LE_MEM_TRACE
588  //----------------------------------------------------------------------------------------------
598  //----------------------------------------------------------------------------------------------
599  void* le_mem_AssertAlloc
600  (
601  le_mem_PoolRef_t pool
602  );
603 #else
604  void* _le_mem_AssertAlloc(le_mem_PoolRef_t pool);
607 
608  #define le_mem_AssertAlloc(pool) \
609  _le_mem_AllocTracer(pool, \
610  _le_mem_AssertAlloc, \
611  "le_mem_AssertAlloc", \
612  __FILE__, \
613  __FUNCTION__, \
614  __LINE__)
615 #endif
616 
617 
618 #ifndef LE_MEM_TRACE
619  //----------------------------------------------------------------------------------------------
629  //----------------------------------------------------------------------------------------------
630  void* le_mem_ForceAlloc
631  (
632  le_mem_PoolRef_t pool
633  );
634 #else
635  void* _le_mem_ForceAlloc(le_mem_PoolRef_t pool);
638 
639  #define le_mem_ForceAlloc(pool) \
640  _le_mem_AllocTracer(pool, \
641  _le_mem_ForceAlloc, \
642  "le_mem_ForceAlloc", \
643  __FILE__, \
644  __FUNCTION__, \
645  __LINE__)
646 #endif
647 
648 
649 //--------------------------------------------------------------------------------------------------
659 //--------------------------------------------------------------------------------------------------
661 (
662  le_mem_PoolRef_t pool,
663  size_t numObjects
664 );
666 
667 
668 #ifndef LE_MEM_TRACE
669  //----------------------------------------------------------------------------------------------
683  //----------------------------------------------------------------------------------------------
684  void le_mem_Release
685  (
686  void* objPtr
687  );
688 #else
689  void _le_mem_Release(void* objPtr);
692 
693  #define le_mem_Release(objPtr) \
694  _le_mem_Trace(_le_mem_GetBlockPool(objPtr), \
695  __FILE__, \
696  __FUNCTION__, \
697  __LINE__, \
698  "le_mem_Release", \
699  (objPtr)); \
700  _le_mem_Release(objPtr);
701 #endif
702 
703 
704 #ifndef LE_MEM_TRACE
705  //----------------------------------------------------------------------------------------------
714  //----------------------------------------------------------------------------------------------
715  void le_mem_AddRef
716  (
717  void* objPtr
718  );
719 #else
720  void _le_mem_AddRef(void* objPtr);
723 
724  #define le_mem_AddRef(objPtr) \
725  _le_mem_Trace(_le_mem_GetBlockPool(objPtr), \
726  __FILE__, \
727  __FUNCTION__, \
728  __LINE__, \
729  "le_mem_AddRef", \
730  (objPtr)); \
731  _le_mem_AddRef(objPtr);
732 #endif
733 
734 
735 //--------------------------------------------------------------------------------------------------
744 //--------------------------------------------------------------------------------------------------
746 (
747  le_mem_PoolRef_t pool,
748  le_mem_Destructor_t destructor
749 );
750 
751 
752 //--------------------------------------------------------------------------------------------------
759 //--------------------------------------------------------------------------------------------------
760 void le_mem_GetStats
761 (
762  le_mem_PoolRef_t pool,
763  le_mem_PoolStats_t* statsPtr
764 );
765 
766 
767 //--------------------------------------------------------------------------------------------------
774 //--------------------------------------------------------------------------------------------------
776 (
777  le_mem_PoolRef_t pool
778 );
779 
780 
781 //--------------------------------------------------------------------------------------------------
792 //--------------------------------------------------------------------------------------------------
794 (
795  le_mem_PoolRef_t pool,
796  char* namePtr,
797  size_t bufSize
798 );
799 
800 
801 //--------------------------------------------------------------------------------------------------
809 //--------------------------------------------------------------------------------------------------
810 const bool le_mem_IsSubPool
811 (
812  le_mem_PoolRef_t pool
813 );
814 
815 
816 //--------------------------------------------------------------------------------------------------
824 //--------------------------------------------------------------------------------------------------
826 (
827  le_mem_PoolRef_t pool
828 );
829 
830 
831 //--------------------------------------------------------------------------------------------------
838 //--------------------------------------------------------------------------------------------------
840 (
841  le_mem_PoolRef_t pool
842 );
843 
844 
845 //--------------------------------------------------------------------------------------------------
852 //--------------------------------------------------------------------------------------------------
854 (
855  le_mem_PoolRef_t pool
856 );
857 
858 
859 //--------------------------------------------------------------------------------------------------
865 //--------------------------------------------------------------------------------------------------
866 le_mem_PoolRef_t _le_mem_FindPool
867 (
868  const char* componentName,
869  const char* name
870 );
872 
873 
874 //--------------------------------------------------------------------------------------------------
881 //--------------------------------------------------------------------------------------------------
882 static inline le_mem_PoolRef_t le_mem_FindPool
883 (
884  const char* name
885 )
886 {
887  return _le_mem_FindPool(STRINGIZE(LEGATO_COMPONENT), name);
888 }
889 
890 
891 //--------------------------------------------------------------------------------------------------
897 //--------------------------------------------------------------------------------------------------
898 le_mem_PoolRef_t _le_mem_CreateSubPool
899 (
900  le_mem_PoolRef_t superPool,
901  const char* componentName,
902  const char* name,
903  size_t numObjects
905 );
907 
908 
909 //--------------------------------------------------------------------------------------------------
919 //--------------------------------------------------------------------------------------------------
921 (
922  le_mem_PoolRef_t superPool,
923  const char* name,
924  size_t numObjects
926 )
927 {
928  return _le_mem_CreateSubPool(superPool, STRINGIZE(LEGATO_COMPONENT), name, numObjects);
929 }
930 
931 
932 //--------------------------------------------------------------------------------------------------
941 //--------------------------------------------------------------------------------------------------
943 (
944  le_mem_PoolRef_t subPool
945 );
946 
947 
948 #endif // LEGATO_MEM_INCLUDE_GUARD
void * le_mem_TryAlloc(le_mem_PoolRef_t pool)
le_mem_PoolRef_t le_mem_ExpandPool(le_mem_PoolRef_t pool, size_t numObjects)
uint64_t numAllocs
Number of times an object has been allocated from this pool.
Definition: le_mem.h:446
le_result_t
Definition: le_basics.h:35
void * le_mem_AssertAlloc(le_mem_PoolRef_t pool)
void le_mem_GetStats(le_mem_PoolRef_t pool, le_mem_PoolStats_t *statsPtr)
const bool le_mem_IsSubPool(le_mem_PoolRef_t pool)
size_t numBlocksInUse
Number of currently allocated blocks.
Definition: le_mem.h:443
static le_mem_PoolRef_t le_mem_FindPool(const char *name)
Definition: le_mem.h:883
size_t maxNumBlocksUsed
Maximum number of allocated blocks at any one time.
Definition: le_mem.h:444
#define STRINGIZE(x)
Definition: le_basics.h:205
void le_mem_SetDestructor(le_mem_PoolRef_t pool, le_mem_Destructor_t destructor)
static le_mem_PoolRef_t le_mem_CreatePool(const char *name, size_t objSize)
Definition: le_mem.h:529
void le_mem_ResetStats(le_mem_PoolRef_t pool)
void le_mem_SetNumObjsToForce(le_mem_PoolRef_t pool, size_t numObjects)
void le_mem_DeleteSubPool(le_mem_PoolRef_t subPool)
struct le_mem_Pool * le_mem_PoolRef_t
Definition: le_mem.h:414
le_result_t le_mem_GetName(le_mem_PoolRef_t pool, char *namePtr, size_t bufSize)
void le_mem_Release(void *objPtr)
size_t numFree
Number of free objects currently available in this pool.
Definition: le_mem.h:447
size_t numOverflows
Number of times le_mem_ForceAlloc() had to expand the pool.
Definition: le_mem.h:445
void(* le_mem_Destructor_t)(void *objPtr)
Definition: le_mem.h:431
size_t le_mem_GetObjectCount(le_mem_PoolRef_t pool)
Definition: le_mem.h:441
size_t le_mem_GetObjectFullSize(le_mem_PoolRef_t pool)
size_t le_mem_GetObjectSize(le_mem_PoolRef_t pool)
void le_mem_AddRef(void *objPtr)
void * le_mem_ForceAlloc(le_mem_PoolRef_t pool)
static le_mem_PoolRef_t le_mem_CreateSubPool(le_mem_PoolRef_t superPool, const char *name, size_t numObjects)
Definition: le_mem.h:921