1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-26 16:18:31 +00:00

Do not spin when trying to lock on a single-CPU system.

Reported by:	davidxu
This commit is contained in:
Jason Evans 2008-11-30 05:55:24 +00:00
parent cb2394085d
commit 93e34865fa
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=185468

View File

@ -1262,10 +1262,11 @@ malloc_spin_lock(pthread_mutex_t *lock)
if (__isthreaded) {
if (_pthread_mutex_trylock(lock) != 0) {
/* 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++;
@ -1275,6 +1276,7 @@ malloc_spin_lock(pthread_mutex_t *lock)
if (_pthread_mutex_trylock(lock) == 0)
return (ret);
}
}
/*
* Spinning failed. Block until the lock becomes