Skip to content

Commit

Permalink
Remove designated initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
sirknightj committed Nov 8, 2024
1 parent ce7d0b2 commit 608001f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/utils/src/Thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ PUBLIC_API STATUS defaultCreateThreadWithParams(PTID pThreadId, PThreadParams pT
PUBLIC_API STATUS defaultCreateThread(PTID pThreadId, startRoutine start, PVOID args)
{
STATUS retStatus = STATUS_SUCCESS;
ThreadParams threadParams = {.version = 0};
ThreadParams threadParams;
threadParams.version = 0;

#if defined(KVS_DEFAULT_STACK_SIZE_BYTES)
threadParams.stackSize = (SIZE_T) KVS_DEFAULT_STACK_SIZE_BYTES;
Expand Down Expand Up @@ -223,7 +224,8 @@ PUBLIC_API STATUS defaultCreateThreadWithParams(PTID pThreadId, PThreadParams pT
PUBLIC_API STATUS defaultCreateThread(PTID pThreadId, startRoutine start, PVOID args)
{
STATUS retStatus = STATUS_SUCCESS;
ThreadParams threadParams = {.version = 0};
ThreadParams threadParams;
threadParams.version = 0;

#if defined(KVS_DEFAULT_STACK_SIZE_BYTES) && defined(CONSTRAINED_DEVICE)
DLOGW("KVS_DEFAULT_STACK_SIZE_BYTES and CONSTRAINED_DEVICE are both defined. KVS_DEFAULT_STACK_SIZE_BYTES will take priority.");
Expand Down
34 changes: 25 additions & 9 deletions tst/utils/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ TEST_F(ThreadFunctionalityTest, ThreadCreateAndReleaseSimpleCheckWithStack)
srand(GETTIME());
SIZE_T threadStack = 64 * 1024;
struct sleep_times st[TEST_THREAD_COUNT];
ThreadParams threadParams = {.version = 0, .stackSize = threadStack};
ThreadParams thread_params[TEST_THREAD_COUNT];

gThreadCount = 0;

Expand All @@ -141,7 +141,9 @@ TEST_F(ThreadFunctionalityTest, ThreadCreateAndReleaseSimpleCheckWithStack)
st[index].threadVisited = FALSE;
st[index].threadCleared = FALSE;
st[index].threadSleepTime = index * HUNDREDS_OF_NANOS_IN_A_MILLISECOND;
EXPECT_EQ(STATUS_SUCCESS, THREAD_CREATE_WITH_PARAMS(&threads[index], &threadParams, testThreadRoutine, (PVOID) &st[index]));
thread_params[index].version = 0;
thread_params[index].stackSize = threadStack;
EXPECT_EQ(STATUS_SUCCESS, THREAD_CREATE_WITH_PARAMS(&threads[index], &thread_params[index], testThreadRoutine, (PVOID) &st[index]));
}

// Await for the threads to finish
Expand All @@ -164,7 +166,9 @@ TEST_F(ThreadFunctionalityTest, ThreadCreateAndReleaseSimpleCheckWithStack)
TEST_F(ThreadFunctionalityTest, ThreadCreateUseDefaultsTest)
{
TID threadId = 0;
ThreadParams threadParams = {.version = 0, .stackSize = 0};
ThreadParams threadParams;
threadParams.version = 0;
threadParams.stackSize = 0;

// 0 passed into the size parameter means to use the defaults.
EXPECT_EQ(STATUS_SUCCESS, THREAD_CREATE_WITH_PARAMS(&threadId, &threadParams, emptyRoutine, NULL));
Expand All @@ -176,7 +180,9 @@ TEST_F(ThreadFunctionalityTest, NegativeTest)
{
TID threadId = 0;
SIZE_T threadStack = 512 * 1024; // 0.5 MiB
ThreadParams threadParams = {.version = 0, .stackSize = threadStack};
ThreadParams threadParams;
threadParams.version = 0;
threadParams.stackSize = threadStack;

// No out value case
EXPECT_NE(STATUS_SUCCESS, THREAD_CREATE_WITH_PARAMS(NULL, &threadParams, emptyRoutine, NULL));
Expand Down Expand Up @@ -246,13 +252,23 @@ PVOID fetchStackSizeThreadRoutine(PVOID arg)
// Then check that the thread has the requested size.
TEST_F(ThreadFunctionalityTest, VerifyStackSize)
{
TID halfMiBThreadId = 0, oneMiBThreadId = 0;
TID halfMiBThreadId = 0;
SIZE_T halfMiBThreadStackSize = 512 * 1024; // 0.5 MiB
TestThreadInfo halfMiBThreadInfo = {.stackSize = 0, .failure = 0};
ThreadParams halfMiBThreadParams = {.version = 0, .stackSize = halfMiBThreadStackSize};
TestThreadInfo halfMiBThreadInfo;
halfMiBThreadInfo.stackSize = 0;
halfMiBThreadInfo.failure = 0;
ThreadParams halfMiBThreadParams;
halfMibThreadParams.version = 0;
halfMibThreadParams.stackSize = halfMiBThreadStackSize;

TID oneMiBThreadId = 0;
SIZE_T oneMiBThreadStackSize = 1024 * 1024; // 1 MiB
TestThreadInfo oneMiBThreadInfo = {.stackSize = 0, .failure = 0};
ThreadParams oneMiBThreadParams = {.version = 0, .stackSize = oneMiBThreadStackSize};
TestThreadInfo oneMiBThreadInfo;
oneMiBThreadInfo.stackSize = 0;
oneMiBThreadInfo.failure = 0;
ThreadParams oneMiBThreadParams;
oneMiBThreadParams.version = 0;
oneMiBThreadParams.stackSize = oneMiBThreadStackSize;

// Check case 1: 0.5 MiB
EXPECT_EQ(STATUS_SUCCESS, THREAD_CREATE_WITH_PARAMS(&halfMiBThreadId, &halfMiBThreadParams, fetchStackSizeThreadRoutine, &halfMiBThreadInfo));
Expand Down

0 comments on commit 608001f

Please sign in to comment.