Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void
- lock_acquire3(struct lock *lockA, struct lock *lockB, struct lock *lockC)
- {
- // Write this
- int splold;
- assert(lockA != NULL);
- assert(lockB != NULL);
- assert(lockC != NULL);
- splold = splhigh();
- while(1)
- {
- // spin while first lock is previously held
- while(*(lockA->status) == 1);
- // status is now 0 (free to acquire)
- if (lock_testAndSet(lockA) == 0)
- {
- // try to get 2nd lock
- if (lock_testAndSet(lockB) == 0 && lock_testAndSet(lockC) == 0)
- {
- // try to get 3rd lock
- if (lock_testAndSet(lockC) == 0)
- {
- // all locks acquired, exit
- break;
- }
- else
- {
- // couldn't get all locks, release A and B
- lock_release(lockA);
- lock_release(lockB);
- }
- }
- else
- {
- // couldn't get both locks, release first
- lock_release(lockA);
- }
- }
- }
- splx(splold);
- // (void)lock; // suppress warning until code gets written
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement