Skip to content

Things You Should Know

Brian Swetland edited this page Jun 20, 2015 · 7 revisions

Safe Actions From IRQ handlers and Timer Callbacks

(Timer callbacks happen from IRQ context)

A number of these functions take a 'reschedule' parameter, which must be false when called from IRQ context. If your interrupt handler takes action which will wake a thread and you want to ensure it wakes now (provided priority is high enough) rather than when the next quantum expires, return INT_RESCHEDULE instead of INT_NO_RESCHEDULE. This will cause the kernel to invoke the scheduler before returning to thread context.

The follow actions are IRQ-safe:

  • Wake threads on wait queues with wake_queue_wake_one() or wake_queue_wake_all().

  • Signal an event with event_signal().

  • Reprogram a timer with timer_set_oneshot(), timer_set_periodic(), or timer_cancel().

  • Timer reprogramming is safe even from within that timer’s callback.

  • Use spinlocks (but usually the higher level primitives are what you want).

Timekeeping: lk_time_t

This unsigned type is used by kernel functions involving timers, timeouts, etc, and is in units of milliseconds. The maximum value (defined as INFINITE_TIME) is used to specify a timeout that will never expore. The value 0 passed as a timeout parameter always means ``return immediately if you would have to wait.''

ERR_TIMED_OUT is the status returned by a function taking a timeout value, if the timeout expires before the requested action can be accomplished.

Destroying Primitives

There are _destroy() functions, but they require careful use — it is not safe to destroy a primitive that might be used again from another thread or interrupt context after its destruction.

Clone this wiki locally