From 8a8c8303d12188df2bb0578af31c18c7746f067b Mon Sep 17 00:00:00 2001 From: dnflekals <dnflekals@DESKTOP-MFES181.localdomain> Date: Thu, 4 Jun 2020 14:34:17 +0900 Subject: [PATCH] finish spinlock --- pa3.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pa3.c b/pa3.c index 634dd81..bf77e96 100644 --- a/pa3.c +++ b/pa3.c @@ -33,7 +33,7 @@ * Spinlock implementation *********************************************************************/ struct spinlock { - + int held; }; /********************************************************************* @@ -44,6 +44,7 @@ struct spinlock { */ void init_spinlock(struct spinlock *lock) { + lock->held=0; return; } @@ -58,6 +59,8 @@ void init_spinlock(struct spinlock *lock) */ void acquire_spinlock(struct spinlock *lock) { + while(lock->held); + lock->held=1; return; } @@ -72,6 +75,7 @@ void acquire_spinlock(struct spinlock *lock) */ void release_spinlock(struct spinlock *lock) { + lock->held = 0; return; } -- GitLab