#ifndef LIBRARIES #define LIBRARIES #define _GNU_SOURCE #include ///< For O_* constants * #include #include #include #endif #include ///< For semaphores #define FREE_SEM_NAME "/11777707_free" #define USED_SEM_NAME "/11777707_used" #define MUTEX_NAME "/11777707_mutex" static sem_t *free_sem; static sem_t *used_sem; static sem_t *mutex; 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); if(res == SEM_FAILED) { fprintf(stderr, "ERROR: Failed opening semaphore\n"); exit(EXIT_FAILURE); } return res; } void close_sem(sem_t *sem) { if(sem_close(sem) < 0) { fprintf(stderr, "ERROR: Failed closing semaphore\n"); exit(EXIT_FAILURE); } } void destroy_sem(char *sem_name) { if(sem_unlink(sem_name) < 0) { fprintf(stderr, "ERROR: Failed closing semaphore\n"); exit(EXIT_FAILURE); } }