static int createBinarySemaphore(key_t sem_key, int shm_id) { union semun sem_conf; int sem_id = semget(sem_key, NUM_OF_SEMAPHORES, IPC_CREAT|ALLOW_READ_WRITE_TO_ALL); if(sem_id < 0) { deleteFifo(); deleteSharedMemory(shm_id); // No checking needed, exits with error code. write(STDERR_FILENO, SEMGET_ERROR, sizeof(SEMGET_ERROR)); exit(EXIT_ERROR_CODE); } sem_conf.val = SEM_INIT; if(semctl(sem_id, 0, SETVAL, sem_conf) < 0) { deleteFifo(); deleteResources(shm_id, sem_id); // No checking needed, exits with error code. write(STDERR_FILENO, SEMCTL_ERROR, sizeof(SEMCTL_ERROR)); exit(EXIT_ERROR_CODE); } return sem_id; }
void OpenGLContext::makeCurrent(bool current) { m_impl->makeCurrent(current); if (current) deleteResources(); }
bool RadialBlur::createResources() { /* Delete old shader */ deleteResources(); /* Create new resources */ if (!compileShaders()) { io::Log::error("Compiling shaders for radial-blur failed"); deleteResources(); return false; } /* Validate effect */ Valid_ = true; return true; }
OpenGLContext::~OpenGLContext() { m_impl->makeCurrent(true); invalidate(); deleteResources(); delete m_impl; }
void endSafe() { int i; fprintf(stderr,"Waiting for working threads\n"); server.error = 1; for (i = 0; i < res.K; ++i) { pthread_cond_broadcast(&res.resources[i].waitForResources); pthread_cond_broadcast(&res.resources[i].waitForPair); pthread_cond_broadcast(&res.resources[i].waitInQueue); } waitForWorking(); fprintf(stderr, "All threads finished\n"); deleteResources(); closeIPC(); }
static void semUnlock(int sem_id, int shm_id) { struct sembuf sem_opt; sem_opt.sem_num = 0; sem_opt.sem_flg = 0; // Unlock! sem_opt.sem_op = 1; if(semop(sem_id, &sem_opt, NUM_OF_SEMAPHORES) < 0) { deleteResources(shm_id, sem_id); // No checking needed, exits with error code. write(STDERR_FILENO, SEMOP_ERROR, sizeof(SEMOP_ERROR)); exit(EXIT_ERROR_CODE); } }
RadialBlur::~RadialBlur() { deleteResources(); }
Program::~Program() { deleteResources(); }
int main(int argc, char *argv[]) { const unsigned int EXPECTED_ARGC = 2; const unsigned int KEY_FILE_ARG_INDEX = 1; const unsigned char KEY_CHAR = 'H'; const char ENDLINE[] = "\n"; const char SEPERATOR[] = ","; key_t key = 0; char *shm_addr = NULL; int csv_fd = 0, queue_length = 0, shm_id = 0, sem_id = 0; int job_number = 0, rel_prio = 0, real_prio = 0; initSigactions(); // Initialize the rand() seed. srand(time(NULL)); if(argc != EXPECTED_ARGC) { // No checking needed, exits with error code. write(STDERR_FILENO, NOF_INPUTS_ERROR, sizeof(NOF_INPUTS_ERROR)); exit(EXIT_ERROR_CODE); } // Create fifo. if(mkfifo(FIFO_NAME, ALLOW_READ_WRITE_TO_ALL) < 0) { // No checking needed, exits with error code. write(STDERR_FILENO, MKFIFO_ERROR, sizeof(MKFIFO_ERROR)); exit(EXIT_ERROR_CODE); } writePidToFifo(); // Wait for the queue process' singal. waitForSignal(); printf("got signal from %d!\n", Queue_Pid); // Generate key from the given file key = ftok(argv[KEY_FILE_ARG_INDEX], KEY_CHAR); if(key < 0) { deleteFifo(); // No checking needed, exits with error code. write(STDERR_FILENO, FTOK_ERROR, sizeof(FTOK_ERROR)); exit(EXIT_ERROR_CODE); } // Create shared memory. shm_addr = createSharedMemory(key, &shm_id); // Create semaphore. sem_id = createBinarySemaphore(key, shm_id); // Notify the queue.out process. if(kill(Queue_Pid, SIGUSR1) < 0) { deleteFifo(); // No checking needed, exits with error code. write(STDERR_FILENO, KILL_ERROR, sizeof(KILL_ERROR) - 1); exit(EXIT_ERROR_CODE); } queue_length = readQueueLengthFromFifo(); printf("Got N: %d\n", queue_length); // Done using the fifo - delete it. deleteFifo(); // Game Started! handleGame(shm_id, shm_addr, sem_id, queue_length, &job_number, \ &rel_prio, &real_prio); deleteResources(shm_id, sem_id); // Write results csv_fd = open(CSV_FILE_PATH, O_CREAT | O_APPEND | O_RDWR, ALLOW_READ_WRITE_TO_ALL); if(csv_fd < 0) { // No checking needed, exits with error code. write(STDERR_FILENO, OPEN_ERROR, sizeof(OPEN_ERROR) - 1); exit(EXIT_ERROR_CODE); } writeIntWithEnding(csv_fd, queue_length, SEPERATOR); writeIntWithEnding(csv_fd, job_number, SEPERATOR); writeIntWithEnding(csv_fd, rel_prio, SEPERATOR); writeIntWithEnding(csv_fd, real_prio, ENDLINE); return EXIT_OK_CODE; }
void OpenGLContext::deleteFBO(unsigned fboId) { m_deletedFbos.push_back(fboId); deleteResources(); }
void OpenGLContext::deleteVAO(unsigned vaoId) { m_deletedVaos.push_back(vaoId); deleteResources(); }