Skip to content

Instantly share code, notes, and snippets.

@piscisaureus piscisaureus/fubar.c
Created Aug 17, 2011

Embed
What would you like to do?
volatile int uv_initialized = 0;
volatile HANDLE uv_init_event = NULL;
void uv_init() {
HANDLE event, event2;
DWORD result;
if (!uv_initialized) {
event = CreateEvent(NULL, 1, 0, NULL);
assert(event != NULL);
event2 = InterlockedCompareExchangePointer(&uv_init_event, event, NULL);
if (event2 == NULL) {
uv__init();
uv_initialized = 1;
result = SetEvent(event);
assert(result);
} else {
CloseHandle(event);
result = WaitForSingleObject(event2, INFINITE)
assert(result == WAIT_OBJECT_0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.