Skip to content

Commit

Permalink
fix minor test bug related to 0 scratch sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
rtjohnso committed Jan 14, 2025
1 parent f7d3ee1 commit 5fcefd7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ task_create_thread_with_hooks(platform_thread *thread,
free_thread:
platform_free(hid, thread_to_create);
free_scratch:
platform_free(ts->heap_id, ts->thread_scratch[newtid]);
if (ts->thread_scratch[newtid] != NULL) {
platform_free(ts->heap_id, ts->thread_scratch[newtid]);
}
dealloc_tid:
task_deallocate_threadid(ts, newtid);
return ret;
Expand Down
15 changes: 9 additions & 6 deletions tests/unit/task_system_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,9 @@ exec_one_thread_use_lower_apis(void *arg)

// Registration should have allocated some scratch space memory.
ASSERT_TRUE(
task_system_get_thread_scratch(thread_cfg->tasks, platform_get_tid())
!= NULL);
trunk_get_scratch_size() == 0
|| task_system_get_thread_scratch(thread_cfg->tasks, platform_get_tid())
!= NULL);

// Brain-dead cross-check, to understand what's going on with thread-IDs.
platform_thread thread_id = platform_thread_id_self();
Expand All @@ -518,8 +519,9 @@ exec_one_thread_use_lower_apis(void *arg)

// Deregistration releases scratch space memory.
ASSERT_TRUE(
task_system_get_thread_scratch(thread_cfg->tasks, this_threads_idx)
== NULL);
trunk_get_scratch_size() == 0
|| task_system_get_thread_scratch(thread_cfg->tasks, this_threads_idx)
== NULL);

// Register / de-register of thread with SplinterDB's task system is
// SplinterDB's jugglery to keep track of resources. get_tid() should
Expand Down Expand Up @@ -559,8 +561,9 @@ exec_one_thread_use_extern_apis(void *arg)

// Registration should have allocated some scratch space memory.
ASSERT_TRUE(
task_system_get_thread_scratch(thread_cfg->tasks, this_threads_idx)
!= NULL);
trunk_get_scratch_size() == 0
|| task_system_get_thread_scratch(thread_cfg->tasks, this_threads_idx)
!= NULL);

/*
* Dead Code Warning!
Expand Down

0 comments on commit 5fcefd7

Please sign in to comment.