Memory handling fixes
[o-du/l2.git] / src / 5gnrrlc / rlc_utils.h
index 51504f8..3645a85 100755 (executable)
@@ -103,12 +103,22 @@ extern "C" {
  *                              Memory related Defines 
  ******************************************************************************/
 /* Allocate function */
+#ifdef ODU_MEMORY_DEBUG_LOG
+#define RLC_MEM_LOG(_macro, _file, _line, _func, _size, _datPtr)\
+{\
+   printf("\n%s=== %s +%d, %s, %d, %p\n",           \
+         _macro, _file, _line, _func, _size, _datPtr); \
+}
+#else
+#define RLC_MEM_LOG(_macro, _file, _line, _func, _size, _dataPtr) {}
+#endif
 
 #define RLC_ALLOC(_cb,_buf, _size)                                    \
 {                                                                    \
  if (SGetSBuf(_cb->init.region, _cb->init.pool, (Data **)&_buf,      \
                 (Size) _size) == ROK)                                \
    {                                                                 \
+      RLC_MEM_LOG("RLC_ALLOC", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
       memset((_buf), 0, _size);                              \
    }                                                                 \
    else                                                              \
@@ -121,6 +131,7 @@ extern "C" {
 {                                                         \
    if (_buf != NULLP)                                     \
    {                                                      \
+      RLC_MEM_LOG("RLC_FREE", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
       (Void) SPutSBuf(_cb->init.region, _cb->init.pool,   \
             (Data *) _buf, (Size) _size);                 \
       _buf = NULLP;                                       \
@@ -130,7 +141,8 @@ extern "C" {
 #define RLC_FREE_SHRABL_BUF(_region, _pool,_buf, _size)    \
 {                                                         \
    if (_buf != NULLP)                                     \
-   {                                                      \
+   { \
+      RLC_MEM_LOG("RLC_FREE_SHRABL_BUF", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
       (Void) SPutStaticBuffer(_region, _pool,             \
             (Data *) _buf, (Size) _size, 0);                 \
       _buf = NULLP;                                       \
@@ -139,15 +151,25 @@ extern "C" {
 
 #define RLC_FREE_SHRABL_BUF_WC(_region, _pool,_buf, _size) \
 {                                                         \
+ if (_buf != NULLP){\
+      RLC_MEM_LOG("RLC_FREE_SHRABL_BUF_WC", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
   (Void) SPutStaticBuffer(_region, _pool,                 \
         (Data *) _buf, (Size) _size, 0);                 \
-  _buf = NULLP;                                       \
+  _buf = NULLP;      \
+  }\
 }
 
 #define RLC_ALLOC_SHRABL_BUF_WC(_region, _pool,_buf, _size)           \
 {                                                                    \
- SGetStaticBuffer(_region, _pool, (Data **)&_buf,                    \
-                (Size) _size, 0);                                    \
+   if(SGetStaticBuffer(_region, _pool, (Data **)&_buf,                    \
+            (Size) _size, 0)==ROK)                                    \
+   {\
+      RLC_MEM_LOG("RLC_ALLOC_SHRABL_BUF_WC", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
+   }\
+   else\
+   {\
+      (_buf) = NULLP;\
+   }\
 }
 
 #define RLC_ALLOC_SHRABL_BUF(_region, _pool,_buf, _size)              \
@@ -155,6 +177,7 @@ extern "C" {
  if (SGetStaticBuffer(_region, _pool, (Data **)&_buf,                \
                 (Size) _size, 0) == ROK)                                \
    {                                                                 \
+      RLC_MEM_LOG("RLC_ALLOC_SHRABL_BUF", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
       memset((_buf), 0, _size);                              \
    }                                                                 \
    else                                                              \
@@ -164,13 +187,19 @@ extern "C" {
 }
 
 #define RLC_ALLOC_WC(_cb,_buf, _size)  \
-           SGetSBuf(_cb->init.region, _cb->init.pool, (Data **)&_buf, (Size) _size)     
+{\
+   if(SGetSBuf(_cb->init.region, _cb->init.pool, (Data **)&_buf, (Size) _size) == ROK)\
+   {\
+      RLC_MEM_LOG("RLC_ALLOC_WC", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
+   }\
+}
 
 #define RLC_REMOVE_SDU(_cb,_sduQ,_sdu)              \
 {                                               \
    if(_sdu->mBuf)                               \
    {                                            \
-      SPutMsg(_sdu->mBuf);    \
+      RLC_MEM_LOG("RLC_REMOVE_SDU", __FILE__, __LINE__, __FUNCTION__, _sdu->sduSz, _sdu->mBuf);\
+      ODU_PUT_MSG_BUF(_sdu->mBuf);    \
    }                                            \
    cmLListDelFrm(_sduQ,&_sdu->lstEnt);          \
    RLC_FREE(_cb,_sdu, sizeof(RlcSdu));            \
@@ -181,6 +210,7 @@ extern "C" {
 {                                                         \
    if (_buf != NULLP)                                     \
    {                                                      \
+      RLC_MEM_LOG("RLC_PST_FREE", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
       (Void) SPutSBuf(_region, _pool,                     \
                       (Data *) _buf, (Size) _size);       \
       _buf = NULLP;                                       \
@@ -230,16 +260,18 @@ extern "C" {
 {                                                                  \
    if (_buf != NULLP)                                              \
    {                                                               \
+      RLC_MEM_LOG("RLC_SHRABL_STATIC_BUF_FREE", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
       (Void) SPutStaticBuffer(_region, _pool,                      \
-                      (Data *) _buf, (Size) _size, 0);             \
+            (Data *) _buf, (Size) _size, 0);             \
       _buf = NULLP;                                                \
    }                                                               \
 }
 
 #define RLC_SHRABL_STATIC_BUF_ALLOC(_region, _pool, _buf, _size)     \
 {                                                                        \
- SGetStaticBuffer(_region, _pool, (Data **)&_buf,      \
-                (Size) _size, 0);                                        \
+   SGetStaticBuffer(_region, _pool, (Data **)&_buf,      \
+         (Size) _size, 0);                                        \
+   RLC_MEM_LOG("RLC_SHRABL_STATIC_BUF_ALLOC", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
 }
 #endif