summaryrefslogtreecommitdiff
path: root/acsr/c_helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'acsr/c_helpers.c')
-rw-r--r--acsr/c_helpers.c70
1 files changed, 32 insertions, 38 deletions
diff --git a/acsr/c_helpers.c b/acsr/c_helpers.c
index 5d56c12..a7df858 100644
--- a/acsr/c_helpers.c
+++ b/acsr/c_helpers.c
@@ -18,9 +18,8 @@
* contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
- */
-
-
+ */
+
/**
* Lamport's Bakery algorithm for spinlock handling
*
@@ -36,55 +35,50 @@
* Initialize a bakery - only required if the bakery_t is
* on the stack or heap, as static data is zeroed anyway.
*/
-void initialize_spinlock(bakery_t *bakery)
+void initialize_spinlock(bakery_t * bakery)
{
- appf_memset(bakery, 0, sizeof(bakery_t));
+ appf_memset(bakery, 0, sizeof(bakery_t));
}
/**
* Claim a bakery lock. Function does not return until
* lock has been obtained.
*/
-void get_spinlock(unsigned cpuid, bakery_t *bakery)
+void get_spinlock(unsigned cpuid, bakery_t * bakery)
{
- unsigned i, max=0, my_full_number, his_full_number;
+ unsigned i, max = 0, my_full_number, his_full_number;
- /* Get a ticket */
- bakery->entering[cpuid] = TRUE;
- for (i=0; i<MAX_CPUS; ++i)
- {
- if (bakery->number[i] > max)
- {
- max = bakery->number[i];
- }
- }
- ++max;
- bakery->number[cpuid] = max;
- bakery->entering[cpuid] = FALSE;
+ /* Get a ticket */
+ bakery->entering[cpuid] = TRUE;
+ for (i = 0; i < MAX_CPUS; ++i) {
+ if (bakery->number[i] > max) {
+ max = bakery->number[i];
+ }
+ }
+ ++max;
+ bakery->number[cpuid] = max;
+ bakery->entering[cpuid] = FALSE;
- /* Wait for our turn */
- my_full_number = (max << 8) + cpuid;
- for (i=0; i<MAX_CPUS; ++i)
- {
- while(bakery->entering[i]); /* Wait */
- do
- {
- his_full_number = bakery->number[i];
- if (his_full_number)
- {
- his_full_number = (his_full_number << 8) + i;
- }
- }
- while(his_full_number && (his_full_number < my_full_number));
- }
- dmb();
+ /* Wait for our turn */
+ my_full_number = (max << 8) + cpuid;
+ for (i = 0; i < MAX_CPUS; ++i) {
+ while (bakery->entering[i]) ; /* Wait */
+ do {
+ his_full_number = bakery->number[i];
+ if (his_full_number) {
+ his_full_number = (his_full_number << 8) + i;
+ }
+ }
+ while (his_full_number && (his_full_number < my_full_number));
+ }
+ dmb();
}
/**
* Release a bakery lock.
*/
-void release_spinlock(unsigned cpuid, bakery_t *bakery)
+void release_spinlock(unsigned cpuid, bakery_t * bakery)
{
- dmb();
- bakery->number[cpuid] = 0;
+ dmb();
+ bakery->number[cpuid] = 0;
}