Created
May 2, 2013 23:08
-
-
Save gfmurphy/5506156 to your computer and use it in GitHub Desktop.
Mesa style wait and signal algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Condition_H::Wait() { | |
IntStatus oldLevel = interrupt->SetLevel(IntOff); | |
count++; | |
if (mon->next_count > 0) { | |
mon->next->V(); | |
mon->next_count--; | |
} | |
else mon->mutex->V(); | |
sem->P(); | |
count--; | |
(void) interrupt->SetLevel(oldLevel); | |
} | |
void Condition_H::Signal() { | |
IntStatus oldLevel = interrupt->SetLevel(IntOff); | |
if (count > 0) { | |
mon->next_count++; | |
sem->V(); | |
mon->next->P(); | |
mon->next_count--; | |
} | |
(void) interrupt->SetLevel(oldLevel); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment