示例#1
0
文件: obj_ctree.c 项目: janekmi/nvml
static void
test_ctree_insert()
{
	struct ctree *t = ctree_new();
	UT_ASSERT(t != NULL);

	Rcounter_malloc = TEST_INSERT;

	UT_ASSERT(ctree_is_empty(t));

	/* leaf Malloc fail */
	UT_ASSERT(ctree_insert(t, TEST_VAL_A, 0) != 0);

	/* all OK root */
	UT_ASSERT(ctree_insert(t, TEST_VAL_B, 0) == 0); /* insert +2 mallocs */

	/* accessor Malloc fail */
	UT_ASSERT(ctree_insert(t, TEST_VAL_A, 0) != 0);

	/* insert duplicate */
	UT_ASSERT(ctree_insert(t, TEST_VAL_B, 0) != 0);

	/* all OK second */
	UT_ASSERT(ctree_insert(t, TEST_VAL_A, 0) == 0);

	UT_ASSERT(!ctree_is_empty(t));

	ctree_delete(t);
}
示例#2
0
文件: bucket.c 项目: JLLLinn/nvml
/*
 * bucket_tree_delete -- (internal) deletes a tree container
 */
static void
bucket_tree_delete(struct block_container *bc)
{
	struct block_container_ctree *c = (struct block_container_ctree *)bc;
	ctree_delete(c->tree);
	Free(bc);
}
示例#3
0
文件: obj_ctree.c 项目: janekmi/nvml
static void
test_ctree_remove()
{
	struct ctree *t = ctree_new();
	UT_ASSERT(t != NULL);

	Rcounter_malloc = TEST_REMOVE;

	/* remove from empty tree */
	UT_ASSERT(ctree_remove(t, TEST_VAL_A, 0) == 0);

	/* insert 2 valid values */
	UT_ASSERT(ctree_insert(t, TEST_VAL_A, 0) == 0);
	UT_ASSERT(ctree_insert(t, TEST_VAL_B, 0) == 0);

	/* fail to remove equal greater */
	UT_ASSERT(ctree_remove(t, TEST_VAL_C, 0) == 0);

	/* remove accessor */
	UT_ASSERT(ctree_remove(t, TEST_VAL_A, 1) == TEST_VAL_A);

	/* remove root */
	UT_ASSERT(ctree_remove(t, TEST_VAL_B, 1) == TEST_VAL_B);

	ctree_delete(t);
}
示例#4
0
/*
 * obj_fini -- cleanup of obj
 *
 * Called by destructor.
 */
void
obj_fini(void)
{
	LOG(3, NULL);
	cuckoo_delete(pools_ht);
	ctree_delete(pools_tree);
}
示例#5
0
文件: bucket.c 项目: perone/nvml
/*
 * bucket_delete -- cleanups and deallocates bucket instance
 */
void
bucket_delete(struct bucket *b)
{
	if ((errno = pthread_mutex_destroy(&b->lock)) != 0)
		ERR("!pthread_mutex_destroy");

	ctree_delete(b->tree);
	Free(b);
}
示例#6
0
文件: bucket.c 项目: jxy859/nvml
/*
 * bucket_new -- allocates and initializes bucket instance
 */
struct bucket *
bucket_new(size_t unit_size, int unit_max)
{
	ASSERT(unit_size > 0);

	struct bucket *b = Malloc(sizeof (*b));
	if (b == NULL)
		goto error_bucket_malloc;

	b->tree = ctree_new();
	if (b->tree == NULL)
		goto error_tree_new;

	if ((errno = pthread_mutex_init(&b->lock, NULL)) != 0) {
		ERR("!pthread_mutex_init");
		goto error_mutex_init;
	}

	b->unit_size = unit_size;
	b->unit_max = unit_max;

	if (bucket_is_small(b)) {
		b->bitmap_nallocs = RUNSIZE / unit_size;

		ASSERT(b->bitmap_nallocs <= RUN_BITMAP_SIZE);

		int unused_bits = RUN_BITMAP_SIZE - b->bitmap_nallocs;
		int unused_values = unused_bits / BITS_PER_VALUE;
		b->bitmap_nval = MAX_BITMAP_VALUES - unused_values;
		unused_bits -= (unused_values * BITS_PER_VALUE);

		ASSERT(unused_bits >= 0);

		b->bitmap_lastval = unused_bits ?
			(((1ULL << unused_bits) - 1ULL) <<
				(BITS_PER_VALUE - unused_bits)) : 0;
	} else {
		b->bitmap_nval = 0;
		b->bitmap_lastval = 0;
		b->bitmap_nallocs = 0;
	}

	return b;

error_mutex_init:
	ctree_delete(b->tree);
error_tree_new:
	Free(b);
error_bucket_malloc:
	return NULL;
}
示例#7
0
文件: obj_ctree.c 项目: janekmi/nvml
static void
test_ctree_new_delete_empty()
{
	struct ctree *t = NULL;

	Rcounter_malloc = TEST_NEW_DELETE;

	/* t Malloc fail */
	t = ctree_new();
	UT_ASSERT(t == NULL);

	/* all OK and delete */
	t = ctree_new();
	UT_ASSERT(t != NULL);

	ctree_delete(t);
}
示例#8
0
文件: obj_ctree.c 项目: janekmi/nvml
static void
test_ctree_find()
{
	struct ctree *t = ctree_new();
	UT_ASSERT(t != NULL);

	/* search empty tree */
	uint64_t k = TEST_VAL_A;
	UT_ASSERT(ctree_find_le(t, &k) == 0);

	/* insert 2 valid elements */
	UT_ASSERT(ctree_insert(t, TEST_VAL_A, TEST_VAL_A) == 0);
	UT_ASSERT(ctree_insert(t, TEST_VAL_B, TEST_VAL_B) == 0);

	/* search for values */
	k = 0;
	UT_ASSERT(ctree_find_le(t, &k) == 0);
	k = TEST_VAL_A;
	UT_ASSERT(ctree_find_le(t, &k) == TEST_VAL_A);
	k = TEST_VAL_B;
	UT_ASSERT(ctree_find_le(t, &k) == TEST_VAL_B);

	ctree_delete(t);
}