Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
Task Queue Module - User Guide

What is Task Queue?

  • Task Queue provides priority-based deferred work scheduling. Enqueue
  • tasks with priority; dequeue highest priority first. Caller executes tasks.

Quick Start

  • * // Create task
    * sapi_task_t task = {
    * .priority = 50,
    * .function = my_task_handler,
    * .context = &context
    * };
    *
    * // Enqueue
    * sapi_task_queue_enqueue(&queue, &task);
    *
    * // Main loop: dequeue and execute
    * sapi_task_t next;
    * if (sapi_task_queue_dequeue(&queue, &next) == SAPI_STATUS_OK) {
    * next.function(next.context);
    * }
    *

Priority Levels

  • 0-100 scale (higher = more urgent)
  • 90-100: Critical (safety, watchdog)
  • 70-89: Important (vital data)
  • 50-69: Normal (command processing)
  • 30-49: Background (diagnostics)
  • 10-29: Low (cleanup)

Patterns

  • 1. Separate critical from non-critical
  • 2. Keep task execution time bounded
  • 3. Don't chain dependencies
  • 4. Monitor queue depth

See Also