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 <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
6e5db350b2
commit
03c22b8c94
1 changed files with 50 additions and 0 deletions
|
@ -30,6 +30,7 @@ identifier last_timeout =~ "(?x)^k_
|
|||
| sem_take
|
||||
| sleep
|
||||
| stack_pop
|
||||
| thread_create
|
||||
| timer_start
|
||||
| work_poll_submit(|_to_queue)
|
||||
)$";
|
||||
|
@ -87,6 +88,55 @@ C << r_last_timeout_const_report.C;
|
|||
msg = "WARNING: replace constant {} with timeout in {}".format(C, fn)
|
||||
coccilib.report.print_report(p[0], msg);
|
||||
|
||||
// ** Convert integer delays in K_THREAD_DEFINE to the appropriate macro
|
||||
|
||||
// Identify declarers where an identifier is used for the delay
|
||||
@r_thread_decl_id@
|
||||
declarer name K_THREAD_DEFINE;
|
||||
identifier C;
|
||||
position p;
|
||||
@@
|
||||
K_THREAD_DEFINE@p(..., C);
|
||||
|
||||
// Select declarers with constant literal delay and replace with
|
||||
// appropriate macro
|
||||
@depends on patch@
|
||||
declarer name K_THREAD_DEFINE;
|
||||
constant C;
|
||||
position p != r_thread_decl_id.p;
|
||||
@@
|
||||
K_THREAD_DEFINE@p(...,
|
||||
(
|
||||
- 0
|
||||
+ K_NO_WAIT
|
||||
|
|
||||
- -1
|
||||
+ K_FOREVER
|
||||
|
|
||||
- C
|
||||
+ K_MSEC(C)
|
||||
)
|
||||
);
|
||||
|
||||
// Identify declarers where an identifier is used for the delay
|
||||
@r_thread_decl_const
|
||||
depends on report@
|
||||
declarer name K_THREAD_DEFINE;
|
||||
constant C;
|
||||
position p != r_thread_decl_id.p;
|
||||
@@
|
||||
K_THREAD_DEFINE@p(..., C);
|
||||
|
||||
|
||||
@script:python
|
||||
depends on report
|
||||
@
|
||||
C << r_thread_decl_const.C;
|
||||
p << r_thread_decl_const.p;
|
||||
@@
|
||||
msg = "WARNING: replace constant {} with timeout in K_THREAD_DEFINE".format(C)
|
||||
coccilib.report.print_report(p[0], msg);
|
||||
|
||||
// ** Handle k_timer_start where the second (not last) argument is a
|
||||
// ** constant literal.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue