1
0
mirror of https://github.com/Yours3lf/rpi-vk-driver.git synced 2025-01-30 22:52:14 +01:00

cleaned up some warnings

This commit is contained in:
Unknown 2018-08-25 11:07:21 +01:00
parent 756eccd5a8
commit 212889fda6
2 changed files with 21 additions and 21 deletions

View File

@ -26,7 +26,7 @@ ConsecutivePoolAllocator createConsecutivePoolAllocator(char* b, unsigned bs, un
ConsecutivePoolAllocator pa = ConsecutivePoolAllocator pa =
{ {
.buf = b, .buf = b,
.nextFreeBlock = b, .nextFreeBlock = (uint32_t*)b,
.blockSize = bs, .blockSize = bs,
.size = s .size = s
}; };
@ -36,7 +36,7 @@ ConsecutivePoolAllocator createConsecutivePoolAllocator(char* b, unsigned bs, un
unsigned last = s/bs - 1; unsigned last = s/bs - 1;
for(unsigned c = 0; c < last; ++c) for(unsigned c = 0; c < last; ++c)
{ {
*ptr = ptr + bs/4; *ptr = (uint32_t)ptr + bs;
ptr += bs/4; ptr += bs/4;
} }
@ -65,11 +65,11 @@ void* consecutivePoolAllocate(ConsecutivePoolAllocator* pa, uint32_t numBlocks)
} }
void* ret = 0; void* ret = 0;
for(uint32_t* candidate = pa->nextFreeBlock; candidate; candidate = *candidate) for(uint32_t* candidate = pa->nextFreeBlock; candidate; candidate = (uint32_t*)*candidate)
{ {
uint32_t found = 1; uint32_t found = 1;
uint32_t* prevBlock = candidate; uint32_t* prevBlock = candidate;
uint32_t* blockAfterCandidate = *candidate; uint32_t* blockAfterCandidate = (uint32_t*)*candidate;
//check if there are enough consecutive free blocks //check if there are enough consecutive free blocks
for(uint32_t c = 0; c < numBlocks - 1; ++c) for(uint32_t c = 0; c < numBlocks - 1; ++c)
{ {
@ -80,7 +80,7 @@ void* consecutivePoolAllocate(ConsecutivePoolAllocator* pa, uint32_t numBlocks)
break; break;
} }
prevBlock = blockAfterCandidate; prevBlock = blockAfterCandidate;
blockAfterCandidate = *blockAfterCandidate; blockAfterCandidate = (uint32_t*)*blockAfterCandidate;
} }
//numblocks consecutive blocks found //numblocks consecutive blocks found
@ -95,11 +95,11 @@ void* consecutivePoolAllocate(ConsecutivePoolAllocator* pa, uint32_t numBlocks)
else else
{ {
//somewhere the linked list would point to candidate, we need to correct this //somewhere the linked list would point to candidate, we need to correct this
for(uint32_t* nextFreeBlockCandidate = pa->nextFreeBlock; nextFreeBlockCandidate; nextFreeBlockCandidate = *nextFreeBlockCandidate) for(uint32_t* nextFreeBlockCandidate = pa->nextFreeBlock; nextFreeBlockCandidate; nextFreeBlockCandidate = (uint32_t*)*nextFreeBlockCandidate)
{ {
if(*nextFreeBlockCandidate == candidate) if((uint32_t*)*nextFreeBlockCandidate == candidate)
{ {
*nextFreeBlockCandidate = blockAfterCandidate; *nextFreeBlockCandidate = (uint32_t)blockAfterCandidate;
break; break;
} }
} }
@ -117,34 +117,34 @@ void consecutivePoolFree(ConsecutivePoolAllocator* pa, void* p, uint32_t numBloc
assert(pa->buf); assert(pa->buf);
assert(p); assert(p);
if(pa->nextFreeBlock > p) if((void*)pa->nextFreeBlock > p)
{ {
for(uint32_t c = 0; c < numBlocks - 1; ++c) for(uint32_t c = 0; c < numBlocks - 1; ++c)
{ {
//set each allocated block to form a linked list //set each allocated block to form a linked list
*(uint32_t*)((char*)p + c * pa->blockSize) = (char*)p + (c + 1) * pa->blockSize; *(uint32_t*)((char*)p + c * pa->blockSize) = (uint32_t)((char*)p + (c + 1) * pa->blockSize);
} }
//set last block to point to the next free //set last block to point to the next free
*(uint32_t*)((char*)p + (numBlocks - 1) * pa->blockSize) = pa->nextFreeBlock; *(uint32_t*)((char*)p + (numBlocks - 1) * pa->blockSize) = (uint32_t)pa->nextFreeBlock;
//set next free to the newly freed block //set next free to the newly freed block
pa->nextFreeBlock = p; pa->nextFreeBlock = p;
return; return;
} }
//somewhere the linked list may point after the free block (or null), we need to correct this //somewhere the linked list may point after the free block (or null), we need to correct this
for(uint32_t* nextFreeBlockCandidate = pa->nextFreeBlock; nextFreeBlockCandidate; nextFreeBlockCandidate = *nextFreeBlockCandidate) for(uint32_t* nextFreeBlockCandidate = pa->nextFreeBlock; nextFreeBlockCandidate; nextFreeBlockCandidate = (uint32_t*)*nextFreeBlockCandidate)
{ {
if(*nextFreeBlockCandidate > p || !*nextFreeBlockCandidate) if((void*)*nextFreeBlockCandidate > p || !*nextFreeBlockCandidate)
{ {
for(uint32_t c = 0; c < numBlocks - 1; ++c) for(uint32_t c = 0; c < numBlocks - 1; ++c)
{ {
//set each allocated block to form a linked list //set each allocated block to form a linked list
*(uint32_t*)((char*)p + c * pa->blockSize) = (char*)p + (c + 1) * pa->blockSize; *(uint32_t*)((char*)p + c * pa->blockSize) = (uint32_t)((char*)p + (c + 1) * pa->blockSize);
} }
//set last block to point to the next free //set last block to point to the next free
*(uint32_t*)((char*)p + (numBlocks - 1) * pa->blockSize) = *nextFreeBlockCandidate; *(uint32_t*)((char*)p + (numBlocks - 1) * pa->blockSize) = *nextFreeBlockCandidate;
*nextFreeBlockCandidate = p; *nextFreeBlockCandidate = (uint32_t)p;
break; break;
} }
} }
@ -154,10 +154,10 @@ void consecutivePoolFree(ConsecutivePoolAllocator* pa, void* p, uint32_t numBloc
//else it frees current block and allocates a new one //else it frees current block and allocates a new one
void* consecutivePoolReAllocate(ConsecutivePoolAllocator* pa, void* currentMem, uint32_t currNumBlocks) void* consecutivePoolReAllocate(ConsecutivePoolAllocator* pa, void* currentMem, uint32_t currNumBlocks)
{ {
if(pa->nextFreeBlock == (char*)currentMem + currNumBlocks * pa->blockSize) if(pa->nextFreeBlock == (uint32_t*)((char*)currentMem + currNumBlocks * pa->blockSize))
{ {
//we have one more block after current one, so just expand current //we have one more block after current one, so just expand current
pa->nextFreeBlock = *pa->nextFreeBlock; pa->nextFreeBlock = (uint32_t*)*pa->nextFreeBlock;
return currentMem; return currentMem;
} }
else else

View File

@ -26,7 +26,7 @@ PoolAllocator createPoolAllocator(char* b, unsigned bs, unsigned s)
PoolAllocator pa = PoolAllocator pa =
{ {
.buf = b, .buf = b,
.nextFreeBlock = b, .nextFreeBlock = (uint32_t*)b,
.blockSize = bs, .blockSize = bs,
.size = s .size = s
}; };
@ -35,7 +35,7 @@ PoolAllocator createPoolAllocator(char* b, unsigned bs, unsigned s)
uint32_t* ptr = pa.nextFreeBlock; uint32_t* ptr = pa.nextFreeBlock;
for(unsigned c = 0; c < s/bs - 1; ++c) for(unsigned c = 0; c < s/bs - 1; ++c)
{ {
*ptr = ptr + bs; *ptr = (uint32_t)ptr + bs;
ptr += bs; ptr += bs;
} }
@ -66,7 +66,7 @@ void* poolAllocate(PoolAllocator* pa)
void* ret = pa->nextFreeBlock; void* ret = pa->nextFreeBlock;
//set next free block to the one the current next points to //set next free block to the one the current next points to
pa->nextFreeBlock = *pa->nextFreeBlock; pa->nextFreeBlock = (uint32_t*)*pa->nextFreeBlock;
return ret; return ret;
} }
@ -77,7 +77,7 @@ void poolFree(PoolAllocator* pa, void* p)
assert(p); assert(p);
//set block to be freed to point to the current next free block //set block to be freed to point to the current next free block
*(uint32_t*)p = pa->nextFreeBlock; *(uint32_t*)p = (uint32_t)pa->nextFreeBlock;
//set next free block to the freshly freed block //set next free block to the freshly freed block
pa->nextFreeBlock = p; pa->nextFreeBlock = p;