Skip to content

Commit 5be9901

Browse files
Use a deterministic thread numbering scheme (#7167)
Co-authored-by: Amaury Chamayou <[email protected]>
1 parent f5213b7 commit 5be9901

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

include/ccf/threading/thread_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ namespace ccf::threading
2020
static constexpr ThreadID MAIN_THREAD_ID = 0;
2121

2222
uint16_t get_current_thread_id();
23+
void set_current_thread_id(ThreadID to);
2324
void reset_thread_id_generator(ThreadID to = MAIN_THREAD_ID);
2425
}

src/enclave/thread_local.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ namespace ccf::threading
66
{
77
static std::atomic<ThreadID> next_thread_id = MAIN_THREAD_ID;
88

9-
uint16_t get_current_thread_id()
9+
uint16_t& current_thread_id()
1010
{
1111
thread_local ThreadID this_thread_id = next_thread_id.fetch_add(1);
1212
return this_thread_id;
1313
}
1414

15+
uint16_t get_current_thread_id()
16+
{
17+
return current_thread_id();
18+
}
19+
20+
void set_current_thread_id(ThreadID to)
21+
{
22+
current_thread_id() = to;
23+
}
24+
1525
void reset_thread_id_generator(ThreadID to)
1626
{
1727
next_thread_id.store(to);

src/host/run.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,8 @@ namespace ccf
975975
config.command.service_certificate_file);
976976
}
977977

978-
auto enclave_thread_start = [&]() {
978+
auto enclave_thread_start = [&](threading::ThreadID thread_id) {
979+
threading::set_current_thread_id(thread_id);
979980
try
980981
{
981982
bool ret = enclave_run();
@@ -1003,7 +1004,7 @@ namespace ccf
10031004
std::vector<std::thread> threads;
10041005
for (uint32_t i = 0; i < (config.worker_threads + 1); ++i)
10051006
{
1006-
threads.emplace_back(enclave_thread_start);
1007+
threads.emplace_back(enclave_thread_start, i);
10071008
}
10081009

10091010
LOG_INFO_FMT("Entering event loop");

0 commit comments

Comments
 (0)