#include <limits.h>
#include "mutex.h"
-#include "lib/ffz.h"
+#include "arch/arch.h"
#define MP_SAFE /* define to make thread safe */
#define SMALLOC_REDZONE /* define to detect memory corruption */
#define SMALLOC_BPL (SMALLOC_BPB * SMALLOC_BPI)
#define INITIAL_SIZE 1024*1024 /* new pool size */
-#define MAX_POOLS 4 /* maximum number of pools to setup */
+#define MAX_POOLS 128 /* maximum number of pools to setup */
#define SMALLOC_PRE_RED 0xdeadbeefU
#define SMALLOC_POST_RED 0x5aa55aa5U
{
assert(word != -1U);
word >>= (start + 1);
- return __ffs(~word) + start + 1;
+ return ffz(word) + start + 1;
}
static int add_pool(struct pool *pool, unsigned int alloc_size)
pool->fd = fd;
- global_write_lock();
nr_pools++;
- global_write_unlock();
return 0;
out_unlink:
fprintf(stderr, "smalloc: failed adding pool\n");
{
unsigned int i;
- global_read_lock();
+ global_write_lock();
i = last_pool;
do {
if (ptr) {
last_pool = i;
- global_read_unlock();
+ global_write_unlock();
return ptr;
}
}
break;
else {
i = nr_pools;
- global_read_unlock();
if (add_pool(&mp[nr_pools], size))
goto out;
- global_read_lock();
}
} while (1);
- global_read_unlock();
out:
+ global_write_unlock();
return NULL;
}