env_default.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. //
  6. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  7. // Use of this source code is governed by a BSD-style license that can be
  8. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  9. #if defined(OS_WIN)
  10. #include <mutex>
  11. #include "port/win/env_win.h"
  12. #include "rocksdb/env.h"
  13. #include "test_util/sync_point.h"
  14. #include "util/compression_context_cache.h"
  15. #include "util/thread_local.h"
  16. namespace ROCKSDB_NAMESPACE {
  17. namespace port {
  18. // We choose not to destroy the env because joining the threads from the
  19. // system loader
  20. // which destroys the statics (same as from DLLMain) creates a system loader
  21. // dead-lock.
  22. // in this manner any remaining threads are terminated OK.
  23. namespace {
  24. std::once_flag winenv_once_flag;
  25. Env* envptr;
  26. }; // namespace
  27. } // namespace port
  28. Env* Env::Default() {
  29. ThreadLocalPtr::InitSingletons();
  30. CompressionContextCache::InitSingleton();
  31. INIT_SYNC_POINT_SINGLETONS();
  32. std::call_once(port::winenv_once_flag,
  33. []() { port::envptr = new port::WinEnv(); });
  34. return port::envptr;
  35. }
  36. } // namespace ROCKSDB_NAMESPACE
  37. #endif