mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
Do not spin when trying to lock on a single-CPU system.
Reported by: davidxu
This commit is contained in:
parent
cb2394085d
commit
93e34865fa
1 changed files with 12 additions and 10 deletions
|
|
@ -1262,18 +1262,20 @@ malloc_spin_lock(pthread_mutex_t *lock)
|
|||
|
||||
if (__isthreaded) {
|
||||
if (_pthread_mutex_trylock(lock) != 0) {
|
||||
unsigned i;
|
||||
volatile unsigned j;
|
||||
/* Exponentially back off if there are multiple CPUs. */
|
||||
if (ncpus > 1) {
|
||||
unsigned i;
|
||||
volatile unsigned j;
|
||||
|
||||
/* Exponentially back off. */
|
||||
for (i = 1; i <= SPIN_LIMIT_2POW; i++) {
|
||||
for (j = 0; j < (1U << i); j++) {
|
||||
ret++;
|
||||
CPU_SPINWAIT;
|
||||
for (i = 1; i <= SPIN_LIMIT_2POW; i++) {
|
||||
for (j = 0; j < (1U << i); j++) {
|
||||
ret++;
|
||||
CPU_SPINWAIT;
|
||||
}
|
||||
|
||||
if (_pthread_mutex_trylock(lock) == 0)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
if (_pthread_mutex_trylock(lock) == 0)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in a new issue