Skip to content

Commit 03c22b8

Browse files
pabigotnashif
authored andcommitted
scripts/coccinelle: add k_thread create/define to timeout standardization
k_thread_create and K_THREAD_DEFINE both take a delay as the final parameter. Most uses of K_THREAD_DEFINE pass either `K_NO_WAIT` or `K_FOREVER`. Ensure that all uses of K_THREAD_DEFINE follow that practice, and that the runtime k_thread_create calls do so as well. Signed-off-by: Peter Bigot <[email protected]>
1 parent 6e5db35 commit 03c22b8

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

scripts/coccinelle/int_literal_to_timeout.cocci

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ identifier last_timeout =~ "(?x)^k_
3030
| sem_take
3131
| sleep
3232
| stack_pop
33+
| thread_create
3334
| timer_start
3435
| work_poll_submit(|_to_queue)
3536
)$";
@@ -87,6 +88,55 @@ C << r_last_timeout_const_report.C;
8788
msg = "WARNING: replace constant {} with timeout in {}".format(C, fn)
8889
coccilib.report.print_report(p[0], msg);
8990

91+
// ** Convert integer delays in K_THREAD_DEFINE to the appropriate macro
92+
93+
// Identify declarers where an identifier is used for the delay
94+
@r_thread_decl_id@
95+
declarer name K_THREAD_DEFINE;
96+
identifier C;
97+
position p;
98+
@@
99+
K_THREAD_DEFINE@p(..., C);
100+
101+
// Select declarers with constant literal delay and replace with
102+
// appropriate macro
103+
@depends on patch@
104+
declarer name K_THREAD_DEFINE;
105+
constant C;
106+
position p != r_thread_decl_id.p;
107+
@@
108+
K_THREAD_DEFINE@p(...,
109+
(
110+
- 0
111+
+ K_NO_WAIT
112+
|
113+
- -1
114+
+ K_FOREVER
115+
|
116+
- C
117+
+ K_MSEC(C)
118+
)
119+
);
120+
121+
// Identify declarers where an identifier is used for the delay
122+
@r_thread_decl_const
123+
depends on report@
124+
declarer name K_THREAD_DEFINE;
125+
constant C;
126+
position p != r_thread_decl_id.p;
127+
@@
128+
K_THREAD_DEFINE@p(..., C);
129+
130+
131+
@script:python
132+
depends on report
133+
@
134+
C << r_thread_decl_const.C;
135+
p << r_thread_decl_const.p;
136+
@@
137+
msg = "WARNING: replace constant {} with timeout in K_THREAD_DEFINE".format(C)
138+
coccilib.report.print_report(p[0], msg);
139+
90140
// ** Handle k_timer_start where the second (not last) argument is a
91141
// ** constant literal.
92142

0 commit comments

Comments
 (0)