Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions tcmalloc/internal/sampled_allocation_recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ class SampleRecorder {
// Unregisters the sample.
void Unregister(T* sample);

// The dispose callback will be called on all samples the moment they are
// being unregistered. Only affects samples that are unregistered after the
// callback has been set.
// Returns the previous callback.
using DisposeCallback = void (*)(const T&);
DisposeCallback SetDisposeCallback(DisposeCallback f);

// Unregisters any live samples starting from `all_`. Note that if there are
// any samples added in front of `all_` in other threads after this function
// reads `all_`, they won't be cleaned up. External synchronization is
Expand Down Expand Up @@ -128,16 +121,9 @@ class SampleRecorder {
std::atomic<T*> all_ = nullptr;
T graveyard_;

std::atomic<DisposeCallback> dispose_ = nullptr;
Allocator* allocator_ = nullptr;
};

template <typename T, typename Allocator>
typename SampleRecorder<T, Allocator>::DisposeCallback
SampleRecorder<T, Allocator>::SetDisposeCallback(DisposeCallback f) {
return dispose_.exchange(f, std::memory_order_relaxed);
}

template <typename T, typename Allocator>
constexpr SampleRecorder<T, Allocator>::SampleRecorder(Allocator& allocator) {
Init(allocator);
Expand Down Expand Up @@ -172,11 +158,6 @@ void SampleRecorder<T, Allocator>::PushNew(T* sample) {

template <typename T, typename Allocator>
void SampleRecorder<T, Allocator>::PushDead(T* sample) {
if (auto* dispose = dispose_.load(std::memory_order_relaxed);
ABSL_PREDICT_FALSE(dispose != nullptr)) {
dispose(*sample);
}

AllocationGuardSpinLockHolder graveyard_lock(graveyard_.lock);
AllocationGuardSpinLockHolder sample_lock(sample->lock);
sample->dead = graveyard_.dead;
Expand Down Expand Up @@ -229,12 +210,10 @@ template <typename T, typename Allocator>
void SampleRecorder<T, Allocator>::UnregisterAll() {
AllocationGuardSpinLockHolder graveyard_lock(graveyard_.lock);
T* sample = all_.load(std::memory_order_acquire);
auto* dispose = dispose_.load(std::memory_order_relaxed);
while (sample != nullptr) {
{
AllocationGuardSpinLockHolder sample_lock(sample->lock);
if (sample->dead == nullptr) {
if (dispose) dispose(*sample);
sample->dead = graveyard_.dead;
graveyard_.dead = sample;
}
Expand Down
23 changes: 0 additions & 23 deletions tcmalloc/internal/sampled_allocation_recorder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,29 +211,6 @@ TEST_F(SampleRecorderTest, MultiThreaded) {
threads.Stop();
}

TEST_F(SampleRecorderTest, Callback) {
auto* info1 = Register(1);
auto* info2 = Register(2);

static const Info* expected;

auto callback = [](const Info& info) {
// We can't use `info` outside of this callback because the object will be
// disposed as soon as we return from here.
EXPECT_EQ(&info, expected);
};

// Set the callback.
EXPECT_EQ(sample_recorder_.SetDisposeCallback(callback), nullptr);
expected = info1;
sample_recorder_.Unregister(info1);

// Unset the callback.
EXPECT_EQ(callback, sample_recorder_.SetDisposeCallback(nullptr));
expected = nullptr; // no more calls.
sample_recorder_.Unregister(info2);
}

// Similar to Sample<Info> above but requires parameter(s) at initialization.
struct InfoWithParam : public Sample<InfoWithParam> {
public:
Expand Down
Loading