Tue Feb 3 10:29:44 CST 2009 Pekka Pessi <first.last@nokia.com>

* su_alloc: added su_home_parent()



git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12298 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Brian West 2009-02-26 18:23:05 +00:00
parent 00ef45e96b
commit 38abb2ced7
4 changed files with 65 additions and 3 deletions

View File

@ -1 +1 @@
Wed Feb 25 13:40:08 CST 2009
Thu Feb 26 12:22:23 CST 2009

View File

@ -101,6 +101,8 @@ SU_DLL int su_home_threadsafe(su_home_t *home);
SU_DLL int su_home_has_parent(su_home_t const *home);
SU_DLL su_home_t *su_home_parent(su_home_t const *home);
SU_DLL void su_home_check(su_home_t const *home);
SU_DLL int su_home_check_alloc(su_home_t const *home, void const *data);

View File

@ -746,8 +746,21 @@ void *su_home_clone(su_home_t *parent, isize_t size)
/** Return true if home is a clone. */
int su_home_has_parent(su_home_t const *home)
{
return home && !home->suh_lock &&
home->suh_blocks && home->suh_blocks->sub_parent;
return su_home_parent(home) != NULL;
}
/** Return home's parent home. */
su_home_t *su_home_parent(su_home_t const *home)
{
su_home_t *parent = NULL;
if (home && home->suh_blocks) {
su_block_t *sub = MEMLOCK(home);
parent = sub->sub_parent;
UNLOCK(home);
}
return parent;
}
/** Allocate a memory block.
@ -1134,6 +1147,12 @@ int su_home_move(su_home_t *dst, su_home_t *src)
for (i = 0; i < n; i++)
if (s->sub_nodes[i].sua_data) {
su_block_add(d, s->sub_nodes[i].sua_data)[0] = s->sub_nodes[i];
if (s->sub_nodes[i].sua_home) {
su_home_t *subhome = s->sub_nodes[i].sua_data;
su_block_t *subsub = MEMLOCK(subhome);
subsub->sub_parent = dst;
UNLOCK(subhome);
}
}
s->sub_used = 0;
@ -1152,8 +1171,21 @@ int su_home_move(su_home_t *dst, su_home_t *src)
s = MEMLOCK(src);
if (s && s->sub_used) {
n = s->sub_n;
for (i = 0; i < n; i++) {
if (s->sub_nodes[i].sua_data && s->sub_nodes[i].sua_home) {
su_home_t *subhome = s->sub_nodes[i].sua_data;
su_block_t *subsub = MEMLOCK(subhome);
subsub->sub_parent = dst;
UNLOCK(subhome);
}
}
s->sub_used = 0;
memset(s->sub_nodes, 0, s->sub_n * sizeof (s->sub_nodes[0]));
s->sub_used = 0;
}
UNLOCK(src);

View File

@ -192,6 +192,34 @@ static int test_alloc(void)
TEST(h1->suh_size, 13);
}
/* Test su_home_parent() */
TEST_1(h0 = su_home_new(sizeof *h0));
TEST_1(h1 = su_home_clone(h0->home, sizeof *h1));
TEST_1(h2 = su_home_clone(h1->home, sizeof *h2));
TEST_1(h3 = su_home_clone(h2->home, sizeof *h3));
TEST_P(su_home_parent(h0->home), NULL);
TEST_P(su_home_parent(h1->home), h0);
TEST_P(su_home_parent(h2->home), h1);
TEST_P(su_home_parent(h3->home), h2);
TEST(su_home_move(h0->home, h1->home), 0);
TEST_P(su_home_parent(h2->home), h0);
TEST_P(su_home_parent(h3->home), h2);
TEST(su_home_move(h0->home, h2->home), 0);
TEST_P(su_home_parent(h3->home), h0);
su_home_move(NULL, h0->home);
TEST_P(su_home_parent(h0->home), NULL);
TEST_P(su_home_parent(h1->home), NULL);
TEST_P(su_home_parent(h2->home), NULL);
TEST_P(su_home_parent(h3->home), NULL);
su_home_unref(h0->home);
su_home_unref(h1->home);
su_home_unref(h2->home);
su_home_unref(h3->home);
END();
}