X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Falloc%2Ftiny.c;h=ffd17c65734f881f1ca355ed9e1a5b705dd3ff46;hp=563c761ea90a52f1535ef461a172f0e5fae6d0a5;hb=c438ec17d7b2efe76e56e5fc5ab88bd4a02735e8;hpb=3d9899b97bff2a3ec5abe57f06c2a9355a18e6b5;ds=sidebyside diff --git a/ccan/alloc/tiny.c b/ccan/alloc/tiny.c old mode 100755 new mode 100644 index 563c761e..ffd17c65 --- a/ccan/alloc/tiny.c +++ b/ccan/alloc/tiny.c @@ -1,3 +1,4 @@ +/* Licensed under LGPLv2.1+ - see LICENSE file for details */ #include "tiny.h" #include "bitops.h" #include @@ -19,7 +20,7 @@ /* Val is usually offset by MIN_BLOCK_SIZE here. */ static unsigned encode_length(unsigned long val) { - unsigned int bits = fls(val); + unsigned int bits = afls(val); /* 5 bits in first byte. */ if (bits <= 5) return 1; @@ -137,12 +138,12 @@ void tiny_alloc_init(void *pool, unsigned long poolsize) /* Walk through and try to coalesce */ static bool try_coalesce(unsigned char *pool, unsigned long poolsize) { - unsigned long len, hdrlen, prev_off = 0, prev_len = 0, off; + unsigned long len, prev_off = 0, prev_len = 0, off; bool free, prev_free = false, coalesced = false; off = free_array_size(poolsize); do { - hdrlen = decode(&len, &free, pool + off); + decode(&len, &free, pool + off); if (free && prev_free) { prev_len += len; encode(prev_len, true, pool + prev_off); @@ -198,7 +199,7 @@ void *tiny_alloc_get(void *pool, unsigned long poolsize, unsigned long size, unsigned long align) { unsigned long arrsize = free_array_size(poolsize); - unsigned long len, off, actual, hdr, hdrlen, free_bucket; + unsigned long len, off, actual, hdr, free_bucket; long fa_off; unsigned char *arr = pool; bool free, coalesced = false; @@ -224,7 +225,7 @@ void *tiny_alloc_get(void *pool, unsigned long poolsize, if (!off) continue; - hdrlen = decode(&len, &free, arr + off); + decode(&len, &free, arr + off); if (long_enough(off, len, size, align)) { /* Remove it. */ memset(&arr[fa_off], 0, 3); @@ -236,7 +237,7 @@ void *tiny_alloc_get(void *pool, unsigned long poolsize, again: off = arrsize; - hdrlen = decode(&len, &free, arr + off); + decode(&len, &free, arr + off); while (!free || !long_enough(off, len, size, align)) { /* Refill free array as we go. */ if (free && coalesced) @@ -251,7 +252,7 @@ again: } return NULL; } - hdrlen = decode(&len, &free, arr + off); + decode(&len, &free, arr + off); } found: