diff --git a/port/port_win.cc b/port/port_win.cc index 7cf953793761b..15dfde1f271f9 100644 --- a/port/port_win.cc +++ b/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/port/port_win.h b/port/port_win.h index c9e1cdad60d05..849b01705fa19 100644 --- a/port/port_win.h +++ b/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