mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
o Debug version of the pool_grow stuff.
This commit is contained in:
parent
9f44467d44
commit
493793dcbc
@ -17,7 +17,9 @@ struct block {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct pool {
|
struct pool {
|
||||||
int object;
|
int begun;
|
||||||
|
struct block *object;
|
||||||
|
|
||||||
struct block *blocks;
|
struct block *blocks;
|
||||||
struct block *tail;
|
struct block *tail;
|
||||||
};
|
};
|
||||||
@ -70,7 +72,7 @@ static void _append_block(struct pool *p, struct block *b)
|
|||||||
p->blocks = p->tail = b;
|
p->blocks = p->tail = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *pool_alloc_aligned(struct pool *p, size_t s, unsigned alignment)
|
static struct block *_new_block(size_t s, unsigned alignment)
|
||||||
{
|
{
|
||||||
/* FIXME: I'm currently ignoring the alignment arg. */
|
/* FIXME: I'm currently ignoring the alignment arg. */
|
||||||
size_t len = sizeof(struct block) + s;
|
size_t len = sizeof(struct block) + s;
|
||||||
@ -84,6 +86,16 @@ void *pool_alloc_aligned(struct pool *p, size_t s, unsigned alignment)
|
|||||||
b->next = NULL;
|
b->next = NULL;
|
||||||
b->size = s;
|
b->size = s;
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *pool_alloc_aligned(struct pool *p, size_t s, unsigned alignment)
|
||||||
|
{
|
||||||
|
struct block *b = _new_block(s, alignment);
|
||||||
|
|
||||||
|
if (!b)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
_append_block(p, b);
|
_append_block(p, b);
|
||||||
return &b->data[0];
|
return &b->data[0];
|
||||||
}
|
}
|
||||||
@ -120,47 +132,49 @@ void pool_free(struct pool *p, void *ptr)
|
|||||||
p->blocks = p->tail = NULL;
|
p->blocks = p->tail = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *pool_begin_object(struct pool *p, size_t init_size)
|
int pool_begin_object(struct pool *p, size_t init_size)
|
||||||
{
|
{
|
||||||
assert(!p->object);
|
assert(!p->begun);
|
||||||
pool_alloc_aligned(p, init_size, DEFAULT_ALIGNMENT);
|
p->begun = 1;
|
||||||
p->object = 1;
|
return 1;
|
||||||
|
|
||||||
return &p->tail->data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *pool_grow_object(struct pool *p, void *buffer, size_t delta)
|
int pool_grow_object(struct pool *p, const void *buffer, size_t delta)
|
||||||
{
|
{
|
||||||
struct block *old = p->tail, *new;
|
struct block *new;
|
||||||
|
|
||||||
assert(buffer == &old->data);
|
assert(p->begun);
|
||||||
|
|
||||||
if (!pool_alloc(p, old->size + delta))
|
if (!(new = _new_block(p->object->size + delta, DEFAULT_ALIGNMENT))) {
|
||||||
return NULL;
|
log_err("Couldn't extend object.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
new = p->tail;
|
if (p->object) {
|
||||||
|
memcpy(&new->data, &p->object->data, p->object->size);
|
||||||
|
dbg_free(p->object);
|
||||||
|
}
|
||||||
|
p->object = new;
|
||||||
|
|
||||||
memcpy(&new->data, &old->data, old->size);
|
return 1;
|
||||||
|
|
||||||
old->next = NULL;
|
|
||||||
pool_free(p, buffer);
|
|
||||||
|
|
||||||
_append_block(p, new);
|
|
||||||
return &new->data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *pool_end_object(struct pool *p)
|
void *pool_end_object(struct pool *p)
|
||||||
{
|
{
|
||||||
assert(p->object);
|
assert(p->begun);
|
||||||
p->object = 0;
|
_append_block(p, p->object);
|
||||||
|
|
||||||
|
p->begun = 0;
|
||||||
|
p->object = NULL;
|
||||||
return &p->tail->data;
|
return &p->tail->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pool_abandon_object(struct pool *p)
|
void pool_abandon_object(struct pool *p)
|
||||||
{
|
{
|
||||||
assert(p->object);
|
assert(p->begun);
|
||||||
pool_free(p, &p->tail->data);
|
dbg_free(p->object);
|
||||||
p->object = 0;
|
p->begun = 0;
|
||||||
|
p->object = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pool_strdup(struct pool *p, const char *str)
|
char *pool_strdup(struct pool *p, const char *str)
|
||||||
|
Loading…
Reference in New Issue
Block a user