Merge branch 'master' into gfio
[fio.git] / smalloc.c
index a925a653e5d5571e9fff8686b7378efe3a343704..d0b6f1e1f0059fb266aac3334d078f36715fbacd 100644 (file)
--- a/smalloc.c
+++ b/smalloc.c
@@ -8,6 +8,7 @@
 #include <assert.h>
 #include <string.h>
 #include <unistd.h>
+#include <inttypes.h>
 #include <sys/types.h>
 #include <limits.h>
 #include <fcntl.h>
@@ -171,8 +172,8 @@ static void clear_blocks(struct pool *pool, unsigned int pool_idx,
 static int find_next_zero(int word, int start)
 {
        assert(word != -1U);
-       word >>= (start + 1);
-       return ffz(word) + start + 1;
+       word >>= start;
+       return ffz(word) + start;
 }
 
 static int add_pool(struct pool *pool, unsigned int alloc_size)
@@ -205,7 +206,7 @@ static int add_pool(struct pool *pool, unsigned int alloc_size)
        pool->map = ptr;
        pool->bitmap = (void *) ptr + (pool->nr_blocks * SMALLOC_BPL);
 
-       pool->lock = fio_mutex_init(1);
+       pool->lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
        if (!pool->lock)
                goto out_fail;
 
@@ -253,9 +254,9 @@ void scleanup(void)
 #ifdef SMALLOC_REDZONE
 static void *postred_ptr(struct block_hdr *hdr)
 {
-       unsigned long ptr;
+       uintptr_t ptr;
 
-       ptr = (unsigned long) hdr + hdr->size - sizeof(unsigned int);
+       ptr = (uintptr_t) hdr + hdr->size - sizeof(unsigned int);
        ptr = (ptr + int_mask) & ~int_mask;
 
        return (void *) ptr;