Example #1
0
void *dbfile_more_mem(mmfile_t *mm, uint32_t *size)
{
	uint64_t chunksize;
	dbroot_t *root;
	int n, rc;
	void *ret = NULL;

	root = (dbroot_t*)mm->map[0].ptr;
	chunksize = root->meta.chunksize;
	mm_lock(mm, MLCK_WR, __offset(mm, &root->resize), sizeof(root->resize));
	if (mm->size == mm_size(mm)) {
		log_debug("Resizing mmfile +%d bytes", chunksize);
		rc = mm_resize(mm, mm->size + chunksize);
		if (rc != 0) {
			log_error("Resize failed"); abort();
		}
		n = mm->nmap-1;
		*size = mm->map_offset[n].size;
		ret = mm->map_offset[n].ptr;
	} else {
		chunksize = mm_size(mm);
		log_debug("Expanding mapping to 0x%x bytes", chunksize);
		mm_resize(mm, chunksize);
	}
	mm_lock(mm, MLCK_UN, __offset(mm, &root->resize), sizeof(root->resize));
	return ret;
}
Example #2
0
File: mm.c Project: 29n/xunsearch
void *mm_malloc(MM *mm, size_t size)
{
	void *ret;

	if (!mm_lock(mm))
		return NULL;
	ret = mm_malloc_nolock(mm, size);
	mm_unlock(mm);
	return ret;
}
Example #3
0
File: mm.c Project: 29n/xunsearch
size_t mm_available(MM *mm)
{
	size_t available;

	if (mm != NULL && mm_lock(mm))
	{
		available = mm->available;
		mm_unlock(mm);
		return available;
	}
	return 0;
}
Example #4
0
File: mm.c Project: 29n/xunsearch
size_t mm_sizeof(MM *mm, void *x)
{
	mm_mem_head *p;
	size_t ret;

	if (mm == NULL || x == NULL || !mm_lock(mm))
		return 0;
	p = PTR_TO_HEAD(x);
	ret = p->size;
	mm_unlock(mm);
	return ret;
}
Example #5
0
int _dbmemlock(pgctx_t *ctx, memblock_t *mb, uint32_t op)
{
#ifndef PMEM_LOCKFREE
	uint64_t chunk;
	uint64_t locksz;

	chunk = mb->mb_offset + mb->pg_size;
	locksz = mb->pg_count * sizeof(uint32_t);
	return mm_lock(&ctx->mm, op, chunk, locksz);
#endif
	return 0;
}
Example #6
0
File: mm.c Project: 29n/xunsearch
size_t mm_maxsize(MM *mm)
{
	size_t ret = MM_SIZE(0);
	mm_free_bucket *p;

	if (!mm_lock(mm))
		return 0;

	p = mm->free_list;
	while (p != NULL)
	{
		if (p->size > ret)
			ret = p->size;
		p = p->next;
	}
	mm_unlock(mm);
	return ret - MM_SIZE(0);
}
Example #7
0
int MM_lock(mm_lock_mode mode)
{
    if (mm_global == NULL)
        return FALSE;
    return mm_lock(mm_global, mode);
}
Example #8
0
File: mm.c Project: 29n/xunsearch
void mm_free(MM *mm, void *x)
{
	mm_lock(mm);
	mm_free_nolock(mm, x);
	mm_unlock(mm);
}