void tlist_uninit(tlist_t *tlist) { for (int i = 0; i < tlist->num; i++) { track_free(tlist->tracks[i]); } free(tlist->tracks); tlist_init(tlist); }
int main(int argc, char *argv[]) { struct tlist_children children; struct tlist_cousins cousins; struct child child = { "child" }; struct cousin cousin = { "cousin" }; tlist_init(&children); tlist_init(&cousins); tlist_add(&children, &child, list); tlist_add(&cousins, &cousin, list); tlist_del_from(&cousins, &cousin, list); #ifdef FAIL #if !HAVE_FLEXIBLE_ARRAY_MEMBER #error Need flexible array members to check type #endif tlist_add_tail(&children, &cousin, list); #endif return 0; }
int main(int argc, char *argv[]) { struct tlist_children children; struct child child = { "child" }; #ifdef FAIL #if !HAVE_FLEXIBLE_ARRAY_MEMBER #error Need flexible array members to check type #endif struct cousin *p; #else struct child *p; #endif tlist_init(&children); tlist_add(&children, &child, list); p = tlist_next(&children, &child, list); (void) p; return 0; }
int main(int argc, char *argv[]) { struct tlist_children children; struct child child = { "child" }; #ifdef FAIL #if !HAVE_FLEXIBLE_ARRAY_MEMBER #error Need flexible array members to check type #endif struct cousin *c; #else struct child *c; #endif tlist_init(&children); tlist_add(&children, &child, list); tlist_for_each(&children, c, list) (void) c; /* Suppress unused-but-set-variable warning. */ return 0; }
struct lbalance *lbalance_new(void) { struct lbalance *lb = malloc(sizeof *lb); if (!lb) return NULL; tlist_init(&lb->tasks); lb->num_tasks = 0; gettimeofday(&lb->prev_tasks_time, NULL); lb->tasks_sum = 0.0; getrusage(RUSAGE_CHILDREN, &lb->prev_usage); lb->max_stats = 1; lb->stats = malloc(sizeof(lb->stats[0]) * lb->max_stats); if (!lb->stats) { free(lb); return NULL; } lb->stats[0].num_stats = 0; lb->stats[0].work_rate = 0.0; lb->total_stats = 0; /* Start with # CPUS as a guess. */ lb->target = -1L; #ifdef _SC_NPROCESSORS_ONLN lb->target = sysconf(_SC_NPROCESSORS_ONLN); #elif defined(_SC_NPROCESSORS_CONF) if (lb->target == (unsigned int)-1L) lb->target = sysconf(_SC_NPROCESSORS_CONF); #endif /* Otherwise, two is a good number. */ if (lb->target == (unsigned int)-1L || lb->target < 2) lb->target = 2; lb->target_uptodate = true; return lb; }
void dgraph_init_node(struct dgraph_node *n) { tlist_init(&n->edge[DGRAPH_FROM]); tlist_init(&n->edge[DGRAPH_TO]); }