Reindent of server/core/spinlock.c

This commit is contained in:
Johan Wikman
2015-11-30 20:12:58 +02:00
parent 15df33a93f
commit a95be21266
2 changed files with 55 additions and 48 deletions

View File

@ -22,8 +22,8 @@
* @verbatim
* Revision History
*
* Date Who Description
* 10/06/13 Mark Riddoch Initial implementation
* Date Who Description
* 10/06/13 Mark Riddoch Initial implementation
*
* @endverbatim
*/
@ -59,30 +59,32 @@ void
spinlock_acquire(SPINLOCK *lock)
{
#if SPINLOCK_PROFILE
int spins = 0;
int spins = 0;
atomic_add(&(lock->waiting), 1);
atomic_add(&(lock->waiting), 1);
#endif
#ifdef __GNUC__
while (__sync_lock_test_and_set(&(lock->lock), 1))
while (lock->lock) {
#else
#else
while (atomic_add(&(lock->lock), 1) != 0)
{
atomic_add(&(lock->lock), -1);
atomic_add(&(lock->lock), -1);
#endif
#if SPINLOCK_PROFILE
atomic_add(&(lock->spins), 1);
spins++;
atomic_add(&(lock->spins), 1);
spins++;
#endif
}
}
#if SPINLOCK_PROFILE
if (spins)
{
lock->contended++;
if (lock->maxspins < spins)
{
lock->maxspins = spins;
}
}
lock->acquired++;
lock->owner = THREAD_SHELF();
@ -125,7 +127,9 @@ spinlock_release(SPINLOCK *lock)
{
#if SPINLOCK_PROFILE
if (lock->waiting > lock->max_waiting)
{
lock->max_waiting = lock->waiting;
}
#endif
#ifdef __GNUC__
__sync_synchronize(); /* Memory barrier. */
@ -144,29 +148,31 @@ spinlock_release(SPINLOCK *lock)
* form the spinlock code and also to facilitate other uses of the
* statistics reporting.
*
* @param lock The spinlock to report on
* @param reporter The callback function to pass the statistics to
* @param hdl A handle that is passed to the reporter function
* @param lock The spinlock to report on
* @param reporter The callback function to pass the statistics to
* @param hdl A handle that is passed to the reporter function
*/
void
spinlock_stats(SPINLOCK *lock, void (*reporter)(void *, char *, int), void *hdl)
{
#if SPINLOCK_PROFILE
reporter(hdl, "Spinlock acquired", lock->acquired);
if (lock->acquired)
{
reporter(hdl, "Total no. of spins", lock->spins);
reporter(hdl, "Average no. of spins (overall)",
lock->spins / lock->acquired);
if (lock->contended)
reporter(hdl, "Average no. of spins (when contended)",
lock->spins / lock->contended);
reporter(hdl, "Maximum no. of spins", lock->maxspins);
reporter(hdl, "Maximim no. of blocked threads",
lock->max_waiting);
reporter(hdl, "Contended locks", lock->contended);
reporter(hdl, "Contention percentage",
(lock->contended * 100) / lock->acquired);
}
reporter(hdl, "Spinlock acquired", lock->acquired);
if (lock->acquired)
{
reporter(hdl, "Total no. of spins", lock->spins);
reporter(hdl, "Average no. of spins (overall)",
lock->spins / lock->acquired);
if (lock->contended)
{
reporter(hdl, "Average no. of spins (when contended)",
lock->spins / lock->contended);
}
reporter(hdl, "Maximum no. of spins", lock->maxspins);
reporter(hdl, "Maximim no. of blocked threads",
lock->max_waiting);
reporter(hdl, "Contended locks", lock->contended);
reporter(hdl, "Contention percentage",
(lock->contended * 100) / lock->acquired);
}
#endif
}