mirror of
https://github.com/gperftools/gperftools
synced 2025-02-18 05:06:55 +00:00
issue-655: use safe getenv for aggressive decommit mode flag
Because otherwise we risk deadlock due to too early use of getenv on windows.
This commit is contained in:
parent
8c3dc52fcf
commit
8e97626378
@ -111,6 +111,40 @@
|
||||
} \
|
||||
using FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead::FLAGS_##name
|
||||
|
||||
// implemented in sysinfo.cc
|
||||
namespace tcmalloc {
|
||||
namespace commandlineflags {
|
||||
|
||||
inline bool StringToBool(const char *value, bool def) {
|
||||
if (!value) {
|
||||
return def;
|
||||
}
|
||||
return memchr("tTyY1\0", value[0], 6) != NULL;
|
||||
}
|
||||
|
||||
inline int StringToInt(const char *value, int def) {
|
||||
if (!value) {
|
||||
return def;
|
||||
}
|
||||
return strtol(value, NULL, 10);
|
||||
}
|
||||
|
||||
inline long long StringToLongLong(const char *value, long long def) {
|
||||
if (!value) {
|
||||
return def;
|
||||
}
|
||||
return strtoll(value, NULL, 10);
|
||||
}
|
||||
|
||||
inline double StringToDouble(const char *value, double def) {
|
||||
if (!value) {
|
||||
return def;
|
||||
}
|
||||
return strtod(value, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// These macros (could be functions, but I don't want to bother with a .cc
|
||||
// file), make it easier to initialize flags from the environment.
|
||||
|
||||
@ -118,15 +152,15 @@
|
||||
(!getenv(envname) ? (dflt) : getenv(envname))
|
||||
|
||||
#define EnvToBool(envname, dflt) \
|
||||
(!getenv(envname) ? (dflt) : memchr("tTyY1\0", getenv(envname)[0], 6) != NULL)
|
||||
tcmalloc::commandlineflags::StringToBool(getenv(envname), dflt)
|
||||
|
||||
#define EnvToInt(envname, dflt) \
|
||||
(!getenv(envname) ? (dflt) : strtol(getenv(envname), NULL, 10))
|
||||
tcmalloc::commandlineflags::StringToInt(getenv(envname), dflt)
|
||||
|
||||
#define EnvToInt64(envname, dflt) \
|
||||
(!getenv(envname) ? (dflt) : strtoll(getenv(envname), NULL, 10))
|
||||
tcmalloc::commandlineflags::StringToLongLong(getenv(envname), dflt)
|
||||
|
||||
#define EnvToDouble(envname, dflt) \
|
||||
(!getenv(envname) ? (dflt) : strtod(getenv(envname), NULL))
|
||||
tcmalloc::commandlineflags::StringToDouble(getenv(envname), dflt)
|
||||
|
||||
#endif // BASE_COMMANDLINEFLAGS_H_
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "internal_logging.h" // for CHECK_CONDITION
|
||||
#include "common.h"
|
||||
#include "sampler.h" // for Sampler
|
||||
#include "getenv_safe.h" // TCMallocGetenvSafe
|
||||
#include "base/googleinit.h"
|
||||
|
||||
namespace tcmalloc {
|
||||
@ -96,7 +97,13 @@ void Static::InitStaticVars() {
|
||||
// in is caches as pointers that are sources of heap object liveness,
|
||||
// which leads to it missing some memory leaks.
|
||||
pageheap_ = new (MetaDataAlloc(sizeof(PageHeap))) PageHeap;
|
||||
pageheap_->SetAggressiveDecommit(EnvToBool("TCMALLOC_AGGRESSIVE_DECOMMIT", false));
|
||||
|
||||
bool aggressive_decommit =
|
||||
tcmalloc::commandlineflags::StringToBool(
|
||||
TCMallocGetenvSafe("TCMALLOC_AGGRESSIVE_DECOMMIT"), false);
|
||||
|
||||
pageheap_->SetAggressiveDecommit(aggressive_decommit);
|
||||
|
||||
DLL_Init(&sampled_objects_);
|
||||
Sampler::InitStatics();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user