Skip to content

Instantly share code, notes, and snippets.

@sposterkil
Created March 21, 2015 20:27
Show Gist options
  • Save sposterkil/0194b2af94b57ddb4fb3 to your computer and use it in GitHub Desktop.
Save sposterkil/0194b2af94b57ddb4fb3 to your computer and use it in GitHub Desktop.
Semaphore Ops
void olb_wait(int sem_set_id, int semaphore) {
struct sembuf vsembuf = {.sem_op = -1,
.sem_flg = 0,
.sem_num = semaphore};
if (semop(sem_set_id, &vsembuf, 1) < 0) {
perror("Failed to wait on semaphore");
exit(EXIT_FAILURE);
}
}
void olb_signal(int sem_set_id, int semaphore) {
struct sembuf vsembuf = {.sem_op = 1,
.sem_flg = 0,
.sem_num = semaphore};
if (semop(sem_set_id, &vsembuf, 1) < 0) {
perror("Failed to signal semaphore");
exit(EXIT_FAILURE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment