Fix allocator bug

blocking-uring-test
Vitaliy Filippov 2019-11-27 01:12:25 +03:00
parent ff7469ee91
commit 6ac1d5db08
3 changed files with 22 additions and 2 deletions

View File

@ -11,5 +11,7 @@ test: test.cpp
g++ -g -O3 -o test -luring test.cpp
test_blockstore: $(BLOCKSTORE_OBJS) test_blockstore.cpp
g++ -g -o test_blockstore -luring test_blockstore.cpp $(BLOCKSTORE_OBJS)
test_allocator: test_allocator.cpp allocator.o
g++ -g -o test_allocator test_allocator.cpp allocator.o
libfio_blockstore.so: fio_engine.cpp $(BLOCKSTORE_OBJS)
g++ -g -Wno-pointer-arith -fPIC -shared -luring -o libfio_blockstore.so fio_engine.cpp $(BLOCKSTORE_OBJS)

View File

@ -57,7 +57,7 @@ void allocator::set(uint64_t addr, bool value)
{
if (value)
{
mask[last] = mask[last] | (1 << bit);
mask[last] = mask[last] | (1l << bit);
if (mask[last] != (!is_last || cur_addr/64 < size/64
? UINT64_MAX : last_one_mask))
{
@ -66,7 +66,7 @@ void allocator::set(uint64_t addr, bool value)
}
else
{
mask[last] = mask[last] & ~(1 << bit);
mask[last] = mask[last] & ~(1l << bit);
if (mask[last] != 0)
{
break;

18
test_allocator.cpp Normal file
View File

@ -0,0 +1,18 @@
#include <stdio.h>
#include "allocator.h"
int main(int narg, char *args[])
{
allocator a(8192);
for (int i = 0; i < 8192; i++)
{
uint64_t x = a.find_free();
if (x == UINT64_MAX)
{
printf("ran out of space %d\n", i);
return 1;
}
a.set(x, true);
}
return 0;
}