Merge "make getBpfSupportLevel() cached"

This commit is contained in:
Maciej Żenczykowski 2020-02-11 19:08:03 +00:00 • committed by Gerrit Code Review
commit 61588e0e64

View file

@ -106,7 +106,7 @@ std::string BpfLevelToString(BpfLevel bpfLevel) {
}
}
BpfLevel getBpfSupportLevel() {
static BpfLevel getUncachedBpfSupportLevel() {
struct utsname buf;
int kernel_version_major;
int kernel_version_minor;
@ -135,5 +135,17 @@ BpfLevel getBpfSupportLevel() {
return BpfLevel::NONE;
}
BpfLevel getBpfSupportLevel() {
static bool initialized = false;
static BpfLevel cache;
if (!initialized) {
initialized = true;
cache = getUncachedBpfSupportLevel();
}
return cache;
}
} // namespace bpf
} // namespace android