aboutsummaryrefslogtreecommitdiffstats
path: root/lib/pool_alloc.c
diff options
context:
space:
mode:
authorWayne Davison <wayned@samba.org>2008-07-19 08:49:53 -0700
committerWayne Davison <wayned@samba.org>2008-07-19 09:20:56 -0700
commitfb01d1fb07f6efd3752ff895fe8a77e26a2b2055 (patch)
tree3fe8d6d44fa2754f865592b8f160214ef033c809 /lib/pool_alloc.c
parent51ce67d59968560f0e975dc97bb0a22a7edb0610 (diff)
downloadandroid_external_rsync-fb01d1fb07f6efd3752ff895fe8a77e26a2b2055.tar.gz
android_external_rsync-fb01d1fb07f6efd3752ff895fe8a77e26a2b2055.tar.bz2
android_external_rsync-fb01d1fb07f6efd3752ff895fe8a77e26a2b2055.zip
Changed the POOL_QALIGN flag to POOL_NO_QALIGN, reversing the setting
(making pools aligned by default). Added the missing code to make the documented behavior of pool_free() with a NULL addr work. Updated the pool_alloc.3 manpage.
Diffstat (limited to 'lib/pool_alloc.c')
-rw-r--r--lib/pool_alloc.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/pool_alloc.c b/lib/pool_alloc.c
index c48e4c97..6997ecfa 100644
--- a/lib/pool_alloc.c
+++ b/lib/pool_alloc.c
@@ -2,7 +2,7 @@
#define POOL_DEF_EXTENT (32 * 1024)
-#define POOL_QALIGN_P2 (1<<16)
+#define POOL_QALIGN_P2 (1<<16) /* power-of-2 qalign */
struct alloc_pool
{
@@ -72,8 +72,8 @@ pool_create(size_t size, size_t quantum, void (*bomb)(const char *), int flags)
}
if (quantum <= 1)
- flags &= ~(POOL_QALIGN | POOL_QALIGN_P2);
- else if (flags & POOL_QALIGN) {
+ flags = (flags | POOL_NO_QALIGN) & ~POOL_QALIGN_P2;
+ else if (!(flags & POOL_NO_QALIGN)) {
if (size % quantum)
size += quantum - size % quantum;
/* If quantum is a power of 2, we'll avoid using modulus. */
@@ -123,7 +123,7 @@ pool_alloc(alloc_pool_t p, size_t len, const char *bomb_msg)
else if (pool->flags & POOL_QALIGN_P2) {
if (len & (pool->quantum - 1))
len += pool->quantum - (len & (pool->quantum - 1));
- } else if (pool->flags & POOL_QALIGN) {
+ } else if (!(pool->flags & POOL_NO_QALIGN)) {
if (len % pool->quantum)
len += pool->quantum - len % pool->quantum;
}
@@ -185,12 +185,21 @@ pool_free(alloc_pool_t p, size_t len, void *addr)
if (!pool)
return;
+ if (!addr) {
+ /* A NULL addr starts a fresh extent for new allocations. */
+ if ((cur = pool->extents) != NULL && cur->free != pool->size) {
+ cur->bound += cur->free;
+ cur->free = 0;
+ }
+ return;
+ }
+
if (!len)
len = pool->quantum;
else if (pool->flags & POOL_QALIGN_P2) {
if (len & (pool->quantum - 1))
len += pool->quantum - (len & (pool->quantum - 1));
- } else if (pool->flags & POOL_QALIGN) {
+ } else if (!(pool->flags & POOL_NO_QALIGN)) {
if (len % pool->quantum)
len += pool->quantum - len % pool->quantum;
}