event_t *scheduler_add_callback(uint64_t clock, call_t *c, callback_t callback, void *arg) { event_t *event; if ((scheduler_get_end()) && (clock > scheduler_get_end())) { return NULL; } if ((event = (event_t *) mem_fs_alloc(mem_event)) == NULL) { fprintf(stderr, "scheduler.c: add callback node %d : ERROR when allocating event\n", c->node); return NULL; } event->clock = clock; event->u.cb.call.entity = c->entity; event->u.cb.call.node = c->node; event->u.cb.call.from = c->from; event->u.cb.callback = callback; event->u.cb.arg = arg; event->priority = PRIORITY_CALLBACK; scheduler_add_event(event); /* if worldsens mode save this event as rdv */ if (ws_count) worldsens_add_rdv(clock, PRIORITY_CALLBACK); return event; }
/* ************************************************** */ void print_simulation(void) { fprintf(stderr, "\nSimulation will run using:\n"); fprintf(stderr, " nodes : %d\n", nodes.size); fprintf(stderr, " (x,y,z) : (%lf, %lf, %lf)\n", get_topology_area()->x, get_topology_area()->y, get_topology_area()->z); if (scheduler_get_end()) { fprintf(stderr, " duration : %" PRId64 "ns\n", scheduler_get_end()); } else { fprintf(stderr, " duration : unlimited\n"); } }
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; }
/* 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; }