Skip to content

Commit 3891f63

Browse files
committed
fix: address lock-free bug
1 parent c862039 commit 3891f63

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

ddprof-lib/src/main/cpp/threadFilter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ class ThreadFilter {
215215
snapshot.correlation_id = 0;
216216
}
217217
snapshot.generation = blockGeneration();
218-
snapshot.active = snapshot.active_state != OSThreadState::UNKNOWN;
218+
snapshot.active = snapshot.owner != BlockRunOwner::NONE &&
219+
snapshot.active_state != OSThreadState::UNKNOWN;
219220
snapshot.has_stack_reference =
220221
sampled && (snapshot.call_trace_id != 0 || snapshot.correlation_id != 0);
221222
return snapshot;

ddprof-lib/src/test/cpp/threadFilter_ut.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,22 @@ TEST_F(ThreadFilterTest, BlockRunSnapshotCapturesFirstCallTraceId) {
701701
EXPECT_EQ(0ULL, snapshot.correlation_id);
702702
}
703703

704+
TEST_F(ThreadFilterTest, BlockRunSnapshotTreatsOwnerlessStateAsInactive) {
705+
int slot_id = filter->registerThread();
706+
ASSERT_GE(slot_id, 0);
707+
ThreadFilter::Slot *slot = filter->slotForId(slot_id);
708+
ASSERT_NE(nullptr, slot);
709+
710+
slot->active_block_state.store(OSThreadState::IO_WAIT, std::memory_order_release);
711+
slot->active_block_owner.store(static_cast<int>(BlockRunOwner::NONE),
712+
std::memory_order_release);
713+
714+
BlockRunSnapshot snapshot = filter->snapshotBlockedRun(slot_id);
715+
EXPECT_FALSE(snapshot.active);
716+
EXPECT_EQ(BlockRunOwner::NONE, snapshot.owner);
717+
EXPECT_EQ(OSThreadState::IO_WAIT, snapshot.active_state);
718+
}
719+
704720
TEST_F(ThreadFilterTest, BlockRunSnapshotCapturesFirstCorrelationId) {
705721
int slot_id = filter->registerThread();
706722
ASSERT_GE(slot_id, 0);

0 commit comments

Comments
 (0)