std::string Collector::serve_request(std::string req) { Json::Value root; Json::Reader reader; if (reader.parse(req, root, false) == false) { return generate_error("bad_json"); } if (root["status"] == "have_work") { std::cout << "work: " << root["work"] << std::endl; /* Add the pixels to the pixmap. */ process_work(root["work"], root["pixels"]); Json::Value root; root["success"] = true; return json_to_string(root); } else if (root["status"] == "need_work") { /* We want to reduce network slowdown by only sending the scene when necessary. */ return generate_work(root["have_scene"].asBool()); } else { return generate_error("bad_request"); } }
int process_pending() { if(!complete_list) complete_list = list_create(); if(list_size(complete_list) > 0) return 1; return process_work(0); }
struct process_info *process_waitpid( pid_t pid, int timeout) { if(!complete_list) complete_list = list_create(); do { struct process_info *p = list_find( complete_list, pid_compare, &pid ); if(p) return list_remove(complete_list,(void*)p); } while(process_work(timeout)); return 0; }
struct process_info *process_wait(int timeout) { struct process_info *p; if(!complete_list) complete_list = list_create(); p = list_pop_head(complete_list); if(p) return p; process_work(timeout); return list_pop_head(complete_list); }
//----------------------------------------------------------------------------- // rcu_xxxx -- //----------------------------------------------------------------------------- int rcu_xxxx() { // poll threads for quiesce points // rcu_scan(); // check for any work on smr_queue not // in any thread's hazard ptr // smr_scan(); // process ready deferred work // if (ready_queue.tail != NULL) { process_work(); return 1; } else return 0; }
void ShakerSort(int Arr[], int Start, int N, int count_processes, char *nameOfFile) { if(count_processes > N) count_processes = N; //printf("%s\n", nameOfFile); int processes[count_processes]; int pipes[2]; int segment_id; char* shared_memory; struct shmid_ds shmbuffer; int segment_size; pipe(pipes); //------------------------------------ //------------------------------------ segment_id = shmget (IPC_PRIVATE, sizeof(int*) * N, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR); if(segment_id < 0) { perror("Сегмент не был создан\n"); exit(EXIT_FAILURE); } //printf("Создан сегмент : %d\n", segment_id); int* shared_memory_arr = (int*)shmat(segment_id, 0, 0); int j = 0; for(j; j<N; j++) shared_memory_arr[j] = Arr[j]; shmdt(shared_memory_arr); //------------------------------------ //------------------------------------ shmctl (segment_id, IPC_STAT, &shmbuffer); segment_size = shmbuffer.shm_segsz; //printf ("Размер сегмента: %d\n", segment_size); //------------------------------------ //------------------------------------ int semapfore_id = semget(IPC_PRIVATE, 1, 0666|IPC_CREAT); if(semapfore_id == -1) { perror("Семафор не был создан\n"); exit(EXIT_FAILURE); } //printf("Семафор %d\n",semctl(semapfore_id, 0, GETVAL, 0)); //------------------------------------ //------------------------------------ int i = 0; for (i = 0; i<count_processes; i++) { //printf("Создание процесса %d\n", i); if ((processes[i]=fork()) <0) { shmdt (shared_memory_arr); shmctl(segment_id, IPC_RMID, NULL); close(pipes[0]); close(pipes[1]); exit(-1); } else if (processes[i]==0) { process_work(semapfore_id, pipes[0], i, segment_id, nameOfFile, N); exit(0); } } close(pipes[0]); struct sembuf semapfore_operations_lock; semapfore_operations_lock.sem_num = 1; semapfore_operations_lock.sem_flg = 0; semapfore_operations_lock.sem_op = -1; for(i=0;i<2;i++) { int right = N; int left = 0; int isLeft = 0; do { if((isLeft%2) == 0) right--; else left++; semapfore_operations_lock.sem_op--; semop(semapfore_id, &semapfore_operations_lock, 1); AddTask(left, right, pipes[1], isLeft, 0); isLeft++; //printf("\n"); }while(right>=left); } //msleep(100); int status; for (i=0; i<count_processes -1; i++) AddTask(0, 0, pipes[1], 0, 1); AddTask(0, 0, pipes[1], 0, 2); for (i=0; i<count_processes; i++) { AddTask(0, 0, pipes[1], 0, 1); waitpid(processes[i], &status, 0); //printf("Завершение процесса %d\n", i); } close(pipes[1]); /*if((*///shared_memory_arr = (int*)shmat(segment_id, 0, 0);//) < (int*)0) //{ //perror("Сегмент 'arr' не был присоединен\n"); //exit(EXIT_FAILURE); //} //else //{ //rrayOutput(shared_memory_arr, 0, N); //} shmdt(shared_memory_arr); shmctl(segment_id, IPC_RMID, NULL); }