summaryrefslogtreecommitdiff
path: root/port
diff options
context:
space:
mode:
authorcostan <costan@google.com>2018-09-10 15:38:12 -0700
committerVictor Costan <pwnall@chromium.org>2018-09-10 19:04:59 -0700
commit05709fb43eea34936c9f535edcb74d5e91a0b495 (patch)
tree77ff92928d616b3dd14e0f547de1c19f4a89b63c /port
parentbb88f25115d20a6d73dfb6b16cc298db2f66948b (diff)
downloadleveldb-05709fb43eea34936c9f535edcb74d5e91a0b495.tar.gz
Remove InitOnce from the port API.
This is not an API-breaking change, because it reduces the API that the leveldb embedder must implement. The project will build just fine against ports that still implement InitOnce. C++11 guarantees thread-safe initialization of static variables inside functions. This is a more restricted form of std::call_once or pthread_once_t (e.g., single call site), so the compiler might be able to generate better code [1]. Equally important, having less code in port_example.h makes it easier to port to other platforms. Due to the change above, this CL introduces a new approach for storing the singleton BytewiseComparatorImpl instance returned by BytewiseComparator(). The new approach avoids a dynamic memory allocation, which eliminates the false positive from LeakSanitizer reported in https://github.com/google/leveldb/issues/200 [1] https://stackoverflow.com/a/27206650/ ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=212348004
Diffstat (limited to 'port')
-rw-r--r--port/port_example.h10
-rw-r--r--port/port_stdcxx.h8
2 files changed, 0 insertions, 18 deletions
diff --git a/port/port_example.h b/port/port_example.h
index 88fc9cb..9c648c3 100644
--- a/port/port_example.h
+++ b/port/port_example.h
@@ -62,16 +62,6 @@ class CondVar {
void SignallAll();
};
-// Thread-safe initialization.
-// Used as follows:
-// static port::OnceType init_control = LEVELDB_ONCE_INIT;
-// static void Initializer() { ... do something ...; }
-// ...
-// port::InitOnce(&init_control, &Initializer);
-typedef intptr_t OnceType;
-#define LEVELDB_ONCE_INIT 0
-void InitOnce(port::OnceType*, void (*initializer)());
-
// A type that holds a pointer that can be read or written atomically
// (i.e., without word-tearing.)
class AtomicPointer {
diff --git a/port/port_stdcxx.h b/port/port_stdcxx.h
index 4e58cba..4713e26 100644
--- a/port/port_stdcxx.h
+++ b/port/port_stdcxx.h
@@ -84,14 +84,6 @@ class CondVar {
Mutex* const mu_;
};
-using OnceType = std::once_flag;
-#define LEVELDB_ONCE_INIT {}
-
-// Thinly wraps std::call_once.
-inline void InitOnce(OnceType* once, void (*initializer)()) {
- std::call_once(*once, *initializer);
-}
-
inline bool Snappy_Compress(const char* input, size_t length,
::std::string* output) {
#if HAVE_SNAPPY