void * run_program(void * program_stat) { graph_t c_graph; int memkey, i; status client_program; process_t process_type; mstack_t instruction_stack; thread_status_t thread_info = (thread_status_t)program_stat; instruction_stack = parse_file((char*)thread_info->file); if (instruction_stack != NULL){ c_graph = build_graph(instruction_stack); if (c_graph != NULL) { create_sh_graph(c_graph, get_graph_size(c_graph), &memkey, &client_program.g_header); client_program.cursor = 0; client_program.flag = FALSE; client_program.client_id = thread_info->client_id; for(i = 0; i < MEM_SIZE; i++){ client_program.mem[i] = 0; } process_type = c_graph->first->instruction_process->instruction_type; client_program.mtype = process_type->params->unique_mq_id; free_graph(c_graph); free_stack(instruction_stack); printf("Sending first instruction...\n"); ipc_send(process_type->params, &client_program, sizeof(struct status)); }else{ answer_error_to_client(UNABLE_TO_BUILD_GRAPH, thread_info->client_id); } }else{ answer_error_to_client(errno, thread_info->client_id); errno = 0; } pthread_exit(NULL); }
void * run_program(void * program_stat) { ipc_params_t client_params; stack_t c_stack; graph_t c_graph; int memkey, i; status client_program; process_t process_type; thread_status_t thread_info = (thread_status_t)program_stat; c_stack = parse_file((char*)thread_info->file); c_graph = build_graph(c_stack); if (c_graph != NULL) { create_sh_graph(c_graph, get_graph_size(c_graph), &memkey, &client_program.g_header); client_program.cursor = 0; client_program.flag = FALSE; for(i = 0; i < MEM_SIZE; i++) { client_program.mem[i] = 0; } process_type = c_graph->first->instruction_process->instruction_type; client_program.mtype = process_type->params->unique_mq_id; ipc_send(process_type->params, &client_program, sizeof(struct status)); } else { printf("Entrada incorrecta\n"); } while(!ipc_receive(server_receive_params, &client_program, sizeof(struct status))) sleep(1); client_params = get_params_from_pid(thread_info->client_id, PROGRAM_STATUS, sizeof(struct status)); ipc_open(client_params, O_WRONLY); ipc_send(client_params, &client_program, sizeof(struct status)); ipc_close(client_params); }