Commit fc8c0ee1 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

leveldb: Migrate leveldb::Port back to //base primitives.

Bug: 1140147
Change-Id: Iccfaf6221f791673f84052b3916ced02cfd677ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2489324
Commit-Queue: Victor Costan <pwnall@chromium.org>
Auto-Submit: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819479}
parent eed85ab5
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "port/port_chromium.h" #include "port/port_chromium.h"
#include <cstddef>
#include <cstdint>
#include <string> #include <string>
#include "third_party/crc32c/src/include/crc32c/crc32c.h" #include "third_party/crc32c/src/include/crc32c/crc32c.h"
......
...@@ -7,15 +7,14 @@ ...@@ -7,15 +7,14 @@
#ifndef STORAGE_LEVELDB_PORT_PORT_CHROMIUM_H_ #ifndef STORAGE_LEVELDB_PORT_PORT_CHROMIUM_H_
#define STORAGE_LEVELDB_PORT_PORT_CHROMIUM_H_ #define STORAGE_LEVELDB_PORT_PORT_CHROMIUM_H_
#include <cassert> #include <cstddef>
#include <condition_variable> // NOLINT #include <cstdint>
#include <cstring>
#include <mutex> // NOLINT
#include <string> #include <string>
#include "base/macros.h" #include "base/check.h"
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h" #include "base/thread_annotations.h"
#include "build/build_config.h"
namespace leveldb { namespace leveldb {
namespace port { namespace port {
...@@ -28,35 +27,30 @@ class LOCKABLE Mutex { ...@@ -28,35 +27,30 @@ class LOCKABLE Mutex {
Mutex(const Mutex&) = delete; Mutex(const Mutex&) = delete;
Mutex& operator=(const Mutex&) = delete; Mutex& operator=(const Mutex&) = delete;
void Lock() EXCLUSIVE_LOCK_FUNCTION() { mu_.lock(); } void Lock() EXCLUSIVE_LOCK_FUNCTION() { lock_.Acquire(); }
void Unlock() UNLOCK_FUNCTION() { mu_.unlock(); } void Unlock() UNLOCK_FUNCTION() { lock_.Release(); }
void AssertHeld() ASSERT_EXCLUSIVE_LOCK() {} void AssertHeld() ASSERT_EXCLUSIVE_LOCK() { lock_.AssertAcquired(); }
private: private:
friend class CondVar; friend class CondVar;
std::mutex mu_; base::Lock lock_;
}; };
// Thinly wraps std::condition_variable. // Thinly wraps std::condition_variable.
class CondVar { class CondVar {
public: public:
explicit CondVar(Mutex* mu) : mu_(mu) { assert(mu != nullptr); } explicit CondVar(Mutex* mu) : cv_(&mu->lock_) { DCHECK(mu); }
~CondVar() = default; ~CondVar() = default;
CondVar(const CondVar&) = delete; CondVar(const CondVar&) = delete;
CondVar& operator=(const CondVar&) = delete; CondVar& operator=(const CondVar&) = delete;
void Wait() { void Wait() { cv_.Wait(); }
std::unique_lock<std::mutex> lock(mu_->mu_, std::adopt_lock); void Signal() { cv_.Signal(); }
cv_.wait(lock); void SignalAll() { cv_.Broadcast(); }
lock.release();
}
void Signal() { cv_.notify_one(); }
void SignalAll() { cv_.notify_all(); }
private: private:
std::condition_variable cv_; base::ConditionVariable cv_;
Mutex* const mu_;
}; };
bool Snappy_Compress(const char* input, size_t input_length, bool Snappy_Compress(const char* input, size_t input_length,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment