changeset 3233:6396b4c0a721 HEAD

Added p_get_max_easy_alloc_size().
author Timo Sirainen <tss@iki.fi>
date Sun, 27 Mar 2005 16:29:30 +0300
parents 8508869ab276
children 06f9da4ff7a5
files src/lib/mempool-alloconly.c src/lib/mempool-datastack.c src/lib/mempool-system.c src/lib/mempool-unsafe-datastack.c src/lib/mempool.h
diffstat 5 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/mempool-alloconly.c	Sun Mar 27 16:29:04 2005 +0300
+++ b/src/lib/mempool-alloconly.c	Sun Mar 27 16:29:30 2005 +0300
@@ -47,6 +47,7 @@
 static void *pool_alloconly_realloc(pool_t pool, void *mem,
 				    size_t old_size, size_t new_size);
 static void pool_alloconly_clear(pool_t pool);
+static size_t pool_alloconly_get_max_easy_alloc_size(pool_t pool);
 
 static void block_alloc(struct alloconly_pool *pool, size_t size);
 
@@ -62,6 +63,7 @@
 	pool_alloconly_realloc,
 
 	pool_alloconly_clear,
+	pool_alloconly_get_max_easy_alloc_size,
 
 	TRUE,
 	FALSE
@@ -271,3 +273,10 @@
 	apool->block->left = apool->block->size;
 	apool->block->last_alloc_size = 0;
 }
+
+static size_t pool_alloconly_get_max_easy_alloc_size(pool_t pool)
+{
+	struct alloconly_pool *apool = (struct alloconly_pool *) pool;
+
+	return apool->block->left;
+}
--- a/src/lib/mempool-datastack.c	Sun Mar 27 16:29:04 2005 +0300
+++ b/src/lib/mempool-datastack.c	Sun Mar 27 16:29:30 2005 +0300
@@ -13,6 +13,7 @@
 static void *pool_data_stack_realloc(pool_t pool, void *mem,
 				     size_t old_size, size_t new_size);
 static void pool_data_stack_clear(pool_t pool);
+static size_t pool_data_stack_get_max_easy_alloc_size(pool_t pool);
 
 static struct pool static_data_stack_pool = {
 	pool_data_stack_get_name,
@@ -26,6 +27,7 @@
 	pool_data_stack_realloc,
 
 	pool_data_stack_clear,
+	pool_data_stack_get_max_easy_alloc_size,
 
 	TRUE,
 	TRUE
@@ -128,3 +130,9 @@
 static void pool_data_stack_clear(pool_t pool __attr_unused__)
 {
 }
+
+static size_t
+pool_data_stack_get_max_easy_alloc_size(pool_t pool __attr_unused__)
+{
+	return t_get_bytes_available();
+}
--- a/src/lib/mempool-system.c	Sun Mar 27 16:29:04 2005 +0300
+++ b/src/lib/mempool-system.c	Sun Mar 27 16:29:30 2005 +0300
@@ -21,6 +21,7 @@
 static void *pool_system_realloc(pool_t pool, void *mem,
 				 size_t old_size, size_t new_size);
 static void pool_system_clear(pool_t pool);
+static size_t pool_system_get_max_easy_alloc_size(pool_t pool);
 
 static struct pool static_system_pool = {
 	pool_system_get_name,
@@ -34,6 +35,7 @@
 	pool_system_realloc,
 
 	pool_system_clear,
+	pool_system_get_max_easy_alloc_size,
 
 	FALSE,
 	FALSE
@@ -111,3 +113,8 @@
 {
 	i_panic("pool_system_clear() must not be called");
 }
+
+static size_t pool_system_get_max_easy_alloc_size(pool_t pool __attr_unused__)
+{
+	return 0;
+}
--- a/src/lib/mempool-unsafe-datastack.c	Sun Mar 27 16:29:04 2005 +0300
+++ b/src/lib/mempool-unsafe-datastack.c	Sun Mar 27 16:29:30 2005 +0300
@@ -13,6 +13,7 @@
 static void *pool_unsafe_data_stack_realloc(pool_t pool, void *mem,
 					    size_t old_size, size_t new_size);
 static void pool_unsafe_data_stack_clear(pool_t pool);
+static size_t pool_unsafe_data_stack_get_max_easy_alloc_size(pool_t pool);
 
 static struct pool static_unsafe_data_stack_pool = {
 	pool_unsafe_data_stack_get_name,
@@ -26,6 +27,7 @@
 	pool_unsafe_data_stack_realloc,
 
 	pool_unsafe_data_stack_clear,
+	pool_unsafe_data_stack_get_max_easy_alloc_size,
 
 	TRUE,
 	TRUE
@@ -89,3 +91,9 @@
 static void pool_unsafe_data_stack_clear(pool_t pool __attr_unused__)
 {
 }
+
+static size_t
+pool_unsafe_data_stack_get_max_easy_alloc_size(pool_t pool __attr_unused__)
+{
+	return t_get_bytes_available();
+}
--- a/src/lib/mempool.h	Sun Mar 27 16:29:04 2005 +0300
+++ b/src/lib/mempool.h	Sun Mar 27 16:29:30 2005 +0300
@@ -26,6 +26,10 @@
 	   this and crashes if it's used */
 	void (*clear)(pool_t pool);
 
+	/* Returns the maximum amount of bytes that can be allocated with
+	   minimal trouble. If there's no such concept, always returns 0. */
+	size_t (*get_max_easy_alloc_size)(pool_t pool);
+
 	unsigned int alloconly_pool:1;
 	unsigned int datastack_pool:1;
 };
@@ -65,4 +69,6 @@
 
 #define p_clear(pool) (pool)->clear(pool)
 
+#define p_get_max_easy_alloc_size(pool) (pool)->get_max_easy_alloc_size(pool)
+
 #endif