aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/arena.cc2
-rw-r--r--util/arena_test.cc7
-rw-r--r--util/bloom_test.cc5
-rw-r--r--util/cache.cc2
-rw-r--r--util/cache_test.cc5
-rw-r--r--util/coding.cc10
-rw-r--r--util/coding_test.cc5
-rw-r--r--util/crc32c_test.cc5
-rw-r--r--util/env_posix.cc44
-rw-r--r--util/env_posix_test.cc6
-rw-r--r--util/env_test.cc7
-rw-r--r--util/env_windows.cc32
-rw-r--r--util/hash_test.cc5
-rw-r--r--util/logging_test.cc5
-rw-r--r--util/no_destructor_test.cc5
-rw-r--r--util/random.h2
-rw-r--r--util/status_test.cc5
17 files changed, 67 insertions, 85 deletions
diff --git a/util/arena.cc b/util/arena.cc
index 41c6a0d..d3ec2be 100644
--- a/util/arena.cc
+++ b/util/arena.cc
@@ -14,7 +14,7 @@ Arena::Arena()
Arena::~Arena() {
for (size_t i = 0; i < blocks_.size(); i++) {
//cudaFree(blocks_[i]);
- delete [] blocks_[i];
+ delete[] blocks_[i];
}
}
diff --git a/util/arena_test.cc b/util/arena_test.cc
index d2ead39..3e2011e 100644
--- a/util/arena_test.cc
+++ b/util/arena_test.cc
@@ -3,9 +3,9 @@
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#include "util/arena.h"
-#include "util/random.h"
#include "gtest/gtest.h"
+#include "util/random.h"
namespace leveldb {
@@ -59,8 +59,3 @@ TEST(ArenaTest, Simple) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/bloom_test.cc b/util/bloom_test.cc
index 520473e..9f11108 100644
--- a/util/bloom_test.cc
+++ b/util/bloom_test.cc
@@ -152,8 +152,3 @@ TEST_F(BloomTest, VaryingLengths) {
// Different bits-per-byte
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/cache.cc b/util/cache.cc
index ad1e9a2..fc3d154 100644
--- a/util/cache.cc
+++ b/util/cache.cc
@@ -54,7 +54,7 @@ struct LRUHandle {
char key_data[1]; // Beginning of key
Slice key() const {
- // next_ is only equal to this if the LRU handle is the list head of an
+ // next is only equal to this if the LRU handle is the list head of an
// empty list. List heads never have meaningful keys.
assert(next != this);
diff --git a/util/cache_test.cc b/util/cache_test.cc
index 79cfc27..e68da34 100644
--- a/util/cache_test.cc
+++ b/util/cache_test.cc
@@ -222,8 +222,3 @@ TEST_F(CacheTest, ZeroSizeCache) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/coding.cc b/util/coding.cc
index df3fa10..a8f8af8 100644
--- a/util/coding.cc
+++ b/util/coding.cc
@@ -142,16 +142,6 @@ bool GetVarint64(Slice* input, uint64_t* value) {
}
}
-const char* GetLengthPrefixedSlice(const char* p, const char* limit,
- Slice* result) {
- uint32_t len;
- p = GetVarint32Ptr(p, limit, &len);
- if (p == nullptr) return nullptr;
- if (p + len > limit) return nullptr;
- *result = Slice(p, len);
- return p + len;
-}
-
bool GetLengthPrefixedSlice(Slice* input, Slice* result) {
uint32_t len;
if (GetVarint32(input, &len) && input->size() >= len) {
diff --git a/util/coding_test.cc b/util/coding_test.cc
index aa6c748..cceda14 100644
--- a/util/coding_test.cc
+++ b/util/coding_test.cc
@@ -191,8 +191,3 @@ TEST(Coding, Strings) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/crc32c_test.cc b/util/crc32c_test.cc
index 647e561..2fe1c41 100644
--- a/util/crc32c_test.cc
+++ b/util/crc32c_test.cc
@@ -54,8 +54,3 @@ TEST(CRC, Mask) {
} // namespace crc32c
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/env_posix.cc b/util/env_posix.cc
index 24b1c4c..ffd06c4 100644
--- a/util/env_posix.cc
+++ b/util/env_posix.cc
@@ -4,7 +4,6 @@
#include <dirent.h>
#include <fcntl.h>
-#include <pthread.h>
#include <sys/mman.h>
#ifndef __Fuchsia__
#include <sys/resource.h>
@@ -74,7 +73,14 @@ Status PosixError(const std::string& context, int error_number) {
class Limiter {
public:
// Limit maximum number of resources to |max_acquires|.
- Limiter(int max_acquires) : acquires_allowed_(max_acquires) {}
+ Limiter(int max_acquires)
+ :
+#if !defined(NDEBUG)
+ max_acquires_(max_acquires),
+#endif // !defined(NDEBUG)
+ acquires_allowed_(max_acquires) {
+ assert(max_acquires >= 0);
+ }
Limiter(const Limiter&) = delete;
Limiter operator=(const Limiter&) = delete;
@@ -87,15 +93,35 @@ class Limiter {
if (old_acquires_allowed > 0) return true;
- acquires_allowed_.fetch_add(1, std::memory_order_relaxed);
+ int pre_increment_acquires_allowed =
+ acquires_allowed_.fetch_add(1, std::memory_order_relaxed);
+
+ // Silence compiler warnings about unused arguments when NDEBUG is defined.
+ (void)pre_increment_acquires_allowed;
+ // If the check below fails, Release() was called more times than acquire.
+ assert(pre_increment_acquires_allowed < max_acquires_);
+
return false;
}
// Release a resource acquired by a previous call to Acquire() that returned
// true.
- void Release() { acquires_allowed_.fetch_add(1, std::memory_order_relaxed); }
+ void Release() {
+ int old_acquires_allowed =
+ acquires_allowed_.fetch_add(1, std::memory_order_relaxed);
+
+ // Silence compiler warnings about unused arguments when NDEBUG is defined.
+ (void)old_acquires_allowed;
+ // If the check below fails, Release() was called more times than acquire.
+ assert(old_acquires_allowed < max_acquires_);
+ }
private:
+#if !defined(NDEBUG)
+ // Catches an excessive number of Release() calls.
+ const int max_acquires_;
+#endif // !defined(NDEBUG)
+
// The number of available resources.
//
// This is a counter and is not tied to the invariants of any other class, so
@@ -110,7 +136,7 @@ class Limiter {
class PosixSequentialFile final : public SequentialFile {
public:
PosixSequentialFile(std::string filename, int fd)
- : fd_(fd), filename_(filename) {}
+ : fd_(fd), filename_(std::move(filename)) {}
~PosixSequentialFile() override { close(fd_); }
Status Read(size_t n, Slice* result, char* scratch) override {
@@ -216,7 +242,7 @@ class PosixMmapReadableFile final : public RandomAccessFile {
// over the ownership of the region.
//
// |mmap_limiter| must outlive this instance. The caller must have already
- // aquired the right to use one mmap region, which will be released when this
+ // acquired the right to use one mmap region, which will be released when this
// instance is destroyed.
PosixMmapReadableFile(std::string filename, char* mmap_base, size_t length,
Limiter* mmap_limiter)
@@ -730,7 +756,7 @@ class PosixEnv : public Env {
// Instances are constructed on the thread calling Schedule() and used on the
// background thread.
//
- // This structure is thread-safe beacuse it is immutable.
+ // This structure is thread-safe because it is immutable.
struct BackgroundWorkItem {
explicit BackgroundWorkItem(void (*function)(void* arg), void* arg)
: function(function), arg(arg) {}
@@ -844,7 +870,7 @@ class SingletonEnv {
public:
SingletonEnv() {
#if !defined(NDEBUG)
- env_initialized_.store(true, std::memory_order::memory_order_relaxed);
+ env_initialized_.store(true, std::memory_order_relaxed);
#endif // !defined(NDEBUG)
static_assert(sizeof(env_storage_) >= sizeof(EnvType),
"env_storage_ will not fit the Env");
@@ -861,7 +887,7 @@ class SingletonEnv {
static void AssertEnvNotInitialized() {
#if !defined(NDEBUG)
- assert(!env_initialized_.load(std::memory_order::memory_order_relaxed));
+ assert(!env_initialized_.load(std::memory_order_relaxed));
#endif // !defined(NDEBUG)
}
diff --git a/util/env_posix_test.cc b/util/env_posix_test.cc
index da264f0..34bda62 100644
--- a/util/env_posix_test.cc
+++ b/util/env_posix_test.cc
@@ -243,8 +243,8 @@ TEST_F(EnvPosixTest, TestCloseOnExecRandomAccessFile) {
// Exhaust the RandomAccessFile mmap limit. This way, the test
// RandomAccessFile instance below is backed by a file descriptor, not by an
// mmap region.
- leveldb::RandomAccessFile* mmapped_files[kReadOnlyFileLimit] = {nullptr};
- for (int i = 0; i < kReadOnlyFileLimit; i++) {
+ leveldb::RandomAccessFile* mmapped_files[kMMapLimit];
+ for (int i = 0; i < kMMapLimit; i++) {
ASSERT_LEVELDB_OK(env_->NewRandomAccessFile(file_path, &mmapped_files[i]));
}
@@ -253,7 +253,7 @@ TEST_F(EnvPosixTest, TestCloseOnExecRandomAccessFile) {
CheckCloseOnExecDoesNotLeakFDs(open_fds);
delete file;
- for (int i = 0; i < kReadOnlyFileLimit; i++) {
+ for (int i = 0; i < kMMapLimit; i++) {
delete mmapped_files[i];
}
ASSERT_LEVELDB_OK(env_->RemoveFile(file_path));
diff --git a/util/env_test.cc b/util/env_test.cc
index 491ef43..47174f5 100644
--- a/util/env_test.cc
+++ b/util/env_test.cc
@@ -14,8 +14,6 @@
namespace leveldb {
-static const int kDelayMicros = 100000;
-
class EnvTest : public testing::Test {
public:
EnvTest() : env_(Env::Default()) {}
@@ -233,8 +231,3 @@ TEST_F(EnvTest, ReopenAppendableFile) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/env_windows.cc b/util/env_windows.cc
index 449f564..1c74b02 100644
--- a/util/env_windows.cc
+++ b/util/env_windows.cc
@@ -114,7 +114,14 @@ class ScopedHandle {
class Limiter {
public:
// Limit maximum number of resources to |max_acquires|.
- Limiter(int max_acquires) : acquires_allowed_(max_acquires) {}
+ Limiter(int max_acquires)
+ :
+#if !defined(NDEBUG)
+ max_acquires_(max_acquires),
+#endif // !defined(NDEBUG)
+ acquires_allowed_(max_acquires) {
+ assert(max_acquires >= 0);
+ }
Limiter(const Limiter&) = delete;
Limiter operator=(const Limiter&) = delete;
@@ -133,9 +140,22 @@ class Limiter {
// Release a resource acquired by a previous call to Acquire() that returned
// true.
- void Release() { acquires_allowed_.fetch_add(1, std::memory_order_relaxed); }
+ void Release() {
+ int old_acquires_allowed =
+ acquires_allowed_.fetch_add(1, std::memory_order_relaxed);
+
+ // Silence compiler warnings about unused arguments when NDEBUG is defined.
+ (void)old_acquires_allowed;
+ // If the check below fails, Release() was called more times than acquire.
+ assert(old_acquires_allowed < max_acquires_);
+ }
private:
+#if !defined(NDEBUG)
+ // Catches an excessive number of Release() calls.
+ const int max_acquires_;
+#endif // !defined(NDEBUG)
+
// The number of available resources.
//
// This is a counter and is not tied to the invariants of any other class, so
@@ -622,7 +642,7 @@ class WindowsEnv : public Env {
}
Status NewLogger(const std::string& filename, Logger** result) override {
- std::FILE* fp = std::fopen(filename.c_str(), "w");
+ std::FILE* fp = std::fopen(filename.c_str(), "wN");
if (fp == nullptr) {
*result = nullptr;
return WindowsError(filename, ::GetLastError());
@@ -661,7 +681,7 @@ class WindowsEnv : public Env {
// Instances are constructed on the thread calling Schedule() and used on the
// background thread.
//
- // This structure is thread-safe beacuse it is immutable.
+ // This structure is thread-safe because it is immutable.
struct BackgroundWorkItem {
explicit BackgroundWorkItem(void (*function)(void* arg), void* arg)
: function(function), arg(arg) {}
@@ -745,7 +765,7 @@ class SingletonEnv {
public:
SingletonEnv() {
#if !defined(NDEBUG)
- env_initialized_.store(true, std::memory_order::memory_order_relaxed);
+ env_initialized_.store(true, std::memory_order_relaxed);
#endif // !defined(NDEBUG)
static_assert(sizeof(env_storage_) >= sizeof(EnvType),
"env_storage_ will not fit the Env");
@@ -762,7 +782,7 @@ class SingletonEnv {
static void AssertEnvNotInitialized() {
#if !defined(NDEBUG)
- assert(!env_initialized_.load(std::memory_order::memory_order_relaxed));
+ assert(!env_initialized_.load(std::memory_order_relaxed));
#endif // !defined(NDEBUG)
}
diff --git a/util/hash_test.cc b/util/hash_test.cc
index 6d6771f..0ea5977 100644
--- a/util/hash_test.cc
+++ b/util/hash_test.cc
@@ -39,8 +39,3 @@ TEST(HASH, SignedUnsignedIssue) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/logging_test.cc b/util/logging_test.cc
index 24e1fe9..1746c57 100644
--- a/util/logging_test.cc
+++ b/util/logging_test.cc
@@ -138,8 +138,3 @@ TEST(Logging, ConsumeDecimalNumberNoDigits) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/no_destructor_test.cc b/util/no_destructor_test.cc
index 68fdfee..e3602cc 100644
--- a/util/no_destructor_test.cc
+++ b/util/no_destructor_test.cc
@@ -42,8 +42,3 @@ TEST(NoDestructorTest, StaticInstance) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/random.h b/util/random.h
index d7cbdd9..60ca9ed 100644
--- a/util/random.h
+++ b/util/random.h
@@ -57,8 +57,6 @@ class Random {
// range [0,2^max_log-1] with exponential bias towards smaller numbers.
uint32_t Skewed(int max_log) { return Uniform(1 << Uniform(max_log + 1)); }
};
-
-
} // namespace leveldb
#endif // STORAGE_LEVELDB_UTIL_RANDOM_H_
diff --git a/util/status_test.cc b/util/status_test.cc
index 914b386..dbf5faa 100644
--- a/util/status_test.cc
+++ b/util/status_test.cc
@@ -37,8 +37,3 @@ TEST(Status, MoveConstructor) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}