/* * This function will return the list of the names of relations in the * under the specified section name. */ errcode_t profile_get_relation_names(profile_t profile, const char **names, char ***ret_names) { errcode_t retval; void *state; char *name; struct profile_string_list values; if ((retval = profile_iterator_create(profile, names, PROFILE_ITER_LIST_SECTION | PROFILE_ITER_RELATIONS_ONLY, &state))) return retval; if ((retval = init_list(&values))) return retval; do { if ((retval = profile_iterator(&state, &name, 0))) goto cleanup; if (name) { if (is_list_member(&values, name)) free(name); else add_to_list(&values, name); } } while (state); end_list(&values, ret_names); return 0; cleanup: end_list(&values, 0); return retval; }
void check_first_prio(t_tree **list) { t_tree *ptr; t_tree *tmp; int n; ptr = end_list(list); tmp = NULL; n = END; while (ptr) { if (ptr->type == AND || ptr->type == OR) { n = ptr->type; tmp = ptr; tmp->prio = 1; return; } else if (ptr->type < n) { n = ptr->type; tmp = ptr; } ptr = ptr->left; } if (tmp != NULL) tmp->prio = 1; }
void sem_pend(sem_struct *sem) { cpu_sr_t cpu_sr; list_node_t *pnode; thread_struct *pthread; cpu_sr = save_cpu_sr(); if (sem->value == 0) { if (!is_empty_list(&sem->wait_list)) { for (pnode = begin_list(&sem->wait_list); pnode != end_list(&sem->wait_list); pnode = next_list(pnode)) { pthread = entry_list(pnode, thread_struct, node); if (current_thread->prio < pthread->prio) { current_thread->state = EVENT_WAIT; insert_before_list( pnode, ¤t_thread->node); break; } } } if (current_thread->state != EVENT_WAIT) { current_thread->state = EVENT_WAIT; insert_back_list(&sem->wait_list, ¤t_thread->node); } schedule(SCHED_THREAD_REQUEST); return; } sem->value--; restore_cpu_sr(cpu_sr); }
void ftp_list(t_client *client, char *str) { FILE *fd; int client_fd; struct sockaddr_in cliaddr; socklen_t clilen; char *arg; char buff[4096]; arg = get_cmd(str, 4); if (!is_passive(client)) return; clilen = sizeof(cliaddr); if (!is_authorized_path(client, arg)) return (bad_path(client)); client_fd = accept(client->pasv_sck, (struct sockaddr *)&cliaddr, &clilen); write(client->fd, "150 Accepted data connection\r\n", strlen("150 Accepted data connection\r\n")); sprintf(buff, "ls -la %s > /tmp/.result", arg); system(buff); if (!(fd = fopen("/tmp/.result", "r"))) return (cond_is_ok(client, client_fd)); end_list(client, fd, client_fd); }
// // skelet_condition // Prend en argument deux compteurs, // la liste chaînée contenant les labels et un pointeur sur cette liste // Renvoie 0 si tous les pixels contours sont multiples, 1 sinon // int skelet_condition(int cpt_border,int cpt_mult,t_plist list_copy, t_plist* img_label_list){ // Vérification de la condition de d'arrêt de l'algorithme list_copy=(*img_label_list); while(list_copy!=NULL){ if(list_copy->v_pixel.obj.mult==2) cpt_mult++; cpt_border++; list_copy=end_list(list_copy); } printf("%d mult et %d contours à cette itération\n",cpt_mult,cpt_border); if(cpt_border==cpt_mult) return 0; else return 1; }
errcode_t profile_get_values(profile_t profile, const char *const *names, char ***ret_values) { errcode_t retval; void *state; char *value; struct profile_string_list values; if ((retval = profile_iterator_create(profile, names, PROFILE_ITER_RELATIONS_ONLY, &state))) return retval; if ((retval = init_list(&values))) return retval; do { if ((retval = profile_iterator(&state, 0, &value))) goto cleanup; if (value) add_to_list(&values, value); } while (state); if (values.num == 0) { retval = PROF_NO_RELATION; goto cleanup; } end_list(&values, ret_values); return 0; cleanup: end_list(&values, 0); return retval; }
/** * @brief time tick advanced * Maintain time_quantum */ void advance_time_tick() { cpu_sr_t cpu_sr; list_node_t *pnode; thread_struct *pthread; thread_struct *readyed_thread = NULL; cpu_sr = save_cpu_sr(); os_time_tick++; /* If there are delays in the list of threads... */ if (!is_empty_list(&delayed_list)) { for (pnode = begin_list(&delayed_list); pnode != end_list(&delayed_list); pnode = next_list(pnode) ) { pthread = entry_list(pnode, thread_struct, node); pthread->delayed_time--; /* ready to change the status */ if (readyed_thread != NULL) { delete_list(&readyed_thread->node); readyed_thread->state = READY; readyed_thread->time_quantum = TIME_QUANTUM; insert_back_list( &ready_list[readyed_thread->prio], &readyed_thread->node); prio_exist_flag[readyed_thread->prio] = true; readyed_thread = NULL; } if (pthread->delayed_time <= 0) { readyed_thread = pthread; } } if (readyed_thread != NULL) { delete_list(&readyed_thread->node); readyed_thread->state = READY; readyed_thread->time_quantum = TIME_QUANTUM; insert_back_list( &ready_list[readyed_thread->prio], &readyed_thread->node); prio_exist_flag[readyed_thread->prio] = true; } } current_thread->time_quantum--; restore_cpu_sr(cpu_sr); }
void insert_back_list(list_t *plist, list_node_t *pnode) { insert_after_list(end_list(plist), pnode); }
bool is_empty_list(list_t *plist) { return (begin_list(plist) == end_list(plist)); }