kernel: add k_is_preempt_thread()
Useful for finding out if the current thread is protected against preemption when using non-preemption to protect data structures. Change-Id: Ib545a3609af3646ba49eeeb5a2c50dc51af010d4 Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
This commit is contained in:
parent
d7ad176be6
commit
445830dcec
2 changed files with 19 additions and 0 deletions
|
@ -420,6 +420,20 @@ extern void k_sched_time_slice_set(int32_t slice, int prio);
|
|||
*/
|
||||
extern int k_is_in_isr(void);
|
||||
|
||||
/**
|
||||
* @brief Determine if code is running in a preemptible thread.
|
||||
*
|
||||
* Returns a 'true' value if these conditions are all met:
|
||||
*
|
||||
* - the code is not running in an ISR
|
||||
* - the thread's priority is in the preemptible range
|
||||
* - the thread has not locked the scheduler
|
||||
*
|
||||
* @return 0 if invoked by either an ISR or a cooperative thread.
|
||||
* @return Non-zero if invoked by a preemptible thread.
|
||||
*/
|
||||
extern int k_is_preempt_thread(void);
|
||||
|
||||
/*
|
||||
* @brief Lock the scheduler
|
||||
*
|
||||
|
|
|
@ -363,3 +363,8 @@ void k_sched_time_slice_set(int32_t duration_in_ms, int prio)
|
|||
_time_slice_prio_ceiling = prio;
|
||||
}
|
||||
#endif /* CONFIG_TIMESLICING */
|
||||
|
||||
int k_is_preempt_thread(void)
|
||||
{
|
||||
return !_is_in_isr() && _is_preempt(_current);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue