示例#1
0
文件: mempool.c 项目: now/ned
HIDDEN void *
mem_pool_alloc(MemPool *pool, size_t size)
{
        assert(pool != NULL);

        if (pool->free < size)
                mem_block_new(pool, size);

        size += POINTER_ALIGN(size);
        pool->base += size;
        pool->free -= size;

        return pool->base - size;
}
示例#2
0
文件: lockbench.c 项目: fgp/lockbench
volatile char *shm_alloc(unsigned int size, char align) {
	if (align < 1)
		align = CACHELINE_SIZE;
	
	volatile char *shm = POINTER_ALIGN(shm_next, align);
	if (shm < shm_next)
		die(0, "failed to align pointer at %d", align);
	if ((unsigned long)((char *) shm) % align != 0)
		die(0, "failed to align pointer at %d", align);
	
	if (shm + size >= shm_base + SHM_SIZE)
		die(0, "shared memory segment too small");
		
	shm_next = shm + size;
	return shm;
}