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
main
Kai Liu 12 years ago
parent eb6d139666
commit 958b9c80e1
  1. 3
      util/env_posix.cc

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

Loading…
Cancel
Save