aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-12-12 02:20:18 +0100
committerGavin Andresen <gavinandresen@gmail.com>2013-01-23 10:41:44 -0500
commit960797a0de24454ce0c8c15cbb26cb6fc7683e47 (patch)
treece8c663003e6eaed8cf7385f4523461af275aed5
parent21f2ae7563c8892cbb634ece6911de38dc7dff7c (diff)
Pre-Vista leveldb::port::InitOnce implementation
-rw-r--r--src/leveldb/port/port_win.cc7
-rw-r--r--src/leveldb/port/port_win.h22
2 files changed, 21 insertions, 8 deletions
diff --git a/src/leveldb/port/port_win.cc b/src/leveldb/port/port_win.cc
index 7cf9537937..15dfde1f27 100644
--- a/src/leveldb/port/port_win.cc
+++ b/src/leveldb/port/port_win.cc
@@ -123,13 +123,8 @@ AtomicPointer::AtomicPointer(void* v) {
Release_Store(v);
}
-BOOL CALLBACK InitHandleFunction (PINIT_ONCE InitOnce, PVOID func, PVOID *lpContext) {
- ((void (*)())func)();
- return true;
-}
-
void InitOnce(OnceType* once, void (*initializer)()) {
- InitOnceExecuteOnce((PINIT_ONCE)once, InitHandleFunction, initializer, NULL);
+ once->InitOnce(initializer);
}
void* AtomicPointer::Acquire_Load() const {
diff --git a/src/leveldb/port/port_win.h b/src/leveldb/port/port_win.h
index c9e1cdad60..849b01705f 100644
--- a/src/leveldb/port/port_win.h
+++ b/src/leveldb/port/port_win.h
@@ -93,8 +93,26 @@ class CondVar {
};
-typedef void* OnceType;
-#define LEVELDB_ONCE_INIT 0
+class OnceType {
+public:
+// OnceType() : init_(false) {}
+ OnceType(const OnceType &once) : init_(once.init_) {}
+ OnceType(bool f) : init_(f) {}
+ void InitOnce(void (*initializer)()) {
+ mutex_.Lock();
+ if (!init_) {
+ init_ = true;
+ initializer();
+ }
+ mutex_.Unlock();
+ }
+
+private:
+ bool init_;
+ Mutex mutex_;
+};
+
+#define LEVELDB_ONCE_INIT false
extern void InitOnce(port::OnceType*, void (*initializer)());
// Storage for a lock-free pointer