distributed_mutex.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) Facebook, Inc. and its affiliates. 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. #pragma once
  6. #include "rocksdb/rocksdb_namespace.h"
  7. // This file declares a wrapper around the efficient folly DistributedMutex
  8. // that falls back on a standard mutex when not available. See
  9. // https://github.com/facebook/folly/blob/main/folly/synchronization/DistributedMutex.h
  10. // for benefits and limitations.
  11. // At the moment, only scoped locking is supported using DMutexLock
  12. // RAII wrapper, because lock/unlock APIs will vary.
  13. #ifdef USE_FOLLY
  14. #include <folly/synchronization/DistributedMutex.h>
  15. namespace ROCKSDB_NAMESPACE {
  16. class DMutex : public folly::DistributedMutex {
  17. public:
  18. static const char* kName() { return "folly::DistributedMutex"; }
  19. explicit DMutex(bool IGNORED_adaptive = false) { (void)IGNORED_adaptive; }
  20. // currently no-op
  21. void AssertHeld() const {}
  22. };
  23. using DMutexLock = std::lock_guard<folly::DistributedMutex>;
  24. } // namespace ROCKSDB_NAMESPACE
  25. #else
  26. #include <mutex>
  27. #include "port/port.h"
  28. namespace ROCKSDB_NAMESPACE {
  29. using DMutex = port::Mutex;
  30. using DMutexLock = std::lock_guard<DMutex>;
  31. } // namespace ROCKSDB_NAMESPACE
  32. #endif