コード例 #1
0
/**
 * Free the chunk
 */
void
mem_pools_free (uint8_t *chunk_p) /**< pointer to the chunk */
{
  mem_pool_state_t *pool_state = mem_pools, *prev_pool_state_p = NULL;

  /**
   * Search for the pool containing specified chunk.
   */
  while (!mem_pool_is_chunk_inside (pool_state, chunk_p))
  {
    prev_pool_state_p = pool_state;
    pool_state = MEM_CP_GET_NON_NULL_POINTER (mem_pool_state_t, pool_state->next_pool_cp);
  }

  /**
   * Free the chunk
   */
  mem_pool_free_chunk (pool_state, chunk_p);
  mem_free_chunks_number++;

  MEM_POOLS_STAT_FREE_CHUNK ();

  /**
   * If all chunks of the pool are free, free the pool itself.
   */
  if (pool_state->free_chunks_number == MEM_POOL_CHUNKS_NUMBER)
  {
    if (prev_pool_state_p != NULL)
    {
      prev_pool_state_p->next_pool_cp = pool_state->next_pool_cp;
    }
    else
    {
      mem_pools = MEM_CP_GET_POINTER (mem_pool_state_t, pool_state->next_pool_cp);
    }

    mem_free_chunks_number -= MEM_POOL_CHUNKS_NUMBER;

    mem_heap_free_block ((uint8_t*) pool_state);

    MEM_POOLS_STAT_FREE_POOL ();
  }
  else if (mem_pools != pool_state)
  {
    JERRY_ASSERT (prev_pool_state_p != NULL);

    prev_pool_state_p->next_pool_cp = pool_state->next_pool_cp;
    MEM_CP_SET_NON_NULL_POINTER (pool_state->next_pool_cp, mem_pools);
    mem_pools = pool_state;
  }
} /* mem_pools_free */
コード例 #2
0
ファイル: mem-poolman.cpp プロジェクト: qdk0901/iotjs-openwrt
/**
 * Free the chunk
 */
void __attr_always_inline___
mem_pools_free (uint8_t *chunk_p) /**< pointer to the chunk */
{
    mem_check_pools ();

    mem_pool_chunk_t *chunk_to_free_p = (mem_pool_chunk_t *) chunk_p;

    chunk_to_free_p->u.free.next_p = mem_free_chunk_p;
    mem_free_chunk_p = chunk_to_free_p;

    VALGRIND_FREYA_FREELIKE_SPACE (chunk_to_free_p);
    VALGRIND_NOACCESS_SPACE (chunk_to_free_p, MEM_POOL_CHUNK_SIZE);

#ifndef JERRY_NDEBUG
    mem_free_chunks_number++;
#endif /* !JERRY_NDEBUG */

    MEM_POOLS_STAT_FREE_CHUNK ();

    mem_check_pools ();
} /* mem_pools_free */