Skip to content

Commit

Permalink
Hoist ErrnoRestorer out of common.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 715092604
Change-Id: I65a38d996093227ef8c8e17fd7e3f0d730a7723c
  • Loading branch information
ckennelly authored and copybara-github committed Jan 13, 2025
1 parent afa0c1f commit 91bbb5f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions tcmalloc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ create_tcmalloc_libraries(
"//tcmalloc/internal:stacktrace_filter",
"//tcmalloc/internal:sysinfo",
"//tcmalloc/internal:timeseries_tracker",
"//tcmalloc/internal:util",
"//tcmalloc/selsan",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/base",
Expand Down
16 changes: 0 additions & 16 deletions tcmalloc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,22 +302,6 @@ inline double safe_div(double a, double b) {
}
}

// RAII class that will restore errno to the value it has when created.
class ErrnoRestorer {
public:
ErrnoRestorer() : saved_errno_(errno) {}
~ErrnoRestorer() { errno = saved_errno_; }

ErrnoRestorer(const ErrnoRestorer&) = delete;
ErrnoRestorer& operator=(const ErrnoRestorer&) = delete;

// Updates the errno value to restore to the current value.
void Override() { saved_errno_ = errno; }

private:
int saved_errno_;
};

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END
Expand Down
1 change: 1 addition & 0 deletions tcmalloc/cpu_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "tcmalloc/internal/percpu.h"
#include "tcmalloc/internal/percpu_tcmalloc.h"
#include "tcmalloc/internal/sysinfo.h"
#include "tcmalloc/internal/util.h"
#include "tcmalloc/pages.h"
#include "tcmalloc/parameters.h"
#include "tcmalloc/static_vars.h"
Expand Down
16 changes: 16 additions & 0 deletions tcmalloc/internal/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ inline void ScopedSigmask::Setmask(int how, sigset_t *set, sigset_t *old) {
TC_CHECK_EQ(result, 0);
}

// RAII class that will restore errno to the value it has when created.
class ErrnoRestorer {
public:
ErrnoRestorer() : saved_errno_(errno) {}
~ErrnoRestorer() { errno = saved_errno_; }

ErrnoRestorer(const ErrnoRestorer&) = delete;
ErrnoRestorer& operator=(const ErrnoRestorer&) = delete;

// Updates the errno value to restore to the current value.
void Override() { saved_errno_ = errno; }

private:
int saved_errno_;
};

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END
Expand Down
1 change: 1 addition & 0 deletions tcmalloc/pagemap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "tcmalloc/common.h"
#include "tcmalloc/internal/config.h"
#include "tcmalloc/internal/logging.h"
#include "tcmalloc/internal/util.h"
#include "tcmalloc/pages.h"
#include "tcmalloc/span.h"
#include "tcmalloc/static_vars.h"
Expand Down
1 change: 1 addition & 0 deletions tcmalloc/system-alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "tcmalloc/internal/numa.h"
#include "tcmalloc/internal/optimization.h"
#include "tcmalloc/internal/page_size.h"
#include "tcmalloc/internal/util.h"
#include "tcmalloc/malloc_extension.h"

#ifndef MADV_FREE
Expand Down

0 comments on commit 91bbb5f

Please sign in to comment.