Update lib with named bool parameters and minor fixes

This commit is contained in:
Doyle Thai 2018-02-20 00:21:00 +11:00
parent 7f2950b3dd
commit 540deb4774
3 changed files with 434 additions and 159 deletions

524
dqn.h

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,11 @@
<DisplayString>{{numEntries={numEntries} numFreeEntries={numFreeEntries} usedEntriesIndex={usedEntriesIndex}}}</DisplayString> <DisplayString>{{numEntries={numEntries} numFreeEntries={numFreeEntries} usedEntriesIndex={usedEntriesIndex}}}</DisplayString>
</Type> </Type>
<Type Name="DqnSlice&lt;*&gt;">
<DisplayString>{len={len} data={data,[len]}}</DisplayString>
<StringView>data,s</StringView>
</Type>
<Type Name="DqnString"> <Type Name="DqnString">
<DisplayString>{{len={len}/{max} {str,s}}}</DisplayString> <DisplayString>{{len={len}/{max} {str,s}}}</DisplayString>
<StringView>str,s</StringView> <StringView>str,s</StringView>

View File

@ -1630,7 +1630,7 @@ void DqnArray_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard); DqnMemStack stack = {}; stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard);
DqnMemAPI memAPI = DqnMemAPI::StackAllocator(&stack); DqnMemAPI memAPI = DqnMemAPI::StackAllocator(&stack);
if (1) if (1)
@ -1782,7 +1782,7 @@ void DqnFile_Test()
} }
DqnMemStack memStack = {}; DqnMemStack memStack = {};
DQN_ASSERT(memStack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard)); DQN_ASSERT(memStack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard));
// Read data back in // Read data back in
for (u32 i = 0; i < DQN_ARRAY_COUNT(fileNames); i++) for (u32 i = 0; i < DQN_ARRAY_COUNT(fileNames); i++)
{ {
@ -1845,9 +1845,9 @@ void DqnFile_Test()
{ {
i32 numFiles; i32 numFiles;
#if defined(DQN_UNIX_IMPLEMENTATION) #if defined(DQN_UNIX_IMPLEMENTATION)
char **filelist = DqnFile::ListDir(".", numFiles); char **filelist = DqnFile::ListDir(".", &numFiles);
#elif defined(DQN_WIN32_IMPLEMENTATION) #elif defined(DQN_WIN32_IMPLEMENTATION)
char **filelist = DqnFile::ListDir("*", numFiles); char **filelist = DqnFile::ListDir("*", &numFiles);
#endif #endif
Log("Test directory listing"); Log("Test directory listing");
@ -1895,7 +1895,7 @@ FILE_SCOPE void DqnJobQueue_Test()
globalDebugCounter = 0; globalDebugCounter = 0;
DqnMemStack memStack = {}; DqnMemStack memStack = {};
DQN_ASSERT(memStack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard)); DQN_ASSERT(memStack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard));
u32 numThreads, numCores; u32 numThreads, numCores;
DqnPlatform_GetNumThreadsAndCores(&numCores, &numThreads); DqnPlatform_GetNumThreadsAndCores(&numCores, &numThreads);
@ -1935,7 +1935,7 @@ void DqnQuickSort_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; DqnMemStack stack = {};
DQN_ASSERT(stack.Init(DQN_KILOBYTE(1), false, DqnMemStack::Flag::BoundsGuard)); DQN_ASSERT(stack.Init(DQN_KILOBYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard));
// Create array of ints // Create array of ints
u32 numInts = 1000000; u32 numInts = 1000000;
@ -2353,7 +2353,7 @@ FILE_SCOPE void DqnMemStack_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; DqnMemStack stack = {};
DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard)); DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard));
i32 const ALIGN64 = 64; i32 const ALIGN64 = 64;
i32 const ALIGN16 = 16; i32 const ALIGN16 = 16;
@ -2391,7 +2391,7 @@ FILE_SCOPE void DqnMemStack_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; DqnMemStack stack = {};
DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::NonExpandable)); DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::NonExpandable));
auto *result1 = stack.Push(DQN_MEGABYTE(2)); auto *result1 = stack.Push(DQN_MEGABYTE(2));
DQN_ASSERT(result1 == nullptr); DQN_ASSERT(result1 == nullptr);
DQN_ASSERT(stack.block->prevBlock == nullptr); DQN_ASSERT(stack.block->prevBlock == nullptr);
@ -2404,7 +2404,7 @@ FILE_SCOPE void DqnMemStack_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; DqnMemStack stack = {};
DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), true)); DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True));
DQN_ASSERT(stack.metadata.GetBoundsGuardSize() == 0); DQN_ASSERT(stack.metadata.GetBoundsGuardSize() == 0);
auto *oldBlock = stack.block; auto *oldBlock = stack.block;
@ -2430,7 +2430,7 @@ FILE_SCOPE void DqnMemStack_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; DqnMemStack stack = {};
DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard)); DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard));
DqnMemStack::Block *blockToReturnTo = stack.block; DqnMemStack::Block *blockToReturnTo = stack.block;
auto headBefore = blockToReturnTo->head; auto headBefore = blockToReturnTo->head;
@ -2464,7 +2464,7 @@ FILE_SCOPE void DqnMemStack_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; DqnMemStack stack = {};
DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard)); DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard));
DqnMemStack::Block *blockToReturnTo = stack.block; DqnMemStack::Block *blockToReturnTo = stack.block;
auto headBefore = blockToReturnTo->head; auto headBefore = blockToReturnTo->head;
@ -2499,7 +2499,7 @@ FILE_SCOPE void DqnMemStack_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; DqnMemStack stack = {};
DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard)); DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard));
auto *pop1 = stack.Push(222); auto *pop1 = stack.Push(222);
auto *pop2 = stack.PushOnTail(333); auto *pop2 = stack.PushOnTail(333);
@ -2550,7 +2550,7 @@ FILE_SCOPE void DqnMemStack_Test()
{ {
u8 memBuf[sizeof(DqnMemStack::Block) - 1] = {}; u8 memBuf[sizeof(DqnMemStack::Block) - 1] = {};
DqnMemStack stack = {}; DqnMemStack stack = {};
auto result = stack.Init(&(memBuf[0]), DQN_ARRAY_COUNT(memBuf), false); auto result = stack.Init(&(memBuf[0]), DQN_ARRAY_COUNT(memBuf), Dqn::ZeroClear::False);
DQN_ASSERT(result == false); DQN_ASSERT(result == false);
DQN_ASSERT(stack.block == nullptr); DQN_ASSERT(stack.block == nullptr);
@ -2563,7 +2563,7 @@ FILE_SCOPE void DqnMemStack_Test()
i32 const bufSize = sizeof(DqnMemStack::Block) * 5; i32 const bufSize = sizeof(DqnMemStack::Block) * 5;
u8 memBuf[bufSize] = {}; u8 memBuf[bufSize] = {};
DqnMemStack stack = {}; DqnMemStack stack = {};
auto result = stack.Init(&(memBuf[0]), bufSize, false); auto result = stack.Init(&(memBuf[0]), bufSize, Dqn::ZeroClear::False);
DQN_ASSERT(result == true); DQN_ASSERT(result == true);
DQN_ASSERT(stack.block); DQN_ASSERT(stack.block);
@ -2595,7 +2595,7 @@ FILE_SCOPE void DqnMemStack_Test()
usize size = 32; usize size = 32;
usize additionalSize = DqnMemStack::MINIMUM_BLOCK_SIZE; usize additionalSize = DqnMemStack::MINIMUM_BLOCK_SIZE;
DqnMemAPI heap = DqnMemAPI::HeapAllocator(); DqnMemAPI heap = DqnMemAPI::HeapAllocator();
DQN_ASSERT(stack.Init(size, true, 0, &heap)); DQN_ASSERT(stack.Init(size, Dqn::ZeroClear::True, 0, &heap));
auto *block1 = stack.block; auto *block1 = stack.block;
size += additionalSize; size += additionalSize;
@ -2645,7 +2645,7 @@ FILE_SCOPE void DqnMemStack_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; DqnMemStack stack = {};
DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard)); DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard));
auto *result = stack.Push(64); auto *result = stack.Push(64);
// TODO(doyle): check head and tail are adjacent to the bounds of the allocation // TODO(doyle): check head and tail are adjacent to the bounds of the allocation
@ -2664,7 +2664,7 @@ FILE_SCOPE void DqnMemStack_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; DqnMemStack stack = {};
DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard)); DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard));
auto *result1 = stack.Push(100); auto *result1 = stack.Push(100);
auto *result2 = stack.PushOnTail(100); auto *result2 = stack.PushOnTail(100);
@ -2692,7 +2692,7 @@ FILE_SCOPE void DqnMemStack_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; DqnMemStack stack = {};
DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard)); DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard));
auto *result1 = stack.Push(100); auto *result1 = stack.Push(100);
DQN_ASSERT(stack.block->prevBlock == nullptr); DQN_ASSERT(stack.block->prevBlock == nullptr);
@ -2723,7 +2723,7 @@ FILE_SCOPE void DqnMemStack_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; DqnMemStack stack = {};
DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::NonExpandable)); DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::NonExpandable));
auto *result1 = stack.Push(100); auto *result1 = stack.Push(100);
DQN_ASSERT(stack.block->prevBlock == nullptr); DQN_ASSERT(stack.block->prevBlock == nullptr);
@ -2761,7 +2761,7 @@ FILE_SCOPE void DqnMemStack_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; DqnMemStack stack = {};
DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard)); DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard));
auto *api = &stack.myHeadAPI; auto *api = &stack.myHeadAPI;
auto *blockBefore = stack.block; auto *blockBefore = stack.block;
@ -2792,7 +2792,7 @@ FILE_SCOPE void DqnMemStack_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; DqnMemStack stack = {};
DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard)); DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard));
auto *api = &stack.myHeadAPI; auto *api = &stack.myHeadAPI;
auto *blockBefore = stack.block; auto *blockBefore = stack.block;
@ -2811,7 +2811,7 @@ FILE_SCOPE void DqnMemStack_Test()
DQN_ASSERT(blockBefore == stack.block); DQN_ASSERT(blockBefore == stack.block);
DQN_ASSERT(tailBefore > stack.block->tail); DQN_ASSERT(tailBefore > stack.block->tail);
stack.PopOnTail(buf, bufSize); stack.PopOnTail(buf);
DQN_ASSERT(blockBefore == stack.block); DQN_ASSERT(blockBefore == stack.block);
DQN_ASSERT(tailBefore == stack.block->tail); DQN_ASSERT(tailBefore == stack.block->tail);
@ -2828,7 +2828,7 @@ FILE_SCOPE void DqnMemStack_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; DqnMemStack stack = {};
DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard)); DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard));
auto *api = &stack.myHeadAPI; auto *api = &stack.myHeadAPI;
auto *blockBefore = stack.block; auto *blockBefore = stack.block;
@ -2846,7 +2846,7 @@ FILE_SCOPE void DqnMemStack_Test()
DqnMem_Set(buf, '@', bufSize); DqnMem_Set(buf, '@', bufSize);
DQN_ASSERT(blockBefore == stack.block->prevBlock); DQN_ASSERT(blockBefore == stack.block->prevBlock);
stack.Pop(buf, bufSize); stack.Pop(buf);
DQN_ASSERT(blockBefore == stack.block); DQN_ASSERT(blockBefore == stack.block);
DQN_ASSERT(headBefore == stack.block->head); DQN_ASSERT(headBefore == stack.block->head);
@ -2858,7 +2858,7 @@ FILE_SCOPE void DqnMemStack_Test()
if (1) if (1)
{ {
DqnMemStack stack = {}; DqnMemStack stack = {};
DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard)); DQN_ASSERT(stack.Init(DQN_MEGABYTE(1), Dqn::ZeroClear::True, DqnMemStack::Flag::BoundsGuard));
auto *api = &stack.myHeadAPI; auto *api = &stack.myHeadAPI;
auto *blockBefore = stack.block; auto *blockBefore = stack.block;