Skip to content

Commit

Permalink
Modernize to [[nodiscard]]
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 695430742
Change-Id: I47f912f0f37fb9d424450c5308d8842d5170bf1c
  • Loading branch information
ckennelly authored and copybara-github committed Nov 11, 2024
1 parent 07937e8 commit a390a1d
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 29 deletions.
3 changes: 1 addition & 2 deletions tcmalloc/huge_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class VirtualAllocator {
VirtualAllocator& operator=(VirtualAllocator&&) = delete;

// Allocates bytes of virtual address space with align alignment.
ABSL_MUST_USE_RESULT virtual AddressRange operator()(size_t bytes,
size_t align) = 0;
[[nodiscard]] virtual AddressRange operator()(size_t bytes, size_t align) = 0;
};

// This tracks available ranges of hugepages and fulfills requests for
Expand Down
4 changes: 2 additions & 2 deletions tcmalloc/huge_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class MemoryModifyFunction {
public:
virtual ~MemoryModifyFunction() = default;

ABSL_MUST_USE_RESULT virtual bool operator()(Range r) = 0;
ABSL_MUST_USE_RESULT bool operator()(HugeRange r) {
[[nodiscard]] virtual bool operator()(Range r) = 0;
[[nodiscard]] bool operator()(HugeRange r) {
return (*this)(Range{r.start().first_page(), r.len().in_pages()});
}
};
Expand Down
9 changes: 4 additions & 5 deletions tcmalloc/huge_page_aware_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class HugePageAwareAllocator final : public PageAllocatorInterface {
explicit Unback(HugePageAwareAllocator& hpaa ABSL_ATTRIBUTE_LIFETIME_BOUND)
: hpaa_(hpaa) {}

ABSL_MUST_USE_RESULT bool operator()(Range r) override
[[nodiscard]] bool operator()(Range r) override
ABSL_EXCLUSIVE_LOCKS_REQUIRED(pageheap_lock) {
#ifndef NDEBUG
pageheap_lock.AssertHeld();
Expand All @@ -269,7 +269,7 @@ class HugePageAwareAllocator final : public PageAllocatorInterface {
HugePageAwareAllocator& hpaa ABSL_ATTRIBUTE_LIFETIME_BOUND)
: hpaa_(hpaa) {}

ABSL_MUST_USE_RESULT bool operator()(Range r) override
[[nodiscard]] bool operator()(Range r) override
ABSL_NO_THREAD_SAFETY_ANALYSIS {
#ifndef NDEBUG
pageheap_lock.AssertHeld();
Expand All @@ -296,8 +296,7 @@ class HugePageAwareAllocator final : public PageAllocatorInterface {
HugePageAwareAllocator& hpaa ABSL_ATTRIBUTE_LIFETIME_BOUND)
: hpaa_(hpaa) {}

ABSL_MUST_USE_RESULT AddressRange operator()(size_t bytes,
size_t align) override
[[nodiscard]] AddressRange operator()(size_t bytes, size_t align) override
ABSL_EXCLUSIVE_LOCKS_REQUIRED(pageheap_lock) {
return hpaa_.AllocAndReport(bytes, align);
}
Expand All @@ -312,7 +311,7 @@ class HugePageAwareAllocator final : public PageAllocatorInterface {
HugePageAwareAllocator& hpaa ABSL_ATTRIBUTE_LIFETIME_BOUND)
: hpaa_(hpaa) {}

ABSL_MUST_USE_RESULT void* operator()(size_t bytes) override
[[nodiscard]] void* operator()(size_t bytes) override
ABSL_EXCLUSIVE_LOCKS_REQUIRED(pageheap_lock) {
return hpaa_.forwarder_.arena().Alloc(bytes);
}
Expand Down
3 changes: 1 addition & 2 deletions tcmalloc/huge_page_filler.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ class PageTracker : public TList<PageTracker>::Elem {

bool has_dense_spans_ = false;

ABSL_MUST_USE_RESULT bool ReleasePages(Range r,
MemoryModifyFunction& unback) {
[[nodiscard]] bool ReleasePages(Range r, MemoryModifyFunction& unback) {
bool success = unback(r);
if (ABSL_PREDICT_TRUE(success)) {
unbroken_ = false;
Expand Down
2 changes: 1 addition & 1 deletion tcmalloc/huge_page_filler_fuzz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ absl::flat_hash_set<PageId>& ReleasedPages() {

class MockUnback final : public MemoryModifyFunction {
public:
ABSL_MUST_USE_RESULT bool operator()(Range r) override {
[[nodiscard]] bool operator()(Range r) override {
if (!unback_success) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions tcmalloc/huge_page_filler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class PageTrackerTest : public testing::Test {

class MockUnbackInterface final : public MemoryModifyFunction {
public:
ABSL_MUST_USE_RESULT bool operator()(Range r) override {
[[nodiscard]] bool operator()(Range r) override {
TC_CHECK_LT(actual_index_, ABSL_ARRAYSIZE(actual_));
actual_[actual_index_].r = r;
TC_CHECK_LT(actual_index_, ABSL_ARRAYSIZE(expected_));
Expand Down Expand Up @@ -619,7 +619,7 @@ class BlockingUnback final : public MemoryModifyFunction {
public:
constexpr BlockingUnback() = default;

ABSL_MUST_USE_RESULT bool operator()(Range r) override {
[[nodiscard]] bool operator()(Range r) override {
if (!mu_) {
return success_;
}
Expand Down
2 changes: 1 addition & 1 deletion tcmalloc/huge_region_fuzz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace {

class MockUnback final : public MemoryModifyFunction {
public:
ABSL_MUST_USE_RESULT bool operator()(Range r) override {
[[nodiscard]] bool operator()(Range r) override {
release_callback_();

if (!unback_success_) {
Expand Down
4 changes: 2 additions & 2 deletions tcmalloc/internal/cpu_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ class CpuSet {
// Sets the CPU affinity of the process with the given pid. Returns true if
// successful. If returns false, please check the global 'errno' variable to
// determine the specific error that occurred.
ABSL_MUST_USE_RESULT bool SetAffinity(pid_t pid) {
[[nodiscard]] bool SetAffinity(pid_t pid) {
return sched_setaffinity(pid, kCpuSetBytes, cpu_set_.data()) == 0;
}

// Gets the CPU affinity of the process with the given pid. Return trues if
// successful. If returns false, please check the global 'errno' variable to
// determine the specific error that occurred.
ABSL_MUST_USE_RESULT bool GetAffinity(pid_t pid) {
[[nodiscard]] bool GetAffinity(pid_t pid) {
return sched_getaffinity(pid, kCpuSetBytes, cpu_set_.data()) == 0;
}

Expand Down
8 changes: 4 additions & 4 deletions tcmalloc/internal/percpu_tcmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class TcmallocSlab {
// <classes_to_resize> provides the number of size classes for which the
// capacity needs to be updated.
// <drain_handler> callback drains the old slab.
ABSL_MUST_USE_RESULT ResizeSlabsInfo UpdateMaxCapacities(
[[nodiscard]] ResizeSlabsInfo UpdateMaxCapacities(
void* new_slabs, absl::FunctionRef<size_t(size_t)> capacity,
absl::FunctionRef<void(int, uint16_t)> update_capacity,
absl::FunctionRef<bool(size_t)> populated, DrainHandler drain_handler,
Expand All @@ -168,7 +168,7 @@ class TcmallocSlab {
//
// Caller must ensure that there are no concurrent calls to InitCpu,
// ShrinkOtherCache, or Drain.
ABSL_MUST_USE_RESULT ResizeSlabsInfo ResizeSlabs(
[[nodiscard]] ResizeSlabsInfo ResizeSlabs(
Shift new_shift, void* new_slabs,
absl::FunctionRef<size_t(size_t)> capacity,
absl::FunctionRef<bool(size_t)> populated, DrainHandler drain_handler);
Expand Down Expand Up @@ -200,7 +200,7 @@ class TcmallocSlab {

// Remove an item (LIFO) from the current CPU's slab. If the slab is empty,
// invokes <underflow_handler> and returns its result.
ABSL_MUST_USE_RESULT void* Pop(size_t class_size);
[[nodiscard]] void* Pop(size_t size_class);

// Add up to <len> items to the current cpu slab from the array located at
// <batch>. Returns the number of items that were added (possibly 0). All
Expand Down Expand Up @@ -351,7 +351,7 @@ class TcmallocSlab {

// It's important that we use consistent values for slabs/shift rather than
// loading from the atomic repeatedly whenever we use one of the values.
ABSL_MUST_USE_RESULT std::pair<void*, Shift> GetSlabsAndShift(
[[nodiscard]] std::pair<void*, Shift> GetSlabsAndShift(
std::memory_order order) const {
return slabs_and_shift_.load(order).Get();
}
Expand Down
2 changes: 1 addition & 1 deletion tcmalloc/metadata_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MetadataAllocator {
MetadataAllocator& operator=(MetadataAllocator&&) = delete;

// Allocates bytes suitable for metadata.
ABSL_MUST_USE_RESULT virtual void* operator()(size_t bytes) = 0;
[[nodiscard]] virtual void* operator()(size_t bytes) = 0;
};

} // namespace tcmalloc::tcmalloc_internal
Expand Down
2 changes: 1 addition & 1 deletion tcmalloc/mock_metadata_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FakeMetadataAllocator final : public MetadataAllocator {
}
}

ABSL_MUST_USE_RESULT void* operator()(size_t size) override {
[[nodiscard]] void* operator()(size_t size) override {
void* ptr = malloc(size);
metadata_allocs_.push_back(ptr);
return ptr;
Expand Down
3 changes: 1 addition & 2 deletions tcmalloc/mock_virtual_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ namespace tcmalloc::tcmalloc_internal {

class FakeVirtualAllocator final : public VirtualAllocator {
public:
ABSL_MUST_USE_RESULT AddressRange operator()(size_t bytes,
size_t align) override;
[[nodiscard]] AddressRange operator()(size_t bytes, size_t align) override;

static constexpr size_t kMaxBacking = 1024 * 1024;
// This isn't super good form but we'll never have more than one HAT
Expand Down
2 changes: 1 addition & 1 deletion tcmalloc/system-alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int SystemReleaseErrors();
// be released, partial pages will not.)
//
// Returns true on success.
ABSL_MUST_USE_RESULT bool SystemRelease(void* start, size_t length);
[[nodiscard]] bool SystemRelease(void* start, size_t length);

// This call is the inverse of SystemRelease: the pages in this range
// are in use and should be faulted in. (In principle this is a
Expand Down
2 changes: 1 addition & 1 deletion tcmalloc/transfer_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void BackingTransferCache::InsertRange(absl::Span<void *> batch) const {
tc_globals.transfer_cache().InsertRange(size_class_, batch);
}

ABSL_MUST_USE_RESULT int BackingTransferCache::RemoveRange(
[[nodiscard]] int BackingTransferCache::RemoveRange(
const absl::Span<void *> batch) const {
return tc_globals.transfer_cache().RemoveRange(size_class_, batch);
}
Expand Down
3 changes: 1 addition & 2 deletions tcmalloc/transfer_cache_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ class TransferCache {

// Returns the actual number of fetched elements and stores elements in the
// batch.
ABSL_MUST_USE_RESULT int RemoveRange(int size_class,
const absl::Span<void *> batch)
[[nodiscard]] int RemoveRange(int size_class, const absl::Span<void *> batch)
ABSL_LOCKS_EXCLUDED(lock_) {
TC_ASSERT(!batch.empty());
TC_ASSERT_LE(batch.size(), kMaxObjectsToMove);
Expand Down

0 comments on commit a390a1d

Please sign in to comment.