Rename dirty_queue to dirty_db and make it a single std::map

This commit is contained in:
Vitaliy Filippov
2019-11-08 00:20:10 +03:00
parent 5330461029
commit 40890aeec5
8 changed files with 89 additions and 58 deletions
+5 -7
View File
@@ -3,8 +3,6 @@
#include <stdlib.h>
#include <malloc.h>
#define MAX64 ((uint64_t)-1)
allocator *allocator_create(uint64_t blocks)
{
if (blocks >= 0x80000000 || blocks <= 1)
@@ -22,8 +20,8 @@ allocator *allocator_create(uint64_t blocks)
allocator *buf = (allocator*)memalign(sizeof(uint64_t), (2 + total)*sizeof(uint64_t));
buf->size = blocks;
buf->last_one_mask = (blocks % 64) == 0
? MAX64
: ~(MAX64 << (64 - blocks % 64));
? UINT64_MAX
: ~(UINT64_MAX << (64 - blocks % 64));
for (uint64_t i = 0; i < blocks; i++)
{
buf->mask[i] = 0;
@@ -61,7 +59,7 @@ void allocator_set(allocator *alloc, uint64_t addr, bool value)
{
alloc->mask[last] = alloc->mask[last] | (1 << bit);
if (alloc->mask[last] != (!is_last || cur_addr/64 < alloc->size/64
? MAX64 : alloc->last_one_mask))
? UINT64_MAX : alloc->last_one_mask))
{
break;
}
@@ -109,13 +107,13 @@ uint64_t allocator_find_free(allocator *alloc)
if (i == 64)
{
// No space
return MAX64;
return UINT64_MAX;
}
addr = (addr * 64) | i;
if (addr >= alloc->size)
{
// No space
return MAX64;
return UINT64_MAX;
}
offset += p2;
p2 = p2 * 64;