ext/iodine/fio.c
/* allocates memory from within a block - called within an arena's lock */
allocates memory from within a block - called within an arena's lock
allocates memory from within a block - called within an arena ' s lock
static inline void *block_slice(uint16_t units) {
  block_s *blk = arena_last_used->block;
  if (!blk) {
    blk = block_new();
    arena_last_used->block = blk;
  } else if (blk->pos + units > FIO_MEMORY_MAX_SLICES_PER_BLOCK) {
    block_free(blk);
    blk = block_new();
    arena_last_used->block = blk;
  }
  if (!blk) {
    errno = ENOMEM;
    return NULL;
  }
  const void *mem = (void *)((uintptr_t)blk + ((uintptr_t)blk->pos << 4));
  fio_atomic_add(&blk->ref, 1);
  blk->pos += units;
  if (blk->pos >= FIO_MEMORY_MAX_SLICES_PER_BLOCK) {
    block_free(blk);
    arena_last_used->block = NULL;
  }
  return (void *)mem;
}
static inline void * block_slice ( uint16_t units ) { block_s * blk = arena_last_used -> block ; if ( ! blk ) { blk = block_new ( ) ; arena_last_used -> block = blk ; } else if ( blk -> pos + units > FIO_MEMORY_MAX_SLICES_PER_BLOCK ) { block_free ( blk ) ; blk = block_new ( ) ; arena_last_used -> block = blk ; } if ( ! blk ) { errno = ENOMEM ; return NULL ; } const void * mem = ( void * ) ( ( uintptr_t ) blk + ( ( uintptr_t ) blk -> pos << 4 ) ) ; fio_atomic_add ( & blk -> ref , 1 ) ; blk -> pos += units ; if ( blk -> pos >= FIO_MEMORY_MAX_SLICES_PER_BLOCK ) { block_free ( blk ) ; arena_last_used -> block = NULL ; } return ( void * ) mem ; }
allocates memory from within a block - called within an arena's lock
allocates memory from within a block - called within an arena ' s lock
/* arena is empty */ /* not enough memory in the block - rotate */ /* no system memory available? */ /* slice block starting at blk->pos and increase reference count */ /* ... the block was fully utilized, clear arena */