nanokernel: Add scheduling context-independent APIs for nano_fifo
When the exact scheduling context is not known it's convenient to have a wrapper API that uses context_type_get() to call the right function at runtime. Change-Id: Ie72a4b78d53f664575c1d9dfeace52b53d018850 Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
4baf0f0e15
commit
68224c1c69
2 changed files with 42 additions and 0 deletions
|
@ -90,6 +90,10 @@ extern void task_fiber_start(char *pStack,
|
||||||
/* FIFO APIs
|
/* FIFO APIs
|
||||||
*/
|
*/
|
||||||
extern void nano_fifo_init(struct nano_fifo *chan);
|
extern void nano_fifo_init(struct nano_fifo *chan);
|
||||||
|
/* scheduling context independent methods (when context is not known) */
|
||||||
|
extern void nano_fifo_put(struct nano_fifo *chan, void *data);
|
||||||
|
extern void *nano_fifo_get(struct nano_fifo *chan);
|
||||||
|
extern void *nano_fifo_get_wait(struct nano_fifo *chan);
|
||||||
/* methods for ISRs */
|
/* methods for ISRs */
|
||||||
extern void nano_isr_fifo_put(struct nano_fifo *chan, void *data);
|
extern void nano_isr_fifo_put(struct nano_fifo *chan, void *data);
|
||||||
extern void *nano_isr_fifo_get(struct nano_fifo *chan);
|
extern void *nano_isr_fifo_get(struct nano_fifo *chan);
|
||||||
|
|
|
@ -192,9 +192,27 @@ void nano_task_fifo_put(
|
||||||
irq_unlock_inline(imask);
|
irq_unlock_inline(imask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
*
|
||||||
|
* nano_fifo_put - add an element to the end of a fifo
|
||||||
|
*
|
||||||
|
* This is a convenience wrapper for the context-specific APIs. This is
|
||||||
|
* helpful whenever the exact scheduling context is not known, but should
|
||||||
|
* be avoided when the context is known up-front (to avoid unnecessary
|
||||||
|
* overhead).
|
||||||
|
*/
|
||||||
|
void nano_fifo_put(struct nano_fifo *chan, void *data)
|
||||||
|
{
|
||||||
|
static void (*func[3])(struct nano_fifo *chan, void *data) = {
|
||||||
|
nano_isr_fifo_put, nano_fiber_fifo_put, nano_task_fifo_put
|
||||||
|
};
|
||||||
|
func[context_type_get()](chan, data);
|
||||||
|
}
|
||||||
|
|
||||||
FUNC_ALIAS(_fifo_get, nano_isr_fifo_get, void *);
|
FUNC_ALIAS(_fifo_get, nano_isr_fifo_get, void *);
|
||||||
FUNC_ALIAS(_fifo_get, nano_fiber_fifo_get, void *);
|
FUNC_ALIAS(_fifo_get, nano_fiber_fifo_get, void *);
|
||||||
FUNC_ALIAS(_fifo_get, nano_task_fifo_get, void *);
|
FUNC_ALIAS(_fifo_get, nano_task_fifo_get, void *);
|
||||||
|
FUNC_ALIAS(_fifo_get, nano_fifo_get, void *);
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
*
|
*
|
||||||
|
@ -360,3 +378,23 @@ void *nano_task_fifo_get_wait(
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
*
|
||||||
|
* nano_fifo_get_wait - get an element from the head of a fifo, poll/pend if
|
||||||
|
* not available
|
||||||
|
*
|
||||||
|
* This is a convenience wrapper for the context-specific APIs. This is
|
||||||
|
* helpful whenever the exact scheduling context is not known, but should
|
||||||
|
* be avoided when the context is known up-front (to avoid unnecessary
|
||||||
|
* overhead).
|
||||||
|
*
|
||||||
|
* It's only valid to call this API from a fiber or a task.
|
||||||
|
*/
|
||||||
|
void *nano_fifo_get_wait(struct nano_fifo *chan)
|
||||||
|
{
|
||||||
|
static void *(*func[3])(struct nano_fifo *chan) = {
|
||||||
|
NULL, nano_fiber_fifo_get_wait, nano_task_fifo_get_wait
|
||||||
|
};
|
||||||
|
return func[context_type_get()](chan);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue