Add shuffler and paramaterize the open_sem function additionally

This commit is contained in:
2019-01-13 14:18:20 +01:00
parent 8c423aaa16
commit 004ee52ae4
3 changed files with 81 additions and 6 deletions

View File

@@ -22,12 +22,21 @@ static sem_t *mutex;
* @brief Function that executes sem_open(3) and does error handling.
* @details The function executes sem_open(3), giving it a semaphor name and size as parameters,
* and handles the errors if any. The same behaviour as sem_open(3) should be expected.
* The type parameter is used to determine how the semaphore should be opened:
* - as a supervisor: 0
* - as a generator: 1
* Returns a new semaphore
* @param sem_name, sem_size
* @param sem_name, sem_size, type
* @return res
**/
sem_t * open_sem(char *sem_name, size_t sem_size) {
sem_t *res = sem_open(sem_name, O_CREAT | O_EXCL, 0600, sem_size);
sem_t * open_sem(char *sem_name, size_t sem_size, short type) {
sem_t *res;
if(type == 0)
res = sem_open(sem_name, O_CREAT | O_EXCL, 0600, sem_size);
else
res = sem_open(sem_name, sem_size);
if(res == SEM_FAILED) {
fprintf(stderr, "ERROR: Failed opening semaphore\n");
exit(EXIT_FAILURE);