thread.h File Reference

Provides utility functions for event handler threads. More...

Detailed Description

Provides utility functions for event handler threads.

Usage

By using the module event_thread, the event queues EVENT_PRIO_HIGHEST, EVENT_PRIO_MEDIUM, and EVENT_PRIO_LOWEST are provided and declared in the header event/thread.h. With default settings, the auto_init module will automatically start one or more threads to handle these queues.

By default, a single thread with priority EVENT_THREAD_MEDIUM_PRIO will handle all three event queues according to their priority. An already started event handler will not be preempted in this case by an incoming higher priority event. Still, lower priority event queues will only be worked on once the higher priority queues are empty. Hence, the worst case latency is increased by the worst case duration of any possible lower priority event in this configuration.

By using module event_thread_highest, the highest priority queue gets its own thread. With this, events of the highest priority can preempt already running event handlers of medium and lowest priority.

By using module event_thread_medium, the lowest priority events are handled in their own thread. With this, events of at least medium priority can preempt already running events of the lowest priority.

By using both module event_thread_highest and event_thread_medium, each event queue gets its own thread. So higher priority events will always preempt events of lower priority in this case.

Finally, the module event_thread_lowest is provided for backward compatibility and has no effect.

Event Thread API

Author
Kaspar Schleiser kaspa.nosp@m.r@sc.nosp@m.hleis.nosp@m.er.d.nosp@m.e

Definition in file thread.h.

#include <stddef.h>
#include "event.h"
+ Include dependency graph for thread.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

#define EVENT_PRIO_HIGHEST   (&event_thread_queues[EVENT_QUEUE_PRIO_HIGHEST])
 Pointer to the event queue handling highest priority events.
 
#define EVENT_PRIO_MEDIUM   (&event_thread_queues[EVENT_QUEUE_PRIO_MEDIUM])
 Pointer to the event queue handling medium priority events.
 
#define EVENT_PRIO_LOWEST   (&event_thread_queues[EVENT_QUEUE_PRIO_LOWEST])
 Pointer to the event queue handling lowest priority events.
 
enum  { EVENT_QUEUE_PRIO_HIGHEST , EVENT_QUEUE_PRIO_MEDIUM , EVENT_QUEUE_PRIO_LOWEST , EVENT_QUEUE_PRIO_NUMOF }
 Event queue priorities. More...
 
event_queue_t event_thread_queues [EVENT_QUEUE_PRIO_NUMOF]
 
void event_thread_init_multi (event_queue_t *queues, size_t queues_numof, char *stack, size_t stack_size, unsigned priority)
 Convenience function for initializing an event queue thread handling multiple queues. More...
 
static void event_thread_init (event_queue_t *queue, char *stack, size_t stack_size, unsigned priority)
 Convenience function for initializing an event queue thread. More...
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Event queue priorities.

The lower the numeric value, the higher the priority. The highest priority is 0, so that these priorities can be used as index to access arrays.

Enumerator
EVENT_QUEUE_PRIO_HIGHEST 

Highest event queue priority.

EVENT_QUEUE_PRIO_MEDIUM 

Medium event queue priority.

EVENT_QUEUE_PRIO_LOWEST 

Lowest event queue priority.

EVENT_QUEUE_PRIO_NUMOF 

Number of event queue priorities.

Definition at line 105 of file thread.h.

Function Documentation

◆ event_thread_init()

static void event_thread_init ( event_queue_t queue,
char *  stack,
size_t  stack_size,
unsigned  priority 
)
inlinestatic

Convenience function for initializing an event queue thread.

Parameters
[in]queueptr to preallocated queue object
[in]stackptr to stack space
[in]stack_sizesize of stack
[in]prioritypriority to use

Definition at line 91 of file thread.h.

◆ event_thread_init_multi()

void event_thread_init_multi ( event_queue_t queues,
size_t  queues_numof,
char *  stack,
size_t  stack_size,
unsigned  priority 
)

Convenience function for initializing an event queue thread handling multiple queues.

Parameters
[in]queuesarray of the preallocated queue objects
[in]queues_numofnumber of elements in queues
[in]stackptr to stack space
[in]stack_sizesize of stack
[in]prioritypriority to use
Precondition
queues_numof is at most 4