Avoid global static initialization in Env::Default()

Summary:
Mark's task description from #2316777

Env::Default() comes from util/env_posix.cc

This is a static global.

static PosixEnv default_env;

Env* Env::Default() {
  return &default_env;
}

-----

These globals assume default_env was initialized first. I don't think that is safe or correct to do (http://stackoverflow.com/questions/1005685/c-static-initialization-order)

const string AutoRollLoggerTest::kTestDir(
test::TmpDir() + "/db_log_test");
const string AutoRollLoggerTest::kLogFile(
test::TmpDir() + "/db_log_test/LOG");
Env* AutoRollLoggerTest::env = Env::Default();

Test Plan:
run make clean && make && make check
But how can I know if it works in Ubuntu?

Reviewers: MarkCallaghan, chip

Reviewed By: chip

CC: leveldb, dhruba, haobo

Differential Revision: https://reviews.facebook.net/D10491
This commit is contained in:
Kai Liu 2013-04-22 18:10:28 -07:00
parent eb6d139666
commit 958b9c80e1

View File

@ -1078,9 +1078,8 @@ void PosixEnv::StartThread(void (*function)(void* arg), void* arg) {
} // namespace
static PosixEnv default_env;
Env* Env::Default() {
static PosixEnv default_env;
return &default_env;
}