Skip to content

Commit

Permalink
Roll src/third_party/leveldatabase/src/ fe4494804..9ce30510d (9 commits)
Browse files Browse the repository at this point in the history
https://chromium.googlesource.com/external/leveldb.git/+log/fe4494804f5e..9ce30510d482

$ git log fe4494804..9ce30510d --date=short --no-merges --format='%ad %ae %s'
2019-03-11 cmumford Deleted dangling reference to deleted atomic_pointer.h.
2019-03-11 costan leveldb: Replace AtomicPointer with std::atomic.
2019-03-11 cmumford Make InMemoryEnv more consistent with filesystem based Env's.
2019-03-11 costan leveldb: Remove unused file port/win/stdint.h.
2019-03-11 dimitris.apostolou Fix typo (#565)
2019-03-07 costan Add AppVeyor (Windows CI) badge to README.
2019-03-07 costan Align windows_logger with posix_logger.
2019-03-04 costan Improve CI configuration.
2019-03-01 cmumford Added native support for Windows.

Created with:
  roll-dep src/third_party/leveldatabase/src

This roll also required changes to the Chromium source:

1. Fixups for the Windows DeleteFile macro. Previously we compiled
   leveldb with DeleteFile defined as DeleteFileW which meant that
   leveldb::Env::DeleteFile was really leveldb::Env::DeleteFileW.
   The leveldb native Windows support undefines/redefines the
   DeleteFile macro to always force the Env::DeleteFile.
2. Synced leveldb::port::Mutex and leveldb::port::CondVar
   implementations in port_chromium.h with those in
   port_stdcxx.h. This was done to eliminate includes of
   header files in //base which defined the DeleteFile
   macro so that when leveldb was compiled it used DeleteFile
   throughout the library and never DeleteFileW.
3. Removal of AtomicPointer from the Chromium port now that
   leveldb uses std::atomic.

Bug: None
Change-Id: I7a6b284d278ded76d4f4970081b3f3c3578907e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1516881
Reviewed-by: Victor Costan <[email protected]>
Reviewed-by: Marijn Kruisselbrink <[email protected]>
Commit-Queue: Chris Mumford <[email protected]>
Cr-Commit-Position: refs/heads/master@{#642625}
  • Loading branch information
cmumford authored and Commit Bot committed Mar 20, 2019
1 parent 1ee2986 commit 6b4373b
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 97 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ deps = {
},

'src/third_party/leveldatabase/src':
Var('chromium_git') + '/external/leveldb.git' + '@' + 'fe4494804f5e3a2e25485d32aeb0eb7d2f25732e',
Var('chromium_git') + '/external/leveldb.git' + '@' + '9ce30510d482f5b2fa2965201453f0fc914f700c',

'src/third_party/libFuzzer/src':
Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git' + '@' + Var('libfuzzer_revision'),
Expand Down
4 changes: 4 additions & 0 deletions components/services/leveldb/env_mojo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include "third_party/leveldatabase/chromium_logger.h"
#include "third_party/leveldatabase/src/include/leveldb/status.h"

#if defined(OS_WIN) && defined(DeleteFile)
#undef DeleteFile
#endif

using leveldb_env::UMALogger;

namespace leveldb {
Expand Down
12 changes: 12 additions & 0 deletions components/services/leveldb/env_mojo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@
#include <string>
#include <vector>

#include "build/build_config.h"
#include "components/services/filesystem/public/interfaces/directory.mojom.h"
#include "components/services/leveldb/leveldb_mojo_proxy.h"
#include "third_party/leveldatabase/env_chromium.h"
#include "third_party/leveldatabase/src/include/leveldb/env.h"

#if defined(OS_WIN) && defined(DeleteFile)
// See comment in env.h.
#undef DeleteFile
#define ENV_MOJO_DELETEFILE_UNDEFINED
#endif // defined(OS_WIN) && defined(DeleteFile)

namespace leveldb {

class MojoRetrierProvider {
Expand Down Expand Up @@ -87,4 +94,9 @@ class MojoEnv : public Env,

} // namespace leveldb

// Redefine DeleteFile if necessary.
#if defined(OS_WIN) && defined(ENV_MOJO_DELETEFILE_UNDEFINED)
#define DeleteFile DeleteFileW
#endif

#endif // COMPONENTS_SERVICES_LEVELDB_ENV_MOJO_H_
11 changes: 0 additions & 11 deletions third_party/leveldatabase/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ config("leveldb_config") {
"src",
"src/include",
]

if (is_win) {
# windows.h #defines DeleteFile to DeleteFileW on Unicode builds. This
# definition is in effect in a large part of Chromium's compilation units.
# leveldb::Env has a DeleteFile method, which becomes DeleteFileW when the
# definition is in effect.
#
# Define the macro everywhere, to avoid reasoning about which headers bring
# windows.h in.
defines += [ "DeleteFile=DeleteFileW" ]
}
}

leveldb_sources = [
Expand Down
2 changes: 1 addition & 1 deletion third_party/leveldatabase/README.chromium
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Name: LevelDB: A Fast Persistent Key-Value Store
Short Name: leveldb
URL: https://github.com/google/leveldb.git
Version: 1.20.git.7b945f200339aa47c24788d3ee9910c09c513843
Version: 1.20.git.9ce30510d482f5b2fa2965201453f0fc914f700c
License: New BSD
License File: src/LICENSE
Security Critical: yes
Expand Down
13 changes: 10 additions & 3 deletions third_party/leveldatabase/env_chromium.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
#include "third_party/leveldatabase/src/include/leveldb/options.h"
#include "third_party/re2/src/re2/re2.h"

#if defined(OS_WIN)
#undef DeleteFile
#define base_DeleteFile base::DeleteFileW
#else // defined(OS_WIN)
#define base_DeleteFile base::DeleteFile
#endif // defined(OS_WIN)

using base::FilePath;
using base::trace_event::MemoryAllocatorDump;
using base::trace_event::MemoryDumpArgs;
Expand Down Expand Up @@ -869,7 +876,7 @@ void ChromiumEnv::DeleteBackupFiles(const FilePath& dir) {
FILE_PATH_LITERAL("*.bak"));
for (base::FilePath fname = dir_reader.Next(); !fname.empty();
fname = dir_reader.Next()) {
histogram->AddBoolean(base::DeleteFile(fname, false));
histogram->AddBoolean(base_DeleteFile(fname, false));
}
}

Expand Down Expand Up @@ -903,7 +910,7 @@ Status ChromiumEnv::DeleteFile(const std::string& fname) {
Status result;
FilePath fname_filepath = FilePath::FromUTF8Unsafe(fname);
// TODO(jorlow): Should we assert this is a file?
if (!base::DeleteFile(fname_filepath, false)) {
if (!base_DeleteFile(fname_filepath, false)) {
result = MakeIOError(fname, "Could not delete file.", kDeleteFile);
RecordErrorAt(kDeleteFile);
}
Expand All @@ -927,7 +934,7 @@ Status ChromiumEnv::CreateDir(const std::string& name) {
Status ChromiumEnv::DeleteDir(const std::string& name) {
Status result;
// TODO(jorlow): Should we assert this is a directory?
if (!base::DeleteFile(FilePath::FromUTF8Unsafe(name), false)) {
if (!base_DeleteFile(FilePath::FromUTF8Unsafe(name), false)) {
result = MakeIOError(name, "Could not delete directory.", kDeleteDir);
RecordErrorAt(kDeleteDir);
}
Expand Down
13 changes: 13 additions & 0 deletions third_party/leveldatabase/env_chromium.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/metrics/histogram.h"
#include "base/synchronization/condition_variable.h"
#include "build/build_config.h"
#include "leveldb/cache.h"
#include "leveldb/db.h"
#include "leveldb/env.h"
#include "leveldb/export.h"
#include "port/port_chromium.h"
#include "util/mutexlock.h"

#if defined(OS_WIN) && defined(DeleteFile)
// See comment in env.h.
#undef DeleteFile
#define ENV_CHROMIUM_DELETEFILE_UNDEFINED
#endif // defined(OS_WIN) && defined(DeleteFile)

namespace base {
namespace trace_event {
class MemoryAllocatorDump;
Expand Down Expand Up @@ -369,4 +377,9 @@ LEVELDB_EXPORT leveldb::Slice MakeSlice(const base::StringPiece& s);

} // namespace leveldb_env

// Redefine DeleteFile if necessary.
#if defined(OS_WIN) && defined(ENV_CHROMIUM_DELETEFILE_UNDEFINED)
#define DeleteFile DeleteFileW
#endif

#endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_
5 changes: 5 additions & 0 deletions third_party/leveldatabase/env_chromium_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "base/test/scoped_task_environment.h"
#include "base/test/test_suite.h"
#include "base/trace_event/process_memory_dump.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/leveldatabase/env_chromium.h"
#include "third_party/leveldatabase/leveldb_chrome.h"
Expand All @@ -27,6 +28,10 @@

#define FPL FILE_PATH_LITERAL

#if defined(OS_WIN) && defined(DeleteFile)
#undef DeleteFile
#endif

using base::trace_event::MemoryDumpArgs;
using base::trace_event::MemoryDumpLevelOfDetail;
using base::trace_event::ProcessMemoryDump;
Expand Down
10 changes: 9 additions & 1 deletion third_party/leveldatabase/leveldb_chrome.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/memory_dump_provider.h"
#include "base/trace_event/process_memory_dump.h"
#include "build/build_config.h"
#include "third_party/leveldatabase/env_chromium.h"
#include "third_party/leveldatabase/src/helpers/memenv/memenv.h"
#include "util/mutexlock.h"

#if defined(OS_WIN)
#undef DeleteFile
#define base_DeleteFile base::DeleteFileW
#else // defined(OS_WIN)
#define base_DeleteFile base::DeleteFile
#endif // defined(OS_WIN)

using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel;
using base::trace_event::MemoryAllocatorDump;
using base::trace_event::MemoryDumpArgs;
Expand Down Expand Up @@ -365,7 +373,7 @@ leveldb::Status DeleteDB(const base::FilePath& db_path,

// TODO(cmumford): To be fully safe this implementation should acquire a lock
// as there is some daylight in between DestroyDB and DeleteFile.
if (!base::DeleteFile(db_path, true)) {
if (!base_DeleteFile(db_path, true)) {
// Only delete the directory when when DestroyDB is successful. This is
// because DestroyDB checks for database locks, and will fail if in use.
return leveldb::Status::IOError(db_path.AsUTF8Unsafe(), "Error deleting");
Expand Down
36 changes: 0 additions & 36 deletions third_party/leveldatabase/port/port_chromium.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,12 @@

#include <string>

#include "base/threading/platform_thread.h"
#include "third_party/crc32c/src/include/crc32c/crc32c.h"
#include "third_party/snappy/src/snappy.h"
#include "util/logging.h"

namespace leveldb {
namespace port {

Mutex::Mutex() = default;

Mutex::~Mutex() = default;

void Mutex::Lock() {
mu_.Acquire();
}

void Mutex::Unlock() {
mu_.Release();
}

void Mutex::AssertHeld() {
mu_.AssertAcquired();
}

CondVar::CondVar(Mutex* mu)
: cv_(&mu->mu_) {
}

CondVar::~CondVar() = default;

void CondVar::Wait() {
cv_.Wait();
}

void CondVar::Signal(){
cv_.Signal();
}

void CondVar::SignalAll() {
cv_.Broadcast();
}

bool Snappy_Compress(const char* input,
size_t input_length,
std::string* output) {
Expand Down
70 changes: 26 additions & 44 deletions third_party/leveldatabase/port/port_chromium.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
#ifndef STORAGE_LEVELDB_PORT_PORT_CHROMIUM_H_
#define STORAGE_LEVELDB_PORT_PORT_CHROMIUM_H_

#include <stddef.h>
#include <stdint.h>

#include <cassert>
#include <condition_variable> // NOLINT
#include <cstring>
#include <mutex> // NOLINT
#include <string>

#include "base/atomicops.h"
#include "base/macros.h"
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
#include "build/build_config.h"

Expand All @@ -28,56 +25,41 @@ static const bool kLittleEndian = true;

class LOCKABLE Mutex {
public:
Mutex();
~Mutex();
void Lock() EXCLUSIVE_LOCK_FUNCTION();
void Unlock() UNLOCK_FUNCTION();
void AssertHeld() ASSERT_EXCLUSIVE_LOCK();
Mutex() = default;
~Mutex() = default;

private:
base::Lock mu_;
Mutex(const Mutex&) = delete;
Mutex& operator=(const Mutex&) = delete;

friend class CondVar;
DISALLOW_COPY_AND_ASSIGN(Mutex);
};

class CondVar {
public:
explicit CondVar(Mutex* mu);
~CondVar();
void Wait();
void Signal();
void SignalAll();
void Lock() EXCLUSIVE_LOCK_FUNCTION() { mu_.lock(); }
void Unlock() UNLOCK_FUNCTION() { mu_.unlock(); }
void AssertHeld() ASSERT_EXCLUSIVE_LOCK() {}

private:
base::ConditionVariable cv_;

DISALLOW_COPY_AND_ASSIGN(CondVar);
friend class CondVar;
std::mutex mu_;
};

class AtomicPointer {
// Thinly wraps std::condition_variable.
class CondVar {
public:
AtomicPointer() = default;
~AtomicPointer() = default;
explicit CondVar(Mutex* mu) : mu_(mu) { assert(mu != nullptr); }
~CondVar() = default;

explicit AtomicPointer(void* p) : rep_(reinterpret_cast<Rep>(p)) {}
CondVar(const CondVar&) = delete;
CondVar& operator=(const CondVar&) = delete;

inline void* Acquire_Load() const {
return reinterpret_cast<void*>(base::subtle::Acquire_Load(&rep_));
}
inline void Release_Store(void* v) {
base::subtle::Release_Store(&rep_, reinterpret_cast<Rep>(v));
}
inline void* NoBarrier_Load() const {
return reinterpret_cast<void*>(base::subtle::NoBarrier_Load(&rep_));
}
inline void NoBarrier_Store(void* v) {
base::subtle::NoBarrier_Store(&rep_, reinterpret_cast<Rep>(v));
void Wait() {
std::unique_lock<std::mutex> lock(mu_->mu_, std::adopt_lock);
cv_.wait(lock);
lock.release();
}
void Signal() { cv_.notify_one(); }
void SignalAll() { cv_.notify_all(); }

private:
using Rep = base::subtle::AtomicWord;
Rep rep_;
std::condition_variable cv_;
Mutex* const mu_;
};

bool Snappy_Compress(const char* input, size_t input_length,
Expand Down

0 comments on commit 6b4373b

Please sign in to comment.