зеркало из https://github.com/github/ruby.git
random.c: refactor
* random.c (fill_random_bytes): separate non-raced and raced conditions, on Windows. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
2c3656f5e8
Коммит
f9c2adf310
15
random.c
15
random.c
|
@ -486,17 +486,16 @@ fill_random_bytes(void *seed, size_t size)
|
||||||
prov = (HCRYPTPROV)INVALID_HANDLE_VALUE;
|
prov = (HCRYPTPROV)INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
old_prov = (HCRYPTPROV)ATOMIC_PTR_CAS(perm_prov, 0, prov);
|
old_prov = (HCRYPTPROV)ATOMIC_PTR_CAS(perm_prov, 0, prov);
|
||||||
if (prov == (HCRYPTPROV)INVALID_HANDLE_VALUE) {
|
if (LIKELY(!old_prov)) { /* no other threads acquried */
|
||||||
if (old_prov) prov = old_prov;
|
if (prov != (HCRYPTPROV)INVALID_HANDLE_VALUE) {
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!old_prov) {
|
|
||||||
rb_gc_register_mark_object(Data_Wrap_Struct(0, 0, release_crypt, &perm_prov));
|
rb_gc_register_mark_object(Data_Wrap_Struct(0, 0, release_crypt, &perm_prov));
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
CryptReleaseContext(prov, 0);
|
|
||||||
prov = old_prov;
|
|
||||||
}
|
}
|
||||||
|
else { /* another thread acquried */
|
||||||
|
if (prov != (HCRYPTPROV)INVALID_HANDLE_VALUE) {
|
||||||
|
CryptReleaseContext(prov, 0);
|
||||||
|
}
|
||||||
|
prov = old_prov;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (prov == (HCRYPTPROV)INVALID_HANDLE_VALUE) return -1;
|
if (prov == (HCRYPTPROV)INVALID_HANDLE_VALUE) return -1;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче