Rename static singleton accessor

PiperOrigin-RevId: 384699374
Change-Id: I674baffc77bc6b3815f94512058a14d37d164c6f
This commit is contained in:
Christian Blichmann 2021-07-14 08:00:30 -07:00 committed by Copybara-Service
parent 34c7be759a
commit 7b711b85e8
4 changed files with 7 additions and 8 deletions

View File

@ -31,8 +31,8 @@
namespace sapi {
EmbedFile* EmbedFile::GetEmbedFileSingleton() {
static auto* embed_file_instance = new EmbedFile{};
EmbedFile* EmbedFile::instance() {
static auto* embed_file_instance = new EmbedFile();
return embed_file_instance;
}

View File

@ -27,13 +27,11 @@ namespace sapi {
// executable files.
class EmbedFile {
public:
EmbedFile() = default;
EmbedFile(const EmbedFile&) = delete;
EmbedFile& operator=(const EmbedFile&) = delete;
// Returns the pointer to the per-process EmbedFile object.
static EmbedFile* GetEmbedFileSingleton();
static EmbedFile* instance();
// Returns a file-descriptor for a given FileToc.
int GetFdForFileToc(const FileToc* toc);
@ -46,6 +44,8 @@ class EmbedFile {
// file-descriptors (-1 in case of errors).
static int CreateFdForFileToc(const FileToc* toc);
EmbedFile() = default;
// List of File TOCs and corresponding file-descriptors.
absl::flat_hash_map<const FileToc*, int> file_tocs_
ABSL_GUARDED_BY(file_tocs_mutex_);

View File

@ -141,8 +141,7 @@ absl::Status Sandbox::Init() {
std::string lib_path;
int embed_lib_fd = -1;
if (embed_lib_toc_) {
embed_lib_fd = EmbedFile::GetEmbedFileSingleton()->GetDupFdForFileToc(
embed_lib_toc_);
embed_lib_fd = EmbedFile::instance()->GetDupFdForFileToc(embed_lib_toc_);
if (embed_lib_fd == -1) {
PLOG(ERROR) << "Cannot create executable FD for TOC:'"
<< embed_lib_toc_->name << "'";

View File

@ -118,7 +118,7 @@ GlobalForkserverStartModeSet GetForkserverStartMode() {
std::unique_ptr<GlobalForkClient> StartGlobalForkServer() {
// The fd is owned by EmbedFile
int exec_fd = sapi::EmbedFile::GetEmbedFileSingleton()->GetFdForFileToc(
int exec_fd = sapi::EmbedFile::instance()->GetFdForFileToc(
forkserver_bin_embed_create());
SAPI_RAW_CHECK(exec_fd >= 0, "Getting FD for init binary failed");