8234509: Race in macOS os::processor_id()

Reviewed-by: dholmes, pliden, rehn
This commit is contained in:
Erik Österlund 2019-11-25 09:10:41 +00:00
parent 48615b4ca9
commit f4fced0e24

View File

@ -3264,12 +3264,14 @@ uint os::processor_id() {
int processor_id = Atomic::load(&mapping[apic_id]);
while (processor_id < 0) {
if (Atomic::cmpxchg(-2, &mapping[apic_id], -1)) {
if (Atomic::cmpxchg(-2, &mapping[apic_id], -1) == -1) {
Atomic::store(Atomic::add(1, &next_processor_id) - 1, &mapping[apic_id]);
}
processor_id = Atomic::load(&mapping[apic_id]);
}
assert(processor_id >= 0 && processor_id < os::processor_count(), "invalid processor id");
return (uint)processor_id;
}
#endif