Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions sys/include/tasklet.h
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...
35 changes: 35 additions & 0 deletions sys/include/tasklet_param.h
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 */

Copy link
Copy Markdown
Member

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:

#define TASKLET_PRIO_LOWEST (0U)

#ifdef MODULE_TASKLET_PRIO_LOW
#define TASKLET_PRIO_LOW (TASKLET_PRIO_LOWEST + 1)
#else
#define TASKLET_PRIO_LOW (TASKLET_PRIO_LOWEST)
#endif

#ifdef MODULE_TASKLET_PRIO_MEDIUM
#define TASKLET_PRIO_MEDIUM (TASKLET_PRIO_LOW + 1)
#else
#define TASKLET_PRIO_LOW (TASKLET_PRIO_LOW)
#endif

#ifdef MODULE_TASKLET_PRIO_HIGH
#define TASKLET_PRIO_HIGH (TASKLET_PRIO_MEDIUM + 1)
#else
#define TASKLET_PRIO_HIGH (TASKLET_PRIO_MEDIUM)
#endif

#ifdef MODULE_TASKLET_PRIO_HIGHEST
#define TASKLET_PRIO_HIGHEST (TASKLET_PRIO_HIGH + 1)
#else
#define TASKLET_PRIO_HIGHEST (TASKLET_PRIO_HIGH)
#endif

#define TASKLET_PRIO_NUMOF (TASKLET_PRIO_HIGHEST + 1)

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_LOW to TASKLET_PRIO_LOWEST.

Copy link
Copy Markdown
Contributor Author

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...

#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
}
28 changes: 28 additions & 0 deletions sys/tasklet/tasklet.c
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];
}