summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2013-09-06 14:20:20 -0700
committerVolker Lendecke <vl@samba.org>2013-09-08 11:34:06 +0200
commita3d9099d9a96b36df21ee0733adc5210438fe9dc (patch)
tree834f1409ef6f833f8d7303182b7892e25602b22e /lib
parentb87c8fd435d1863d6efcec03830ecd85ddfcd7fb (diff)
downloadsamba-a3d9099d9a96b36df21ee0733adc5210438fe9dc.tar.gz
samba-a3d9099d9a96b36df21ee0733adc5210438fe9dc.tar.bz2
samba-a3d9099d9a96b36df21ee0733adc5210438fe9dc.zip
talloc: Add a separate pool size
This is necessary to allow talloc pools to be objects on their own. It is an incompatible change in the sense that talloc_get_size(pool) now returns 0 instead of the pool size. When the talloc_pooled_object() call is added, this will start to make sense again. Maybe we should add a talloc_pool_size call? Or is that overkill? Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/talloc/talloc.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c
index a553050e6e..5d13567e6d 100644
--- a/lib/talloc/talloc.c
+++ b/lib/talloc/talloc.c
@@ -461,6 +461,7 @@ _PUBLIC_ const char *talloc_parent_name(const void *ptr)
struct talloc_pool_hdr {
void *end;
unsigned int object_count;
+ size_t poolsize;
};
#define TP_HDR_SIZE TC_ALIGN16(sizeof(struct talloc_pool_hdr))
@@ -478,7 +479,7 @@ static struct talloc_chunk *talloc_chunk_from_pool(struct talloc_pool_hdr *h)
static void *tc_pool_end(struct talloc_pool_hdr *pool_hdr)
{
struct talloc_chunk *tc = talloc_chunk_from_pool(pool_hdr);
- return (char *)tc + TC_HDR_SIZE + tc->size;
+ return (char *)tc + TC_HDR_SIZE + pool_hdr->poolsize;
}
static size_t tc_pool_space_left(struct talloc_pool_hdr *pool_hdr)
@@ -486,17 +487,18 @@ static size_t tc_pool_space_left(struct talloc_pool_hdr *pool_hdr)
return (char *)tc_pool_end(pool_hdr) - (char *)pool_hdr->end;
}
-static void *tc_pool_first_chunk(struct talloc_pool_hdr *pool_hdr)
-{
- return TC_PTR_FROM_CHUNK(talloc_chunk_from_pool(pool_hdr));
-}
-
/* If tc is inside a pool, this gives the next neighbour. */
static void *tc_next_chunk(struct talloc_chunk *tc)
{
return (char *)tc + TC_ALIGN16(TC_HDR_SIZE + tc->size);
}
+static void *tc_pool_first_chunk(struct talloc_pool_hdr *pool_hdr)
+{
+ struct talloc_chunk *tc = talloc_chunk_from_pool(pool_hdr);
+ return tc_next_chunk(tc);
+}
+
/* Mark the whole remaining pool as not accessable */
static void tc_invalidate_pool(struct talloc_pool_hdr *pool_hdr)
{
@@ -678,9 +680,11 @@ _PUBLIC_ void *talloc_pool(const void *context, size_t size)
return NULL;
}
tc->flags |= TALLOC_FLAG_POOL;
+ tc->size = 0;
pool_hdr->object_count = 1;
pool_hdr->end = result;
+ pool_hdr->poolsize = size;
tc_invalidate_pool(pool_hdr);
@@ -1847,13 +1851,20 @@ static size_t _talloc_total_mem_internal(const void *ptr,
* pool itself.
*/
if (!(tc->flags & TALLOC_FLAG_POOLMEM)) {
- total = tc->size + TC_HDR_SIZE;
- /*
- * If this is a pool, remember to
- * add the prefix length.
- */
if (tc->flags & TALLOC_FLAG_POOL) {
- total += TP_HDR_SIZE;
+ /*
+ * If this is a pool, the allocated
+ * size is in the pool header, and
+ * remember to add in the prefix
+ * length.
+ */
+ struct talloc_pool_hdr *pool_hdr
+ = talloc_pool_from_chunk(tc);
+ total = pool_hdr->poolsize +
+ TC_HDR_SIZE +
+ TP_HDR_SIZE;
+ } else {
+ total = tc->size + TC_HDR_SIZE;
}
}
}