12
12
13
13
-export ([get /0 ,
14
14
set /1 ,
15
- wait_for /2 ]).
15
+ wait_for /2 ,
16
+ has_reached /1 ,
17
+ has_reached_and_is_active /1 ]).
16
18
17
19
-define (PT_KEY_BOOT_STATE , {? MODULE , boot_state }).
18
20
19
- -type boot_state () :: 'stopped' | 'booting' | 'ready' | 'stopping' .
21
+ -type boot_state () :: 'stopped' | 'booting' | 'core_started' | ' ready' | 'stopping' .
20
22
21
23
-export_type ([boot_state / 0 ]).
22
24
@@ -36,15 +38,15 @@ set(BootState) ->
36
38
37
39
-spec wait_for (boot_state (), timeout ()) -> ok | {error , timeout }.
38
40
wait_for (BootState , infinity ) ->
39
- case is_reached (BootState ) of
41
+ case has_reached (BootState ) of
40
42
true -> ok ;
41
43
false -> Wait = 200 ,
42
44
timer :sleep (Wait ),
43
45
wait_for (BootState , infinity )
44
46
end ;
45
47
wait_for (BootState , Timeout )
46
48
when is_integer (Timeout ) andalso Timeout >= 0 ->
47
- case is_reached (BootState ) of
49
+ case has_reached (BootState ) of
48
50
true -> ok ;
49
51
false -> Wait = 200 ,
50
52
timer :sleep (Wait ),
@@ -53,24 +55,35 @@ wait_for(BootState, Timeout)
53
55
wait_for (_ , _ ) ->
54
56
{error , timeout }.
55
57
56
- boot_state_idx (stopped ) -> 0 ;
57
- boot_state_idx (booting ) -> 1 ;
58
- boot_state_idx (ready ) -> 2 ;
59
- boot_state_idx (stopping ) -> 3 .
58
+ boot_state_idx (stopped ) -> 0 ;
59
+ boot_state_idx (booting ) -> 1 ;
60
+ boot_state_idx (core_started ) -> 2 ;
61
+ boot_state_idx (ready ) -> 3 ;
62
+ boot_state_idx (stopping ) -> 4 .
60
63
61
64
is_valid (BootState ) ->
62
65
is_integer (boot_state_idx (BootState )).
63
66
64
- is_reached (TargetBootState ) ->
65
- is_reached (? MODULE :get (), TargetBootState ).
67
+ has_reached (TargetBootState ) ->
68
+ has_reached (? MODULE :get (), TargetBootState ).
66
69
67
- is_reached (CurrentBootState , CurrentBootState ) ->
70
+ has_reached (CurrentBootState , CurrentBootState ) ->
68
71
true ;
69
- is_reached (stopping , stopped ) ->
72
+ has_reached (stopping , stopped ) ->
70
73
false ;
71
- is_reached (_CurrentBootState , stopped ) ->
74
+ has_reached (_CurrentBootState , stopped ) ->
72
75
true ;
73
- is_reached (stopped , _TargetBootState ) ->
76
+ has_reached (stopped , _TargetBootState ) ->
74
77
true ;
75
- is_reached (CurrentBootState , TargetBootState ) ->
78
+ has_reached (CurrentBootState , TargetBootState ) ->
76
79
boot_state_idx (TargetBootState ) =< boot_state_idx (CurrentBootState ).
80
+
81
+ has_reached_and_is_active (TargetBootState ) ->
82
+ case ? MODULE :get () of
83
+ stopped ->
84
+ false ;
85
+ CurrentBootState ->
86
+ has_reached (CurrentBootState , TargetBootState )
87
+ andalso
88
+ not has_reached (CurrentBootState , stopping )
89
+ end .
0 commit comments