Skip to content

Commit 139cdf5

Browse files
committed
Fix return parameters of function states
1 parent fa03742 commit 139cdf5

File tree

5 files changed

+65
-34
lines changed

5 files changed

+65
-34
lines changed

apps/examples/dpp/philo.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <string.h>
2828

2929
#include "common/macros.h"
30+
#include "common/types.h"
3031
#include "hsm/hsm.h"
3132
#include "event/event.h"
3233
#include "pal/pal.h"
@@ -54,12 +55,14 @@ struct am_ao *g_ao_philo[PHILO_NUM] = {
5455

5556
static struct am_event event_stopped_ = {.id = EVT_STOPPED};
5657

57-
static int philo_top(struct philo *me, const struct am_event *event);
58-
static int philo_thinking(struct philo *me, const struct am_event *event);
59-
static int philo_hungry(struct philo *me, const struct am_event *event);
60-
static int philo_eating(struct philo *me, const struct am_event *event);
58+
static enum am_rc philo_top(struct philo *me, const struct am_event *event);
59+
static enum am_rc philo_thinking(
60+
struct philo *me, const struct am_event *event
61+
);
62+
static enum am_rc philo_hungry(struct philo *me, const struct am_event *event);
63+
static enum am_rc philo_eating(struct philo *me, const struct am_event *event);
6164

62-
static int philo_top(struct philo *me, const struct am_event *event) {
65+
static enum am_rc philo_top(struct philo *me, const struct am_event *event) {
6366
switch (event->id) {
6467
case EVT_STOP:
6568
am_timer_disarm(me->timer);
@@ -72,7 +75,9 @@ static int philo_top(struct philo *me, const struct am_event *event) {
7275
return AM_HSM_SUPER(am_hsm_top);
7376
}
7477

75-
static int philo_thinking(struct philo *me, const struct am_event *event) {
78+
static enum am_rc philo_thinking(
79+
struct philo *me, const struct am_event *event
80+
) {
7681
switch (event->id) {
7782
case AM_EVT_ENTRY:
7883
am_pal_printf("philo %d is thinking\n", me->id);
@@ -94,7 +99,7 @@ static int philo_thinking(struct philo *me, const struct am_event *event) {
9499
return AM_HSM_SUPER(philo_top);
95100
}
96101

97-
static int philo_hungry(struct philo *me, const struct am_event *event) {
102+
static enum am_rc philo_hungry(struct philo *me, const struct am_event *event) {
98103
switch (event->id) {
99104
case AM_EVT_ENTRY:
100105
am_pal_printf("philo %d is hungry\n", me->id);
@@ -113,7 +118,7 @@ static int philo_hungry(struct philo *me, const struct am_event *event) {
113118
return AM_HSM_SUPER(philo_top);
114119
}
115120

116-
static int philo_eating(struct philo *me, const struct am_event *event) {
121+
static enum am_rc philo_eating(struct philo *me, const struct am_event *event) {
117122
switch (event->id) {
118123
case AM_EVT_ENTRY:
119124
am_pal_printf("philo %d is eating\n", me->id);
@@ -134,7 +139,7 @@ static int philo_eating(struct philo *me, const struct am_event *event) {
134139
return AM_HSM_SUPER(philo_top);
135140
}
136141

137-
static int philo_init(struct philo *me, const struct am_event *event) {
142+
static enum am_rc philo_init(struct philo *me, const struct am_event *event) {
138143
(void)event;
139144
am_ao_subscribe(&me->ao, EVT_EAT);
140145
am_ao_subscribe(&me->ao, EVT_STOP);

apps/examples/dpp/table.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <string.h>
2929

3030
#include "common/macros.h"
31+
#include "common/types.h"
3132
#include "event/event.h"
3233
#include "hsm/hsm.h"
3334
#include "pal/pal.h"
@@ -107,7 +108,9 @@ static void table_serve(int philo) {
107108
}
108109
}
109110

110-
static int table_stopping(struct table *me, const struct am_event *event) {
111+
static enum am_rc table_stopping(
112+
struct table *me, const struct am_event *event
113+
) {
111114
switch (event->id) {
112115
case EVT_STOPPED: {
113116
++me->nstops;
@@ -126,7 +129,9 @@ static bool table_sessions_are_over(const struct table *me) {
126129
return me->nsessions == 0;
127130
}
128131

129-
static int table_serving(struct table *me, const struct am_event *event) {
132+
static enum am_rc table_serving(
133+
struct table *me, const struct am_event *event
134+
) {
130135
switch (event->id) {
131136
case EVT_HUNGRY: {
132137
const struct hungry *hungry = (const struct hungry *)event;
@@ -171,7 +176,7 @@ static int table_serving(struct table *me, const struct am_event *event) {
171176
return AM_HSM_SUPER(am_hsm_top);
172177
}
173178

174-
static int table_init(struct table *me, const struct am_event *event) {
179+
static enum am_rc table_init(struct table *me, const struct am_event *event) {
175180
(void)event;
176181
am_ao_subscribe(&me->ao, EVT_DONE);
177182
return AM_HSM_TRAN(table_serving);

apps/examples/smokers/main.c

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include "common/alignment.h"
3737
#include "common/macros.h"
38+
#include "common/types.h"
3839
#include "event/event.h"
3940
#include "timer/timer.h"
4041
#include "ao/ao.h"
@@ -108,12 +109,18 @@ static int rand_012(void) {
108109
return (int)((unsigned)(next / 65536) % 3);
109110
}
110111

111-
static int smoker_top(struct smoker *me, const struct am_event *event);
112-
static int smoker_idle(struct smoker *me, const struct am_event *event);
113-
static int smoker_smoking(struct smoker *me, const struct am_event *event);
114-
static int smoker_stopping(struct smoker *me, const struct am_event *event);
115-
116-
static int smoker_stopping(struct smoker *me, const struct am_event *event) {
112+
static enum am_rc smoker_top(struct smoker *me, const struct am_event *event);
113+
static enum am_rc smoker_idle(struct smoker *me, const struct am_event *event);
114+
static enum am_rc smoker_smoking(
115+
struct smoker *me, const struct am_event *event
116+
);
117+
static enum am_rc smoker_stopping(
118+
struct smoker *me, const struct am_event *event
119+
);
120+
121+
static enum am_rc smoker_stopping(
122+
struct smoker *me, const struct am_event *event
123+
) {
117124
switch (event->id) {
118125
case EVT_STOP: {
119126
am_ao_publish(&m_evt_stopped);
@@ -126,7 +133,7 @@ static int smoker_stopping(struct smoker *me, const struct am_event *event) {
126133
return AM_HSM_SUPER(am_hsm_top);
127134
}
128135

129-
static int smoker_top(struct smoker *me, const struct am_event *event) {
136+
static enum am_rc smoker_top(struct smoker *me, const struct am_event *event) {
130137
switch (event->id) {
131138
case EVT_STOP: {
132139
return AM_HSM_TRAN_REDISPATCH(smoker_stopping);
@@ -137,7 +144,7 @@ static int smoker_top(struct smoker *me, const struct am_event *event) {
137144
return AM_HSM_SUPER(am_hsm_top);
138145
}
139146

140-
static int smoker_idle(struct smoker *me, const struct am_event *event) {
147+
static enum am_rc smoker_idle(struct smoker *me, const struct am_event *event) {
141148
switch (event->id) {
142149
case EVT_RESOURCE: {
143150
const struct resource *e = (const struct resource *)event;
@@ -157,7 +164,9 @@ static int smoker_idle(struct smoker *me, const struct am_event *event) {
157164
return AM_HSM_SUPER(smoker_top);
158165
}
159166

160-
static int smoker_smoking(struct smoker *me, const struct am_event *event) {
167+
static enum am_rc smoker_smoking(
168+
struct smoker *me, const struct am_event *event
169+
) {
161170
switch (event->id) {
162171
case AM_EVT_ENTRY:
163172
am_timer_arm_ms(&me->timer_done_smoking, /*ms=*/20, /*interval=*/0);
@@ -185,7 +194,7 @@ static int smoker_smoking(struct smoker *me, const struct am_event *event) {
185194
return AM_HSM_SUPER(smoker_top);
186195
}
187196

188-
static int smoker_init(struct smoker *me, const struct am_event *event) {
197+
static enum am_rc smoker_init(struct smoker *me, const struct am_event *event) {
189198
(void)event;
190199
am_ao_subscribe(&me->ao, EVT_RESOURCE);
191200
am_ao_subscribe(&me->ao, EVT_STOP);
@@ -225,7 +234,9 @@ static void agent_check_stats(const struct agent *me) {
225234
}
226235
}
227236

228-
static int agent_stopping(struct agent *me, const struct am_event *event) {
237+
static enum am_rc agent_stopping(
238+
struct agent *me, const struct am_event *event
239+
) {
229240
switch (event->id) {
230241
case AM_EVT_ENTRY:
231242
am_ao_publish_exclude(&m_evt_stop, &me->ao);
@@ -278,7 +289,7 @@ static void publish_resources(struct agent *me) {
278289
me->resource_id++;
279290
}
280291

281-
static int agent_proc(struct agent *me, const struct am_event *event) {
292+
static enum am_rc agent_proc(struct agent *me, const struct am_event *event) {
282293
switch (event->id) {
283294
case AM_EVT_ENTRY: {
284295
am_timer_arm_ms(&me->timeout, AM_TIMEOUT_MS, /*interval=*/0);
@@ -306,7 +317,7 @@ static int agent_proc(struct agent *me, const struct am_event *event) {
306317
return AM_HSM_SUPER(am_hsm_top);
307318
}
308319

309-
static int agent_init(struct agent *me, const struct am_event *event) {
320+
static enum am_rc agent_init(struct agent *me, const struct am_event *event) {
310321
(void)event;
311322
am_ao_subscribe(&me->ao, EVT_DONE_SMOKING);
312323
am_ao_subscribe(&me->ao, EVT_STOPPED);

apps/examples/watchdog/main.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <string.h>
3737

3838
#include "common/macros.h"
39+
#include "common/types.h"
3940
#include "event/event.h"
4041
#include "timer/timer.h"
4142
#include "ao/ao.h"
@@ -75,7 +76,9 @@ static const struct am_event m_evt_wdt_feed = {.id = EVT_WDT_FEED};
7576

7677
/* 'watched' task */
7778

78-
static int watched_proc(struct watched *me, const struct am_event *event) {
79+
static enum am_rc watched_proc(
80+
struct watched *me, const struct am_event *event
81+
) {
7982
switch (event->id) {
8083
case AM_EVT_ENTRY: {
8184
am_timer_arm_ms(
@@ -97,7 +100,9 @@ static int watched_proc(struct watched *me, const struct am_event *event) {
97100
return AM_HSM_SUPER(am_hsm_top);
98101
}
99102

100-
static int watched_init(struct watched *me, const struct am_event *event) {
103+
static enum am_rc watched_init(
104+
struct watched *me, const struct am_event *event
105+
) {
101106
(void)event;
102107
am_timer_ctor(
103108
&me->timer_wdt_feed,
@@ -115,7 +120,7 @@ static void watched_ctor(struct watched *me) {
115120

116121
/* 'wdt' task */
117122

118-
static int wdt_proc(struct wdt *me, const struct am_event *event) {
123+
static enum am_rc wdt_proc(struct wdt *me, const struct am_event *event) {
119124
switch (event->id) {
120125
case AM_EVT_ENTRY: {
121126
am_timer_arm_ms(
@@ -141,7 +146,7 @@ static int wdt_proc(struct wdt *me, const struct am_event *event) {
141146
return AM_HSM_SUPER(am_hsm_top);
142147
}
143148

144-
static int wdt_init(struct wdt *me, const struct am_event *event) {
149+
static enum am_rc wdt_init(struct wdt *me, const struct am_event *event) {
145150
(void)event;
146151
am_timer_ctor(
147152
&me->timer_wdt_bark,

apps/examples/workers/main.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include "common/alignment.h"
3737
#include "common/macros.h"
38+
#include "common/types.h"
3839
#include "event/event.h"
3940
#include "timer/timer.h"
4041
#include "ao/ao.h"
@@ -97,7 +98,7 @@ static void work(int cycles) {
9798
}
9899
}
99100

100-
static int worker_proc(struct worker *me, const struct am_event *event) {
101+
static enum am_rc worker_proc(struct worker *me, const struct am_event *event) {
101102
switch (event->id) {
102103
case EVT_JOB_REQ: {
103104
const struct job_req *req = AM_CAST(const struct job_req *, event);
@@ -121,7 +122,7 @@ static int worker_proc(struct worker *me, const struct am_event *event) {
121122
return AM_HSM_SUPER(am_hsm_top);
122123
}
123124

124-
static int worker_init(struct worker *me, const struct am_event *event) {
125+
static enum am_rc worker_init(struct worker *me, const struct am_event *event) {
125126
(void)event;
126127
am_ao_subscribe(&me->ao, EVT_JOB_REQ);
127128
am_ao_subscribe(&me->ao, EVT_STOP);
@@ -154,7 +155,7 @@ static void balancer_check_stats(const struct balancer *me) {
154155
}
155156
}
156157

157-
static int balancer_stopping(
158+
static enum am_rc balancer_stopping(
158159
struct balancer *me, const struct am_event *event
159160
) {
160161
switch (event->id) {
@@ -179,7 +180,9 @@ static int balancer_stopping(
179180
return AM_HSM_SUPER(am_hsm_top);
180181
}
181182

182-
static int balancer_proc(struct balancer *me, const struct am_event *event) {
183+
static enum am_rc balancer_proc(
184+
struct balancer *me, const struct am_event *event
185+
) {
183186
switch (event->id) {
184187
case AM_EVT_ENTRY: {
185188
am_timer_arm_ms(&me->timeout, AM_TIMEOUT_MS, /*interval=*/0);
@@ -219,7 +222,9 @@ static int balancer_proc(struct balancer *me, const struct am_event *event) {
219222
return AM_HSM_SUPER(am_hsm_top);
220223
}
221224

222-
static int balancer_init(struct balancer *me, const struct am_event *event) {
225+
static enum am_rc balancer_init(
226+
struct balancer *me, const struct am_event *event
227+
) {
223228
(void)event;
224229
am_ao_subscribe(&me->ao, EVT_JOB_DONE);
225230
am_ao_subscribe(&me->ao, EVT_STOPPED);

0 commit comments

Comments
 (0)