Skip to content

Instantly share code, notes, and snippets.

@gfmurphy
Created May 2, 2013 23:08
Show Gist options
  • Save gfmurphy/5506156 to your computer and use it in GitHub Desktop.
Save gfmurphy/5506156 to your computer and use it in GitHub Desktop.
Mesa style wait and signal algorithm
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