static struct meta_lock *lock_alloc(spdid_t spd) { struct meta_lock *l; struct meta_lock *snd, *lst; l = (struct meta_lock*)malloc(sizeof(struct meta_lock)); if (!l) return NULL; l->b_thds.thd_id = 0; INIT_LIST(&(l->b_thds), next, prev); /* FIXME: check for lock_id overflow */ l->lock_id = lock_id++; l->owner = 0; l->gen_num = 0; l->spd = spd; INIT_LIST(l, next, prev); assert(&locks != l); snd = FIRST_LIST(&locks, next, prev); lst = LAST_LIST(&locks, next, prev); (l)->next = (&locks)->next; (l)->prev = (&locks); (&locks)->next = (l); (l)->next->prev = (l); assert(FIRST_LIST(&locks, next, prev) == l); assert(LAST_LIST(l, next, prev) == &locks); if (lst != &locks) { assert(LAST_LIST(&locks, next, prev) == lst); assert(FIRST_LIST(lst, next, prev) == &locks); } assert(FIRST_LIST(l, next, prev) == snd && LAST_LIST(snd, next, prev) == l); // lock_print_all(); return l; }
/* * Return 1 if the inserted event is closer in the future than any * others, 0 otherwise. */ static int __insert_event(struct thread_event *te, struct thread_event *events) { struct thread_event *tmp; assert(NULL != te); assert(te->event_expiration); assert(EMPTY_LIST(te, next, prev)); assert(events->next && events->prev); if (EMPTY_LIST(events, next, prev)) { ADD_LIST(events, te, next, prev); } else for (tmp = FIRST_LIST(events, next, prev) ; ; /* condition built into body (see break;) */ tmp = FIRST_LIST(tmp, next, prev)) { assert(tmp); struct thread_event *prev_te = LAST_LIST(tmp, next, prev); assert(prev_te); assert(tmp->prev && tmp->next); /* We found our place in the list OR end of list. * Either way, insert before this position */ if (tmp->event_expiration > te->event_expiration || events == tmp) { ADD_LIST(prev_te, te, next, prev); assert(prev_te->next == te && te->prev == prev_te); assert(te->next == tmp && tmp->prev == te); break; } assert(tmp->next && tmp->prev); } assert(!EMPTY_LIST(events, next, prev)); assert(!EMPTY_LIST(te, next, prev)); return 0; }
static inline void fp_move_end_runnable(struct sched_thd *t) { struct sched_thd *head; unsigned short int p = sched_get_metric(t)->priority; assert(sched_thd_ready(t)); assert(!sched_thd_suspended(t)); head = &priorities[p].runnable; REM_LIST(t, prio_next, prio_prev); ADD_LIST(LAST_LIST(head, prio_next, prio_prev), t, prio_next, prio_prev); mask_set(p); }
/* insertion sort...only do once */ static int insert_thread(struct thd *t) { struct thd *iter; for (iter = FIRST_LIST(&threads, next, prev) ; iter->sched_info.priority < t->sched_info.priority && iter != &threads ; iter = FIRST_LIST(iter, next, prev)); ADD_LIST(LAST_LIST(iter, next, prev), t, next, prev); return 0; }
/* Take all decedents, return them in a list. */ static struct mapping * __mapping_linearize_decendents(struct mapping *m) { struct mapping *first, *last, *c, *gc; first = c = m->c; m->c = NULL; if (!c) return NULL; do { last = LAST_LIST(first, _s, s_); c->p = NULL; gc = c->c; c->c = NULL; if (gc) APPEND_LIST(last, gc, _s, s_); c = FIRST_LIST(c, _s, s_); } while (first != c); return first; }
/* Take all decedents, return them in a list. */ static struct mapping * __mapping_linearize_decendents(struct mapping *m) { struct mapping *first, *last, *c, *gc; first = c = m->c; m->c = NULL; if (!c) return NULL; do { last = LAST_LIST(first, _s, s_); c->p = NULL; gc = c->c; c->c = NULL; /* add the grand-children onto the end of our list of decedents */ if (gc) ADD_LIST(last, gc, _s, s_); c = FIRST_LIST(c, _s, s_); } while (first != c); return first; }