{
struct trans_info *ti = NULL;
- // If there is no ongoing transition, the available state is the current state.
- if (!transition_context.ongoing)
- return current;
-
- // If there is ongoing transition and there are also some pending transitions,
- // the available state is the last state of pending transitions.
- // Otherwise, if there is ongoing transition but there are no pending transitions,
- // the available state is the destination of ongoing transition.
- return (ti = g_queue_peek_head(transition_queue)) ? ti->next : transition_context.ti.next;
+ // If there is pending transition,
+ // the available state is the last state of pendiong transitions.
+ ti = g_queue_peek_head(transition_queue);
+ if (ti)
+ return ti->next;
+
+ // If a transition is underway and there is no other queued transitions,
+ // the available state is the destination of the ongoing transition.
+ // Otherwise, if there neither ongoing nor queued transitions are,
+ // the available state is the current state.
+ return transition_context.ongoing ? transition_context.ti.next : current;
}
static int dequeue_transition(struct trans_info *ti)
// TODO: immediate handling of poweroff?
if (!delayed_init_done || transition_context.ongoing) {
+ // Processes starting later than the deviced wanted to be informed
+ // about power transition that has happend before the process start. To
+ // this end, all transitions are delayed after the delayed_init_callback(),
+ // which is called on completing delayed.target. Therefore it is guaranteed
+ // that all processes that starts before delayed.target can receieve all
+ // power transition information.
enqueue_transition(&ti);
return 0;
}