clang-format
This commit is contained in:
@@ -32,12 +32,11 @@
|
||||
|
||||
#include <cdefs.h>
|
||||
|
||||
|
||||
/* Type of value needed to actually spin on */
|
||||
typedef unsigned spinlock_data_t;
|
||||
|
||||
/* Initializer for use by SPINLOCK_INITIALIZER */
|
||||
#define SPINLOCK_DATA_INITIALIZER 0
|
||||
#define SPINLOCK_DATA_INITIALIZER 0
|
||||
|
||||
/* Atomic operations on spinlock_data_t */
|
||||
SPINLOCK_INLINE
|
||||
@@ -55,10 +54,8 @@ spinlock_data_t spinlock_data_testandset(volatile spinlock_data_t *sd);
|
||||
* memory.
|
||||
*/
|
||||
SPINLOCK_INLINE
|
||||
void
|
||||
spinlock_data_set(volatile spinlock_data_t *sd, unsigned val)
|
||||
{
|
||||
*sd = val;
|
||||
void spinlock_data_set(volatile spinlock_data_t *sd, unsigned val) {
|
||||
*sd = val;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -66,11 +63,7 @@ spinlock_data_set(volatile spinlock_data_t *sd, unsigned val)
|
||||
* instruction, and instructions are atomic with respect to memory.
|
||||
*/
|
||||
SPINLOCK_INLINE
|
||||
spinlock_data_t
|
||||
spinlock_data_get(volatile spinlock_data_t *sd)
|
||||
{
|
||||
return *sd;
|
||||
}
|
||||
spinlock_data_t spinlock_data_get(volatile spinlock_data_t *sd) { return *sd; }
|
||||
|
||||
/*
|
||||
* Test-and-set a spinlock_data_t. Use the LL/SC instructions to
|
||||
@@ -86,37 +79,34 @@ spinlock_data_get(volatile spinlock_data_t *sd)
|
||||
* to atomically update one machine word.
|
||||
*/
|
||||
SPINLOCK_INLINE
|
||||
spinlock_data_t
|
||||
spinlock_data_testandset(volatile spinlock_data_t *sd)
|
||||
{
|
||||
spinlock_data_t x;
|
||||
spinlock_data_t y;
|
||||
spinlock_data_t spinlock_data_testandset(volatile spinlock_data_t *sd) {
|
||||
spinlock_data_t x;
|
||||
spinlock_data_t y;
|
||||
|
||||
/*
|
||||
* Test-and-set using LL/SC.
|
||||
*
|
||||
* Load the existing value into X, and use Y to store 1.
|
||||
* After the SC, Y contains 1 if the store succeeded,
|
||||
* 0 if it failed.
|
||||
*
|
||||
* On failure, return 1 to pretend that the spinlock
|
||||
* was already held.
|
||||
*/
|
||||
/*
|
||||
* Test-and-set using LL/SC.
|
||||
*
|
||||
* Load the existing value into X, and use Y to store 1.
|
||||
* After the SC, Y contains 1 if the store succeeded,
|
||||
* 0 if it failed.
|
||||
*
|
||||
* On failure, return 1 to pretend that the spinlock
|
||||
* was already held.
|
||||
*/
|
||||
|
||||
y = 1;
|
||||
__asm volatile(
|
||||
".set push;" /* save assembler mode */
|
||||
".set mips32;" /* allow MIPS32 instructions */
|
||||
".set volatile;" /* avoid unwanted optimization */
|
||||
"ll %0, 0(%2);" /* x = *sd */
|
||||
"sc %1, 0(%2);" /* *sd = y; y = success? */
|
||||
".set pop" /* restore assembler mode */
|
||||
: "=&r" (x), "+r" (y) : "r" (sd));
|
||||
if (y == 0) {
|
||||
return 1;
|
||||
}
|
||||
return x;
|
||||
y = 1;
|
||||
__asm volatile(".set push;" /* save assembler mode */
|
||||
".set mips32;" /* allow MIPS32 instructions */
|
||||
".set volatile;" /* avoid unwanted optimization */
|
||||
"ll %0, 0(%2);" /* x = *sd */
|
||||
"sc %1, 0(%2);" /* *sd = y; y = success? */
|
||||
".set pop" /* restore assembler mode */
|
||||
: "=&r"(x), "+r"(y)
|
||||
: "r"(sd));
|
||||
if (y == 0) {
|
||||
return 1;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
#endif /* _MIPS_SPINLOCK_H_ */
|
||||
|
||||
Reference in New Issue
Block a user