Skip to content

Commit

Permalink
mem_tg: declare methods called within each thread as const
Browse files Browse the repository at this point in the history
This ensures that shared object members are not modified by any thread.

Signed-off-by: Peter Colberg <peter.colberg@intel.com>
  • Loading branch information
pcolberg committed Aug 19, 2024
1 parent a132211 commit a70f5c0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions samples/mem_tg/tg_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ class tg_test : public test_command
}

// Convert number of transactions to bandwidth (GB/s)
double bw_calc(uint64_t xfer_bytes, uint64_t num_ticks)
double bw_calc(uint64_t xfer_bytes, uint64_t num_ticks) const
{
return (double)(xfer_bytes) / ((1000.0 / (double)tg_exe_->mem_speed_ * (double)num_ticks));
}

void tg_perf (mem_tg *tg_exe_) {
void tg_perf (mem_tg *tg_exe_) const
{
// Lock mutex before printing so print statements don't collide between threads.
std::unique_lock<std::mutex> print_lock(tg_print_mutex);
std::cout << "Channel " << std::stoi(tg_exe_->mem_ch_[0]) << ":" << std::endl;
Expand Down Expand Up @@ -121,7 +121,7 @@ class tg_test : public test_command
print_lock.unlock();
}

bool tg_wait_test_completion (mem_tg *tg_exe_)
bool tg_wait_test_completion (mem_tg *tg_exe_) const
{
/* Wait for test completion */
uint32_t timeout = MEM_TG_TEST_TIMEOUT * tg_exe_->loop_ * tg_exe_->bcnt_;
Expand Down Expand Up @@ -152,7 +152,7 @@ class tg_test : public test_command
return true;
}

int config_input_options(mem_tg *tg_exe_)
int config_input_options(mem_tg *tg_exe_) const
{
if (!tg_exe_)
return -1;
Expand All @@ -178,7 +178,7 @@ class tg_test : public test_command
}

// The test state has been configured. Run one test instance.
int run_mem_test(mem_tg *tg_exe_)
int run_mem_test(mem_tg *tg_exe_) const
{
int status = 0;

Expand Down

0 comments on commit a70f5c0

Please sign in to comment.