Skip to content

Instantly share code, notes, and snippets.

@piscisaureus
Created August 17, 2011 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piscisaureus/1152491 to your computer and use it in GitHub Desktop.
Save piscisaureus/1152491 to your computer and use it in GitHub Desktop.
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