diff options
Diffstat (limited to 'big-little/lib/bakery.c')
-rw-r--r-- | big-little/lib/bakery.c | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/big-little/lib/bakery.c b/big-little/lib/bakery.c index 5ab789e..068ac0d 100644 --- a/big-little/lib/bakery.c +++ b/big-little/lib/bakery.c @@ -18,7 +18,7 @@ * contributors may be used to endorse or promote products * derived from this software without specific prior written * permission. - */ + */ /* * bakery.c: Lamport's Bakery algorithm for spinlock handling @@ -33,39 +33,39 @@ void init_bakery_spinlock(bakery_t * bakery) { - memset(bakery, 0, sizeof(bakery_t)); + memset(bakery, 0, sizeof(bakery_t)); } void get_bakery_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)); - } + /* 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)); + } } void release_bakery_spinlock(unsigned cpuid, bakery_t * bakery) { - bakery->number[cpuid] = 0; + bakery->number[cpuid] = 0; } |