Created
August 17, 2011 20:14
-
-
Save piscisaureus/1152491 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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