-
Notifications
You must be signed in to change notification settings - Fork 2.1k
demonstrator: take on shared event handler threads #12480
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
Closed
+88
−0
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
|
|
||
|
|
||
|
|
||
|
|
||
| #include <stddef.h> | ||
|
|
||
| #include "event.h" | ||
|
|
||
|
|
||
| typedef struct { | ||
| uint8_t prio; | ||
| char *stack; | ||
| size_t stack_size; | ||
| } tasklet_params_t; | ||
|
|
||
|
|
||
| void auto_init_tasklet(void); | ||
| event_queue_t *tasklet_get(unsigned n); | ||
|
|
||
| /* for syntactic sugar, we could discuss to add some (none overhead) wrappers */ | ||
| static inline tasklet_schedule(unsgined n, event_t *evt) | ||
| { | ||
| even_post(tasklet_get(n), evt); | ||
| } | ||
| // and so on... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
|
|
||
| #include "tasklet.h" | ||
|
|
||
| #ifdef MODULE_TASKLET_HIGHPRIO | ||
| static char _stack_t1[SOME_STACK_SIZE]; | ||
| #endif | ||
|
|
||
| #ifdef MODULE_TASKLET_LOWPRIO | ||
| static char _stack_t2[SOME_OTHER_STACK_SIZE]; | ||
|
|
||
| /* syntactic sugar: we could give some names - however, we need to find a better | ||
| * way to do this non statically depending on the actual selected modules... */ | ||
| #define TASKLET_LOWPRIO (1u) /* position in params array */ | ||
| #endif | ||
|
|
||
|
|
||
|
|
||
| static tasklet_params_t tasklet_params[] = { | ||
| #ifdef MODULE_TASKLET_HIGHPRIO | ||
| { | ||
| .prio = (THREAD_PRIORITY_HIGHEST + 1), | ||
| .stack = _stack_t1, | ||
| .stack_size = sizeof(stack_t1), | ||
|
|
||
| }, | ||
| #endif | ||
| #ifdef MODULE_TASKLET_LOWPRIO | ||
| { | ||
| .prio = (THREAD_PRIORITY_IDLE - 1), | ||
| .stack = _stack_t2, | ||
| .stack_size = sizeof(stack_t2), | ||
|
|
||
| }, | ||
| #endif | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
|
|
||
| #include "thread.h" | ||
| #include "event.h" | ||
| #include "tasklet.h" | ||
| #include "tasklet_params.h" | ||
|
|
||
|
|
||
| static event_queue_t _eqs[ARRAY_SIZE(tasklet_params)]; | ||
|
|
||
| static void *_runner(void *arg) | ||
| { | ||
| event_queue_init((event_queue_t *)arg); | ||
| event_loop((event_queue_t *)arg); | ||
| return NULL; | ||
| } | ||
|
|
||
| void auto_init_tasklet(void) | ||
| { | ||
| for (unsigned i = 0; i < ARRAY_SIZE(tasklet_params); i++) { | ||
| thread_create(tasklet_params.stack, ... , _runner, &_eqs[i]); | ||
| } | ||
| } | ||
|
|
||
| void tasklet_get(unsigned n) | ||
| { | ||
| assert(n <= ARRAY_SIZE(tasklet_params)); | ||
| return &_eqs[n]; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You could do something like this:
One could argue that it is a bit confusing that the defines for all 5 priority levels are always defined. But I would say that this is actually an advantage, as I could decided later on that I do not need the divide in lowest and low without having to change all uses of
TASKLET_PRIO_LOWtoTASKLET_PRIO_LOWEST.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.
As stated, please lets first focus on the overall concept before jumping into implementation details...