1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Make vm_exit_handler installation MT-safe

This commit is contained in:
Nobuyoshi Nakada 2021-02-23 21:30:54 +09:00
parent 9299703b39
commit b7d4dcf3a6
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6

View file

@ -781,15 +781,23 @@ vm_exit_handler(ruby_vm_t *vm)
LeaveCriticalSection(&conlist_mutex);
}
#define ATOMIC_LONG_CAS(var, oldval, newval) InterlockedCompareExchange(&(var), (newval), (oldval))
/* License: Ruby's */
static void
install_vm_exit_handler(void)
{
static bool installed = 0;
static LONG installed = 0;
LONG i;
if (!installed) {
while ((i = ATOMIC_LONG_CAS(installed, 0, -1)) != 1) {
if (i != 0) {
Sleep(1);
continue;
}
ruby_vm_at_exit(vm_exit_handler);
installed = 1;
ATOMIC_LONG_CAS(installed, -1, 1);
break;
}
}