-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys: preprocessor successor module #18299
Conversation
@fjmolinas could be interested |
#include "auto_init_utils.h" | ||
|
||
#define PRIO 1111 | ||
#define PRIO AUTO_INIT_PRIORITY_AFTER(AUTO_INIT_PRIO_MOD_RANDOM) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose
#define PRIO2 AUTO_INIT_PRIORITY_AFTER(PRIO)
would not work, right?
But even if limited to in-tree modules as reference, this already is a big improvement.
What if two external modules both chose UTO_INIT_PRIORITY_AFTER(AUTO_INIT_PRIO_MOD_RANDOM)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sorting is done by XFA alphabetically. The priorities just prefix numbers to the symbol name. So symbol 1337_foo
would always come after 1337_bar
, because b
< f
.
This may be good enough if both foo
and bar
really only care to be called after random is initialized and have no interdependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#define PRIO2 AUTO_INIT_PRIORITY_AFTER(PRIO)
That’s also possible. Note the priority is 1042 instead of 1041. And note the alphabetic order if some modules have the same priority.
diff --git a/tests/external_module_dirs/external_modules/external_module/external_module.c b/tests/external_module_dirs/external_modules/external_module/external_module.c
index f520d66631..351fa55526 100644
--- a/tests/external_module_dirs/external_modules/external_module/external_module.c
+++ b/tests/external_module_dirs/external_modules/external_module/external_module.c
@@ -23,9 +23,16 @@
#include "auto_init_priorities.h"
#include "auto_init_utils.h"
+void bauto_init_external_module(void)
+{
+ external_module_initialized = true;
+}
+
#define PRIO AUTO_INIT_PRIORITY_AFTER(AUTO_INIT_PRIO_MOD_RANDOM)
+#define PRIO2 AUTO_INIT_PRIORITY_AFTER(PRIO)
-AUTO_INIT(auto_init_external_module, PRIO);
+AUTO_INIT(bauto_init_external_module, PRIO2);
+AUTO_INIT(auto_init_external_module, PRIO2);
bool external_module_initialized = false;
char *external_module_message = "Linking worked";
tests/external_module_dirs/bin/miot-nucleo-f767zi/tests_external_module_dirs.map
.roxfa.auto_init_xfa.5_1042
0x0000000008003cc0 0x18 /home/fabian/forks/RIOT/tests/external_module_dirs/bin/miot-nucleo-f767zi/external_module/external_module.o
0x0000000008003cc0 auto_init_xfa_auto_init_external_module
0x0000000008003ccc auto_init_xfa_bauto_init_external_module
tests/external_module_dirs
Type '/exit' to exit.
2022-10-13 17:48:25,548 # auto_init: ztimer_init (1010)
2022-10-13 17:48:25,551 # auto_init: auto_init_random (1040)
2022-10-13 17:48:25,555 # auto_init: auto_init_external_module (1042)
2022-10-13 17:48:25,559 # auto_init: bauto_init_external_module (1042)
2022-10-13 17:48:25,562 # auto_init: auto_init_miot_mtd (1249)
2022-10-13 17:48:25,566 # auto_init: auto_init_miot_node (1359)
2022-10-13 17:48:25,573 # main(): This is RIOT! (Version: 2022.07-devel-790-g44a6e-preprocessor_successor)
2022-10-13 17:48:25,575 # Message: Linking worked
2022-10-13 17:48:25,577 # Initialization worked!
2022-10-13 17:48:49,627 # Exiting Pyterm
Please rebase & squash |
44a6e7c
to
86f2477
Compare
Oops forgot the rebase ... |
86f2477
to
c6363e3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is some dark magic, but the benefits are clearly worth it.
Murdock results✔️ PASSED fefd8ba sys/preprocessor: add Kconfig file
ArtifactsThis only reflects a subset of all builds from https://ci-prod.riot-os.org. Please refer to https://ci.riot-os.org for a complete build for now. |
c6363e3
to
2b4b61d
Compare
looks like KConfig is still missing |
Please squash! |
9c86bc6
to
fefd8ba
Compare
Thank You! |
Contribution description
Generate a header file, containing successor definitions up to a fixed maximum.
This allows to use the preprocessor to compute the successor of a number and is useful to construct priority values for
auto_init
.This is similar to boost preprocessor arithmetik.
Testing procedure
See usage in
tests/external_module_dirs/external_modules/external_module/external_module.c
Issues/PRs references
#18003