Created
March 21, 2015 20:27
-
-
Save sposterkil/0194b2af94b57ddb4fb3 to your computer and use it in GitHub Desktop.
Semaphore Ops
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 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