2022-06-17 20:08:45 +00:00
|
|
|
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "rocksdb/rocksdb_namespace.h"
|
|
|
|
|
|
|
|
// This file declares a wrapper around the efficient folly DistributedMutex
|
|
|
|
// that falls back on a standard mutex when not available. See
|
|
|
|
// https://github.com/facebook/folly/blob/main/folly/synchronization/DistributedMutex.h
|
|
|
|
// for benefits and limitations.
|
|
|
|
|
|
|
|
// At the moment, only scoped locking is supported using DMutexLock
|
|
|
|
// RAII wrapper, because lock/unlock APIs will vary.
|
|
|
|
|
|
|
|
#ifdef USE_FOLLY
|
|
|
|
|
|
|
|
#include <folly/synchronization/DistributedMutex.h>
|
|
|
|
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
|
|
|
|
class DMutex : public folly::DistributedMutex {
|
|
|
|
public:
|
|
|
|
static const char* kName() { return "folly::DistributedMutex"; }
|
|
|
|
|
|
|
|
explicit DMutex(bool IGNORED_adaptive = false) { (void)IGNORED_adaptive; }
|
|
|
|
|
|
|
|
// currently no-op
|
2023-10-12 17:05:23 +00:00
|
|
|
void AssertHeld() const {}
|
2022-06-17 20:08:45 +00:00
|
|
|
};
|
|
|
|
using DMutexLock = std::lock_guard<folly::DistributedMutex>;
|
|
|
|
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
remove dependency on options.h for port_posix.h andport_win.h (#11214)
Summary:
The files in `port/`, such as `port_posix.h`, are layering over the system libraries, so shouldn't include the DB-specific files like `options.h`. This PR remove this dependency.
# How
The reason that `port_posix.h` (or `port_win.h`) include `options.h` is to use `CpuPriority`, as there is a method `SetCpuPriority()` in `port_posix.h` that uses `CpuPriority.`
- I think `SetCpuPriority()` make sense to exist in `port_posix.h` as it provides has platform-dependent implementation
- `CpuPriority` enum is defined in `env.h`, but used in `rocksdb/include` and `port/`.
Hence, let us define `CpuPriority` enum in a common file, say `port_defs.h`, such that both directories `rocksdb/include` and `port/` can include.
When we remove this dependency, some other files have compile errors because they can't find definitions, so add header files to resolve
# Test
make all check -j
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11214
Reviewed By: pdillinger
Differential Revision: D43196910
Pulled By: guowentian
fbshipit-source-id: 70deccb72844cfb08fcc994f76c6ef6df5d55ab9
2023-02-13 10:21:38 +00:00
|
|
|
#include <mutex>
|
|
|
|
|
2022-06-17 20:08:45 +00:00
|
|
|
#include "port/port.h"
|
|
|
|
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
|
|
|
|
using DMutex = port::Mutex;
|
|
|
|
using DMutexLock = std::lock_guard<DMutex>;
|
|
|
|
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
|
|
|
|
|
|
|
#endif
|