Beispiel #1
0
// for GS_ARENA, count must be 4, 8, 16 or 20
void *__gs_mempool_alloc(unsigned int arena_id, unsigned int count)
{
  gs_arena_t *arena = &gs_mempool[arena_id];
  gs_memblock_t *memblk = arena->lastblock;
  if (memblk == NULL) {
#ifdef TARG_IA64
    // On IA64, the sizeof(gspin_t) is 32
    GS_ASSERT(sizeof(gspin_t) == 32, "struct gspin size has changed.");
#else
    GS_ASSERT(sizeof(gspin_t) == 20, "struct gspin size has changed.");
#endif
    memblk = gs_new_memblock(0);
    arena->firstblock = arena->lastblock = memblk;
    arena->current_index = 0;
  }
  else if ((arena->current_index + count - 1) >=
           ((memblk->block_id + 1) << GS_BLOCK_IDX_SHIFT_AMT)) {
    memblk = gs_new_memblock(memblk->block_id + 1);
    arena->lastblock->next = memblk;
    arena->lastblock = memblk;
    if (count > 1) // this is needed to gaurantee locations to be contiguous
      arena->current_index = memblk->block_id * GS_MEMBLOCK_SIZE;
  }
  gs_void_t *p = &memblk->mem[arena->current_index & GS_OFST_IN_BLK_MASK];
  arena->current_index += count;
  return p;
}
Beispiel #2
0
// for GS_ARENA, count must be 4, 8, 16 or 20
void *__gs_mempool_alloc(unsigned int arena_id, unsigned int count)
{
    gs_arena_t *arena = &gs_mempool[arena_id];
    gs_memblock_t *memblk = arena->lastblock;
    if (memblk == NULL) {
        memblk = gs_new_memblock(0);
        arena->firstblock = arena->lastblock = memblk;
        arena->current_index = 0;
    }
    else if ((arena->current_index + count - 1) >=
             ((memblk->block_id + 1) << GS_BLOCK_IDX_SHIFT_AMT)) {
        memblk = gs_new_memblock(memblk->block_id + 1);
        arena->lastblock->next = memblk;
        arena->lastblock = memblk;
        if (count > 1) // this is needed to gaurantee locations to be contiguous
            arena->current_index = memblk->block_id * GS_MEMBLOCK_SIZE;
    }
    gs_void_t *p = &memblk->mem[arena->current_index & GS_OFST_IN_BLK_MASK];
    arena->current_index += count;
    return p;
}