env_default.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #include <mutex>
  10. #include <rocksdb/env.h>
  11. #include "port/win/env_win.h"
  12. #include "test_util/sync_point.h"
  13. #include "util/compression_context_cache.h"
  14. #include "util/thread_local.h"
  15. namespace ROCKSDB_NAMESPACE {
  16. namespace port {
  17. // We choose not to destroy the env because joining the threads from the
  18. // system loader
  19. // which destroys the statics (same as from DLLMain) creates a system loader
  20. // dead-lock.
  21. // in this manner any remaining threads are terminated OK.
  22. namespace {
  23. std::once_flag winenv_once_flag;
  24. Env* envptr;
  25. };
  26. }
  27. Env* Env::Default() {
  28. using namespace port;
  29. ThreadLocalPtr::InitSingletons();
  30. CompressionContextCache::InitSingleton();
  31. INIT_SYNC_POINT_SINGLETONS();
  32. std::call_once(winenv_once_flag, []() { envptr = new WinEnv(); });
  33. return envptr;
  34. }
  35. } // namespace ROCKSDB_NAMESPACE