Skip to content

Commit e4149de

Browse files
committed
wip: make tid atomic
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
1 parent 28ebae7 commit e4149de

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

test/libsinsp_e2e/thread_state.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class thread_state_test : public ::testing::Test {
3636
// Each entry in the vector has a parent of the previous
3737
// entry. The first entry has a parent of 1.
3838
for(int64_t pid = 100, i = 0; i < m_max; pid++, i++) {
39-
int64_t ppid = (i == 0 ? 1 : m_threads[i - 1]->m_tid);
39+
int64_t ppid = (i == 0 ? 1 : m_threads[i - 1]->m_tid.load());
4040
std::unique_ptr<sinsp_threadinfo> thr = threadinfo_factory.create();
4141
thr->init();
4242
thr->m_tid = pid;
@@ -54,7 +54,7 @@ class thread_state_test : public ::testing::Test {
5454
void reset() {
5555
// Reset the state
5656
for(uint32_t i = 0; i < m_max; i++) {
57-
int64_t ppid = (i == 0 ? 1 : m_threads[i - 1]->m_tid);
57+
int64_t ppid = (i == 0 ? 1 : m_threads[i - 1]->m_tid.load());
5858
sinsp_threadinfo* tinfo = m_threads[i];
5959
tinfo->m_lastevent_fd = 0;
6060
tinfo->set_parent_loop_detected(false);

userspace/libsinsp/sinsp_debug/sinsp_debug.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void display_thread_lineage(sinsp_thread_manager& thread_manager, sinsp_threadin
5555
return true;
5656
};
5757

58-
printf("📜 Task Lineage for tid: %" PRId64 "\n", tinfo->m_tid);
58+
printf("📜 Task Lineage for tid: %" PRId64 "\n", tinfo->m_tid.load());
5959
printf("⬇️ %s\n", thread_info_to_string(tinfo).c_str());
6060

6161
/* If the thread is invalid it has no parent */
@@ -147,7 +147,7 @@ int main(int argc, char** argv) {
147147
auto child_shr = child.lock().get();
148148
printf("- move child, tid: %" PRId64 ", ptid: %" PRId64
149149
" (dead) to a new reaper.\n",
150-
child_shr->m_tid,
150+
child_shr->m_tid.load(),
151151
child_shr->m_ptid);
152152
}
153153
}

userspace/libsinsp/thread_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ const std::shared_ptr<sinsp_threadinfo>& sinsp_thread_manager::add_thread(
249249
libsinsp_logger()->format(
250250
sinsp_logger::SEV_INFO,
251251
"Thread table full, dropping tid %lu (pid %lu, comm \"%s\")",
252-
threadinfo->m_tid,
252+
threadinfo->m_tid.load(),
253253
threadinfo->m_pid,
254254
threadinfo->m_comm.c_str());
255255
}

userspace/libsinsp/threadinfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ libsinsp::state::static_field_infos sinsp_threadinfo::get_static_fields() {
5151

5252
libsinsp::state::static_field_infos ret;
5353
// todo(jasondellaluce): support missing fields that are vectors, maps, or sub-tables
54-
DEFINE_STATIC_FIELD(ret, self, m_tid, "tid");
54+
DEFINE_STATIC_TYPED_FIELD(ret, self, m_tid, "tid", SS_PLUGIN_ST_INT64);
5555
DEFINE_STATIC_FIELD(ret, self, m_pid, "pid");
5656
DEFINE_STATIC_FIELD(ret, self, m_ptid, "ptid");
5757
DEFINE_STATIC_FIELD(ret, self, m_reaper_tid, "reaper_tid");

userspace/libsinsp/threadinfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ class SINSP_PUBLIC sinsp_threadinfo : public libsinsp::state::extensible_struct
351351
//
352352
// Core state
353353
//
354-
int64_t m_tid; ///< The id of this thread
354+
std::atomic<int64_t> m_tid; ///< The id of this thread
355355
int64_t m_pid; ///< The id of the process containing this thread. In single thread threads,
356356
///< this is equal to tid.
357357
int64_t m_ptid; ///< The id of the process that started this thread.

0 commit comments

Comments
 (0)