pike.git / src / block_allocator.c

version» Context lines:

pike.git/src/block_allocator.c:86:   }      PMOD_EXPORT INLINE void ba_init(struct block_allocator * a,    uint32_t block_size, ba_page_t blocks) {    uint32_t page_size = block_size * blocks;       a->first = NULL;    a->last_free = NULL;    a->last_free_num = 0;    -  if ((page_size & (page_size - 1)) == 0) -  a->magnitude = (uint16_t)ctz32(page_size); -  else -  a->magnitude = (uint16_t)ctz32(round_up32(page_size)); +  if ((page_size & (page_size - 1))) { +  page_size = round_up32(page_size); +  a->blocks = page_size/block_size; +  } else a->blocks = blocks;    -  +  a->magnitude = (uint16_t)ctz32(page_size);    a->block_size = block_size; -  a->blocks = (1 << a->magnitude) / block_size; +     a->num_pages = 0;    a->empty_pages = 0;    a->max_empty_pages = BA_MAX_EMPTY;       // we start with management structures for 16 pages    a->allocated = BA_ALLOC_INITIAL;    a->pages = NULL;    ba_realloc(a);   }   
pike.git/src/block_allocator.c:451:    a->first = p;    IF_HASH(    ba_htable_insert(a, BA_LASTBLOCK(a, p), a->num_pages);   #ifdef BA_DEBUG    ba_check_allocator(a, "ba_alloc after insert", __FILE__, __LINE__);   #endif    );    p->blocks_used = 1;    p->first = BA_BLOCKN(a, p, 1);    +  if (a->blueprint) { +  size_t len = (a->blocks - 1) * a->block_size, clen = a->block_size; +  memcpy(p+1, a->blueprint, a->block_size); +  +  while (len > clen) { +  memcpy(((char*)(p+1)) + clen, p+1, clen); +  len -= clen; +  clen <<= 1; +  } +  +  if (len) memcpy(((char*)(p+1)) + clen, p+1, len); +  } +     for (i = 1; i+1 < a->blocks; i++) {   #ifdef BA_DEBUG    PIKE_MEM_RW(BA_BLOCKN(a, p, i)->magic);    BA_BLOCKN(a, p, i)->magic = BA_MARK_FREE;   #endif    BA_BLOCKN(a, p, i)->next = BA_BLOCKN(a, p, i+1);    }    BA_LASTBLOCK(a, p)->next = NULL;    //memset(p->data, 0x00, BA_PAGESIZE(a));   #ifdef BA_DEBUG