Exemple #1
0
/*
    vpx_memory_tracker_init(int padding_size, int pad_value)
      padding_size - the size of the padding before and after each mem addr.
                     Values > 0 indicate that integrity checks can be performed
                     by inspecting these areas.
      pad_value - the initial value within the padding area before and after
                  each mem addr.

    Initializes global memory tracker structure
    Allocates the head of the list
*/
int vpx_memory_tracker_init(int padding_size, int pad_value)
{
    if (!g_b_mem_tracker_inited)
    {
        if (memtrack.head = (struct mem_block *)MEM_TRACK_MALLOC(sizeof(struct mem_block)))
        {
            int ret;

            MEM_TRACK_MEMSET(memtrack.head, 0, sizeof(struct mem_block));

            memtrack.tail = memtrack.head;

            memtrack.current_allocated = 0;
            memtrack.max_allocated     = 0;

            memtrack.padding_size = padding_size;
            memtrack.pad_value    = pad_value;

#if defined(LINUX) || defined(__uClinux__)
            ret = pthread_mutex_init(&memtrack.mutex,
                                     NULL);            /*mutex attributes (NULL=default)*/
#elif defined(WIN32) || defined(_WIN32_WCE)
            memtrack.mutex = create_mutex(NULL,   /*security attributes*/
                                          FALSE,  /*we don't want initial ownership*/
                                          NULL);  /*mutex name*/
            ret = !memtrack.mutex;
#elif defined(VXWORKS)
            memtrack.mutex = sem_bcreate(SEM_Q_FIFO, /*SEM_Q_FIFO non-priority based mutex*/
                                         SEM_FULL);  /*SEM_FULL initial state is unlocked*/
            ret = !memtrack.mutex;
#elif defined(NDS_NITRO)
            os_init_mutex(&memtrack.mutex);
            ret = 0;
#elif defined(NO_MUTEX)
            ret = 0;
#endif

            if (ret)
            {
                memtrack_log("vpx_memory_tracker_init: Error creating mutex!\n");

                MEM_TRACK_FREE(memtrack.head);
                memtrack.head = NULL;
            }
            else
            {
                memtrack_log("Memory Tracker init'd, v."vpx_mem_tracker_version" pad_size:%d pad_val:0x%x %d\n"
                             , padding_size
                             , pad_value
                             , pad_value);
                g_b_mem_tracker_inited = 1;
            }
        }
    }

    return g_b_mem_tracker_inited;
}
int vpx_memory_tracker_init(int padding_size, int pad_value) {
  if (!g_b_mem_tracker_inited) {
    if ((memtrack.head = (struct mem_block *)
                         MEM_TRACK_MALLOC(sizeof(struct mem_block)))) {
      int ret;

      MEM_TRACK_MEMSET(memtrack.head, 0, sizeof(struct mem_block));

      memtrack.tail = memtrack.head;

      memtrack.current_allocated = 0;
      memtrack.max_allocated     = 0;

      memtrack.padding_size = padding_size;
      memtrack.pad_value    = pad_value;

#if HAVE_PTHREAD_H
      ret = pthread_mutex_init(&memtrack.mutex,
                               NULL);            
#elif defined(WIN32) || defined(_WIN32_WCE)
      memtrack.mutex = CreateMutex(NULL,   
                                   FALSE,  
                                   NULL);  
      ret = !memtrack.mutex;
#elif defined(VXWORKS)
      memtrack.mutex = sem_bcreate(SEM_Q_FIFO, 
                                   SEM_FULL);  
      ret = !memtrack.mutex;
#elif defined(NO_MUTEX)
      ret = 0;
#endif

      if (ret) {
        memtrack_log("vpx_memory_tracker_init: Error creating mutex!\n");

        MEM_TRACK_FREE(memtrack.head);
        memtrack.head = NULL;
      } else {
        memtrack_log("Memory Tracker init'd, v."vpx_mem_tracker_version" pad_size:%d pad_val:0x%x %d\n"
, padding_size
, pad_value
, pad_value);
        g_b_mem_tracker_inited = 1;
      }
    }
  }

  return g_b_mem_tracker_inited;
}