Skip to content

Commit

Permalink
Pre-Vista leveldb::port::InitOnce implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Aug 17, 2013
1 parent 31a2b09 commit 0a7b074
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
7 changes: 1 addition & 6 deletions port/port_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 20 additions & 2 deletions port/port_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0a7b074

Please sign in to comment.