Exemplo n.º 1
0
void leaf_new(struct hdr *hdr,
              NID nid,
              uint32_t height,
              uint32_t children,
              struct node **n)
{
	struct node *node;

	nassert(height == 0);
	nassert(children == 1);
	node = xcalloc(1, sizeof(*node));
	nassert(node);
	node->nid = nid;
	node->height = height;
	ness_mutex_init(&node->attr.mtx);
	ness_mutex_init(&node->mtx);
	ness_rwlock_init(&node->rwlock, &node->mtx);

	node->n_children = children;
	node->layout_version = hdr->layout_version;

	if (children > 0) {
		node->pivots = xcalloc(children - 1, PIVOT_SIZE);
		node->parts = xcalloc(children, PART_SIZE);
	}

	node->opts = hdr->opts;
	node->i = &leaf_operations;
	node_set_dirty(node);

	*n = node;
}
Exemplo n.º 2
0
struct block *block_new(struct status *status) {
	struct block *b;

	b = xcalloc(1, sizeof(*b));
	mutex_init(&b->mtx);
	ness_rwlock_init(&b->rwlock);
	b->allocated += ALIGN(BLOCK_OFFSET_START);
	b->status = status;

	return b;
}
Exemplo n.º 3
0
struct nmb *nmb_new(struct tree_options *opts)
{
	struct nmb *nmb = xmalloc(sizeof(*nmb));

	nmb->mpool = mempool_new();
	nmb->pma = pma_new(64);
	nmb->opts = opts;
	nmb->count = 0;

	ness_mutex_init(&nmb->mtx);
	ness_rwlock_init(&nmb->rwlock, &nmb->mtx);

	return nmb;
}
Exemplo n.º 4
0
struct node *leaf_alloc_empty(NID nid) {
	struct node *node;

	node = xcalloc(1, sizeof(*node));
	node->nid = nid;
	node->height = 0;
	node->node_op = &nop;

	mutex_init(&node->u.l.mtx);
	mutex_init(&node->attr.mtx);
	ness_rwlock_init(&node->u.l.rwlock);

	return node;
}
Exemplo n.º 5
0
struct node *nonleaf_alloc_empty(NID nid, uint32_t height, uint32_t children) {
	int i;
	struct node *node;

	nassert(height > 0);
	nassert(children > 0);

	node = xcalloc(1, sizeof(*node));
	node->nid = nid;
	node->height = height;
	node->node_op = &nop;
	node->u.n.n_children = children;

	node->u.n.pivots = xcalloc(children - 1, PIVOT_SIZE);
	node->u.n.parts = xcalloc(children, PART_SIZE);

	for (i = 0; i < (int)children; i++) {
		mutex_init(&node->u.n.parts[i].mtx);
		ness_rwlock_init(&node->u.n.parts[i].rwlock);
	}
	mutex_init(&node->attr.mtx);

	return node;
}