void spadas_destroy(void *s) { spadas_t *spadas = (spadas_t *) s; int i = 0, j = 0, k = 0; /* remove entries */ for (i = 0; i < spadas->cell_nbr_x; i++) { for (j = 0; j < spadas->cell_nbr_y; j++) { for (k = 0; k < spadas->cell_nbr_z; k++) { spadas_elt_t *elt = spadas->elts[i][j][k]; spadas_elt_t *p_elt = NULL; while (elt != NULL) { p_elt = elt; elt = elt->next; mem_fs_dealloc(mem_spadas_elts, p_elt); } } } } for (i = 0; i < spadas->cell_nbr_x; i++) { for (j = 0; j < spadas->cell_nbr_y; j++) { mem_fs_dealloc(mem_spadas_elts, spadas->elts[i][j]); } mem_fs_dealloc(mem_spadas_elts, spadas->elts[i]); } /* free the data structures */ mem_fs_dealloc(mem_spadas_elts, spadas->elts); mem_fs_dealloc(mem_spadas, spadas); }
void hadas_destroy(void *s) { hadas_t *hadas = (hadas_t *) s; hadas_elt_t *elt; int i; if (hadas != NULL) { for (i = 0; i < HASH_SIZE; i++) { while ((elt = hadas->elts[i]) != NULL) { hadas->elts[i] = elt->next; mem_fs_dealloc(mem_hadas_elts, elt); } } mem_fs_dealloc(mem_hadas, hadas); } }
/* ************************************************** */ void spadas_delete(void *s, void *key, position_t *position) { spadas_t *spadas = (spadas_t *) s; int x = (int) position->x / spadas->cell_width; int y = (int) position->y / spadas->cell_width; int z = (int) position->z / spadas->cell_width; spadas_elt_t *elt = spadas->elts[x][y][z]; while ((elt != NULL) && (elt->key != key)) { elt = elt->next; } if (elt == NULL) { return; } if (elt->previous != NULL) { elt->previous->next = elt->next; } else { spadas->elts[x][y][z] = elt->next; } if (elt->next != NULL) { elt->next->previous = elt->previous; } mem_fs_dealloc(mem_spadas_elts, elt); }
void scheduler_clean(void) { event_t *event; if (scheduler == NULL) { return; } while ((event = (event_t *) sodas_pop(scheduler)) != NULL) { switch (event->priority) { case PRIORITY_RX_END: packet_dealloc(event->u.rx.packet); break; case PRIORITY_RX_BEGIN: packet_dealloc(event->u.rx.packet); break; case PRIORITY_TX_END: packet_dealloc(event->u.rx.packet); break; default: break; } mem_fs_dealloc(mem_event, event); } sodas_destroy(scheduler); worldsens_clean(); }
void hadas_delete(void *h, void *key) { hadas_t *hadas = (hadas_t *) h; unsigned long hash = hadas->hash(key) % HASH_SIZE; hadas_elt_t *elt = hadas->elts[hash], *o_elt = NULL; while (elt != NULL) { if (hadas->equal(elt->key, key)) { /* delete from the begining*/ if (o_elt == NULL) { hadas->elts[hash] = elt->next; if (hadas->elts[hash] != NULL) { hadas->elts[hash]->previous = NULL; } } else { o_elt->next = elt->next; if (elt->next != NULL){ elt->next->previous = o_elt; } } hadas->size--; mem_fs_dealloc(mem_hadas_elts, elt); return; } o_elt = elt; elt = elt->next; } return; }
void das_destroy(void *d) { das_t *das = (das_t *) d; das_elt_t *elt; if (das == NULL) { return; } while ((elt = das->elts) != NULL) { das->elts = elt->next; mem_fs_dealloc(mem_das_elts, elt); das->size--; } mem_fs_dealloc(mem_das, das); return; }
double get_random_z_position(void) { uniform_args_t *args; if ((args = (uniform_args_t *) mem_fs_alloc(mem_rng)) == NULL) { printf("Error: Error while allocating memory for rng. Exiting!\n"); exit(-1); } args->a = 0; args->b = get_topology_area()->z; double result = get_random_double_gsl((void *)DEFAULT_RNG, UNIFORM, args); mem_fs_dealloc(mem_rng, args); return result; }
double get_random_double_range(double min, double max) { uniform_args_t *args; if ((args = (uniform_args_t *) mem_fs_alloc(mem_rng)) == NULL) { printf("Error: Error while allocating memory for rng. Exiting!\n"); exit(-1); } args->a = min; args->b = max; double result = get_random_double_gsl((void *)DEFAULT_RNG, UNIFORM, args); mem_fs_dealloc(mem_rng, args); return result; }
int get_random_integer(void) { uniform_args_t *args; if ((args = (uniform_args_t *) mem_fs_alloc(mem_rng)) == NULL) { printf("Error: Error while allocating memory for rng. Exiting!\n"); exit(-1); } args->a = INT_MIN; args->b = INT_MAX; int result = get_random_integer_gsl((void *)DEFAULT_RNG, UNIFORM, args); mem_fs_dealloc(mem_rng, args); return result; }
nodeid_t get_random_node(nodeid_t exclusion) { uniform_args_t *args; if ((args = (uniform_args_t *) mem_fs_alloc(mem_rng)) == NULL) { printf("Error: Error while allocating memory for rng. Exiting!\n"); exit(-1); } args->a = 0; /* GSL bounds are [min,max[, so we use nodes.size instead of nodes.size-1 */ args->b = nodes.size; int result = get_random_node_gsl((void *)DEFAULT_RNG, UNIFORM, args, exclusion); mem_fs_dealloc(mem_rng, args); return result; }
/* edit by Ibrahim Amadou <*****@*****.**> */ void scheduler_delete_callback(call_t *c, event_t *event) { event_t *event1 = NULL; if((event->clock > get_time()) && (event->clock < scheduler_get_end())) { event1 = (event_t *) sodas_delete(scheduler, event); if(event1 != NULL) { dbg.c_events--; mem_fs_dealloc(mem_event, event1); } return; } return; }
void *das_pop_FIFO(void *d) { das_t *das = (das_t *) d; das_elt_t *elt; void *data; if ((elt = das->elts_end) == NULL) { return NULL; } else if (das->elts_end == das->elts) { data = elt->data; das->elts_end = NULL; das->elts = NULL; das->size--; mem_fs_dealloc(mem_das_elts, elt); return (void *) data; } else { data = elt->data; das->elts_end = das->elts_end->previous; das->elts_end->next = NULL; das->size--; mem_fs_dealloc(mem_das_elts, elt); return (void *) data; } }
uint64_t get_random_time(void) { uniform_args_t *args; if ((args = (uniform_args_t *) mem_fs_alloc(mem_rng)) == NULL) { printf("Error: Error while allocating memory for rng. Exiting!\n"); exit(-1); } args->a = 0; /* GSL bounds are [min,max[, so we use cheduler_get_end()+1 * to provide an integer in the [min,max] range */ args->b = scheduler_get_end() + 1; uint64_t result = get_random_time_gsl((void *)DEFAULT_RNG, UNIFORM, args); mem_fs_dealloc(mem_rng, args); return result; }
int get_random_integer_range(int min, int max) { uniform_args_t *args; if ((args = (uniform_args_t *) mem_fs_alloc(mem_rng)) == NULL) { printf("Error: Error while allocating memory for rng. Exiting!\n"); exit(-1); } args->a = min; /* GSL bounds are [min,max[, so we use max+1 to provide an * integer in the [min,max] range */ args->b = max + 1; int result = get_random_integer_gsl((void *)DEFAULT_RNG, UNIFORM, args); mem_fs_dealloc(mem_rng, args); return result; }
void do_event(event_t *event) { if (ws_count) /* WORLDSENS MODE? */ worldsens_rdv_update(event); switch (event->priority) { case PRIORITY_BIRTH: node_birth(event->u.nodeid); break; case PRIORITY_MOBILITY: mobility_event(g_clock); break; case PRIORITY_RX_BEGIN: medium_cs(event->u.rx.packet, &(event->u.rx.call)); worldsens_rm_duplicate_pk(event); break; case PRIORITY_RX_END: medium_rx(event->u.rx.packet, &(event->u.rx.call)); break; case PRIORITY_TX_END: medium_tx_end(event->u.rx.packet, &(event->u.rx.call)); break; case PRIORITY_CALLBACK: if ((event->u.cb.call.node != -1) && (!is_node_alive(event->u.cb.call.node))) { break; } event->u.cb.callback(&(event->u.cb.call), event->u.cb.arg); break; case PRIORITY_MILESTONE: scheduler_stats(); if (ws_count) { /* WORLDSENS MODE? */ scheduler_add_milestone(g_clock + WORLDSENS_SYNC_PERIOD); } else { scheduler_add_milestone(g_clock + SCHEDULER_MILESTONE_PERIOD); } break; case PRIORITY_QUIT: worldsens_quit(); exception = EXCEPTION_QUIT; break; default: break; } mem_fs_dealloc(mem_event, event); dbg.c_events--; dbg.d_events++; }
static void worldsens_rdv_update(event_t *event) { if ( (event->priority == PRIORITY_QUIT) || (event->priority == PRIORITY_RX_BEGIN) || (event->priority == PRIORITY_RX_END) || (event->priority == PRIORITY_CALLBACK) || (event->priority == PRIORITY_MILESTONE) ) { ws_rdv_t *rdv; rdv = worldsens_rdv_next(); if (rdv->clock != event->clock) { WSNET_S_DBG_DBG ("WSNET2:: === ==================================================\n"); WSNET_S_DBG_DBG ("WSNET2:: === ERROR: CORE DESYNCHRONIZATION, RDV TIME %"PRId64" != EVENT TIME %"PRId64" (rp seq: %"PRId64")\n", rdv->clock, event->clock, ws_csyncseq); WSNET_S_DBG_DBG ("WSNET2:: === ==================================================\n"); } worldsens_event_dump(event); mem_fs_dealloc(mem_ws_rdv, rdv); } }
static void worldsens_clean(void) { if (ws_count) { wsens_srv_finalize(); /* free node informations space */ ws_node_features_t *p_temp = ws_nodes_feat; ws_node_features_t *p_free = NULL; while(p_temp != NULL) { p_free = p_temp; p_temp = p_temp->next; free(p_free); } /* free rdvs */ ws_rdv_t *rdv; while ((rdv = (ws_rdv_t *) sodas_pop(ws_rdvs)) != NULL) { mem_fs_dealloc(mem_ws_rdv, rdv); } } }
/* ************************************************** */ static void worldsens_rm_duplicate_pk(event_t *event) { if (ws_count) { event_t *next_event = scheduler_see_next(); /* A packet sent by a node has the same id for each receiving nodes. So if we find a packet with same source node, same clock and differents ids, it is a duplicated packet (because of a backtrack) and we have to skip it. */ while(next_event->priority == PRIORITY_RX_BEGIN && next_event->u.rx.packet->node == event->u.rx.packet->node && next_event->u.rx.packet->clock0 == event->u.rx.packet->clock0 && next_event->u.rx.packet->id != event->u.rx.packet->id) { /* get out of the fifo the duplicated packet */ event_t *trash_event = scheduler_next(); worldsens_rdv_update(trash_event); WSNET_S_DBG_DBG("WSNET2:: --> RX BEGIN: same packet found in fifo, skip it (src ip:%d, data:0x%02x, freq:%ghz, wsim modul:%d)\n", worldsens_get_wsim_node_id(next_event->u.rx.packet->node), *(next_event->u.rx.packet->data), next_event->u.rx.packet->worldsens_freq, next_event->u.rx.packet->worldsens_mod); mem_fs_dealloc(mem_event, trash_event); dbg.c_events--; next_event = scheduler_see_next(); } } }
void das_delete(void *d, void *data) { das_t *das = (das_t *) d; das_elt_t *elt = das->elts, *o_elt = NULL; while (elt != NULL) { if (elt->data == data) { /* delete from the begining*/ if (o_elt == NULL) { das->elts = elt->next; if (das->elts != NULL) { das->elts->previous = NULL; } else { das->elts_end = NULL; } } else if (elt == das->elts_end) { das->elts_end = das->elts_end->previous; das->elts_end->next = NULL; } else { o_elt->next = elt->next; if (elt->next != NULL){ elt->next->previous = o_elt; } } das->size--; free(elt->data); mem_fs_dealloc(mem_das_elts, elt); return; } o_elt = elt; elt = elt->next; } return; }
void sodas_destroy(void *s) { sodas_t *sodas = (sodas_t *) s; free(sodas->elts); mem_fs_dealloc(mem_sodas, sodas); }