power: clarify notion of action callback function 52/287552/5
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 31 Jan 2023 09:06:59 +0000 (18:06 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 7 Feb 2023 01:42:11 +0000 (10:42 +0900)
The callback, action_for_state(), now denotes jobs that are necessary
before the target state, that is, it is kind of to-do list for entering
the state.

To this end, the name has been slightnly changed from action_on_state(),
which implies it is invoked right 'after' the state change, to
action_for_state(), which emphasizes it is invoked 'before' the state.

In addition, the position where the variable 'current' is updated has
been relocated to fit into the concept of action_for_state(). That is,
it is updated after the callback.

Change-Id: I47698ce9147c155c0d5e30feed0a60d65d69031b
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/power/power.c

index 131a5e2..906ad61 100644 (file)
@@ -105,15 +105,15 @@ static void prepare_transition(const struct trans_info *ti);
 static void action_transition(void);
 static uint64_t get_next_state(void);
 
-static void power_action_normal(void *data);
-static void power_action_sleep(void *data);
-static void power_action_poweroff(void *data);
-static void (*const action_on_state[DEVICED_POWER_STATE_MAX_INDEX]) (void *) = {
-       [DEVICED_POWER_STATE_NORMAL_INDEX]   = power_action_normal,
-       [DEVICED_POWER_STATE_SLEEP_INDEX]    = power_action_sleep,
-       [DEVICED_POWER_STATE_POWEROFF_INDEX] = power_action_poweroff,
-       [DEVICED_POWER_STATE_REBOOT_INDEX]   = power_action_poweroff,
-       [DEVICED_POWER_STATE_EXIT_INDEX]     = power_action_poweroff,
+static void action_for_normal(void *data);
+static void action_for_sleep(void *data);
+static void action_for_poweroff(void *data);
+static void (*const action_for_state[DEVICED_POWER_STATE_MAX_INDEX]) (void *) = {
+       [DEVICED_POWER_STATE_NORMAL_INDEX]   = action_for_normal,
+       [DEVICED_POWER_STATE_SLEEP_INDEX]    = action_for_sleep,
+       [DEVICED_POWER_STATE_POWEROFF_INDEX] = action_for_poweroff,
+       [DEVICED_POWER_STATE_REBOOT_INDEX]   = action_for_poweroff,
+       [DEVICED_POWER_STATE_EXIT_INDEX]     = action_for_poweroff,
 };
 
 uint64_t power_get_state(void)
@@ -281,23 +281,17 @@ static uint64_t alloc_unique_id(void)
        return ++id;
 }
 
-static void power_action_normal(void *udata)
+static void action_for_normal(void *udata)
 {
        power_resume(transition_context.ti.reason);
 }
 
-static void power_action_sleep(void *udata)
+static void action_for_sleep(void *udata)
 {
-       /* for DEVICED_POWER_STATE_NORMAL, DEVICED_POWER_STATE_POWEROFF, do not wake unlock */
-       if (current != DEVICED_POWER_STATE_SLEEP) {
-               _E("Ignore sleep wait done, current=%s", state_name(current));
-               return;
-       }
-
        power_suspend(transition_context.ti.reason);
 }
 
-static void power_action_poweroff(void *data)
+static void action_for_poweroff(void *data)
 {
        // do not transition anymore after poweroff
        unregister_notifier(DEVICE_NOTIFIER_REQUEST_TRANSITION_STATE, transition_request_callback);
@@ -636,16 +630,15 @@ static void action_transition(void)
                int retval;
                int index;
 
-               current = transition_context.ti.next;
                index = DEVICED_POWER_STATE_INDEX(transition_context.ti.next);
-
                if (transition_context.cancel)
                        cancel_transition();
-               else if (action_on_state[index])
-                       action_on_state[index](transition_context.ti.data);
+               else if (action_for_state[index])
+                       action_for_state[index](transition_context.ti.data);
 
                // transition end
                transition_context.ongoing = 0;
+               current = transition_context.ti.next;
                event_wake_unlock(EL_POWER_TRANSITION_STATE);
 
                // trigger next transition if exist